From joewiz at gmail.com Thu Apr 13 12:09:32 2017 From: joewiz at gmail.com (Joe Wicentowski) Date: Thu, 13 Apr 2017 15:09:32 -0400 Subject: [xquery-talk] Error when using predicate after arrow operator Message-ID: Hi all, As I understand the arrow operator (https://www.w3.org/TR/xquery-31/#id-arrow-operator), the following query: "1.2.3" => tokenize("\.") is equivalent to: tokenize("1.2.3", "\.") If this is so, then can anyone shed light on why appending a predicate to the former would raise an error but not so for the latter? In Saxon, eXist, and BaseX, the following expression: "1.2.3" => tokenize("\.")[. < "3"] raises an error like: XPST0003: Unexpected token "[" beyond end of query whereas the pre-XQuery 3.1 approach: tokenize("1.2.3", "\.")[. < "3"] returns the results I'd expect: ("1", "2") Thanks, Joe From John.Snelson at marklogic.com Thu Apr 13 12:44:01 2017 From: John.Snelson at marklogic.com (John Snelson) Date: Thu, 13 Apr 2017 19:44:01 +0000 Subject: [xquery-talk] Error when using predicate after arrow operator In-Reply-To: References: Message-ID: <3ef7853f-c672-f1cf-5f6d-6f39617add22@marklogic.com> The equivalence holds for how it functionally behaves, not for what grammar the parser allows. You need parentheses: ("1.2.3" => tokenize("\."))[. < "3"] John On 13/04/2017 20:09, Joe Wicentowski wrote: > Hi all, > > As I understand the arrow operator > (https://www.w3.org/TR/xquery-31/#id-arrow-operator), the following > query: > > "1.2.3" => tokenize("\.") > > is equivalent to: > > tokenize("1.2.3", "\.") > > If this is so, then can anyone shed light on why appending a predicate > to the former would raise an error but not so for the latter? In > Saxon, eXist, and BaseX, the following expression: > > "1.2.3" => tokenize("\.")[. < "3"] > > raises an error like: > > XPST0003: Unexpected token "[" beyond end of query > > whereas the pre-XQuery 3.1 approach: > > tokenize("1.2.3", "\.")[. < "3"] > > returns the results I'd expect: > > ("1", "2") > > Thanks, > Joe > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk -- John Snelson, Principal Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com From joewiz at gmail.com Thu Apr 13 13:36:21 2017 From: joewiz at gmail.com (Joe Wicentowski) Date: Thu, 13 Apr 2017 16:36:21 -0400 Subject: [xquery-talk] Error when using predicate after arrow operator In-Reply-To: <3ef7853f-c672-f1cf-5f6d-6f39617add22@marklogic.com> References: <3ef7853f-c672-f1cf-5f6d-6f39617add22@marklogic.com> Message-ID: Hi John, Thanks for your reply. I had discovered that parentheses would allow the query to complete without error, but I struggled to see what rule in the spec my query violated. Now I see it: the predicate isn't valid in the ArrowFunctionSpecifier, defined at https://www.w3.org/TR/xquery-31/#doc-xquery31-ArrowFunctionSpecifier as: EQName | VarRef | ParenthesizedExpr So the parser sees the ParenthesizedExpr in my `tokenize("\.")` and then chokes on the following character, the open square bracket. Thanks for helping me see this! Joe On Thu, Apr 13, 2017 at 3:44 PM, John Snelson wrote: > The equivalence holds for how it functionally behaves, not for what > grammar the parser allows. You need parentheses: > > ("1.2.3" => tokenize("\."))[. < "3"] > > > John > > On 13/04/2017 20:09, Joe Wicentowski wrote: > > Hi all, > > > > As I understand the arrow operator > > (https://www.w3.org/TR/xquery-31/#id-arrow-operator), the following > > query: > > > > "1.2.3" => tokenize("\.") > > > > is equivalent to: > > > > tokenize("1.2.3", "\.") > > > > If this is so, then can anyone shed light on why appending a predicate > > to the former would raise an error but not so for the latter? In > > Saxon, eXist, and BaseX, the following expression: > > > > "1.2.3" => tokenize("\.")[. < "3"] > > > > raises an error like: > > > > XPST0003: Unexpected token "[" beyond end of query > > > > whereas the pre-XQuery 3.1 approach: > > > > tokenize("1.2.3", "\.")[. < "3"] > > > > returns the results I'd expect: > > > > ("1", "2") > > > > Thanks, > > Joe > > _______________________________________________ > > talk at x-query.com > > http://x-query.com/mailman/listinfo/talk > > > -- > John Snelson, Principal Engineer http://twitter.com/jpcs > MarkLogic Corporation http://www.marklogic.com > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike at saxonica.com Thu Apr 13 13:06:58 2017 From: mike at saxonica.com (Michael Kay) Date: Thu, 13 Apr 2017 21:06:58 +0100 Subject: [xquery-talk] Error when using predicate after arrow operator In-Reply-To: References: Message-ID: The precedence table at https://www.w3.org/TR/xquery-31/#id-precedence-order shows that [] has higher precedence than => I don't remember the exact details of the deliberations that led to this decision, but I know we looked at a number of examples. One of them was that -1 => abs() should mean (-1) => abs() rather than - (1 => abs()) which was the effect of the original proposal. Michael Kay Saxonica > On 13 Apr 2017, at 20:09, Joe Wicentowski wrote: > > Hi all, > > As I understand the arrow operator > (https://www.w3.org/TR/xquery-31/#id-arrow-operator), the following > query: > > "1.2.3" => tokenize("\.") > > is equivalent to: > > tokenize("1.2.3", "\.") > > If this is so, then can anyone shed light on why appending a predicate > to the former would raise an error but not so for the latter? In > Saxon, eXist, and BaseX, the following expression: > > "1.2.3" => tokenize("\.")[. < "3"] > > raises an error like: > > XPST0003: Unexpected token "[" beyond end of query > > whereas the pre-XQuery 3.1 approach: > > tokenize("1.2.3", "\.")[. < "3"] > > returns the results I'd expect: > > ("1", "2") > > Thanks, > Joe > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From xquery at docbook-autor.de Wed Apr 19 01:51:57 2017 From: xquery at docbook-autor.de (xquery at docbook-autor.de) Date: Wed, 19 Apr 2017 10:51:57 +0200 Subject: [xquery-talk] Omit namespace attributes in output file Message-ID: <7cb4c226-d6bf-79a0-b4d8-6d40b55c1228@docbook-autor.de> Hi, I?m transforming some DocBook data into an XML file using XQuery. The transformation works perfectly so far. My problem is, that I have to use some confluence namespace tags like in the XML output file. So I have to declare the respective namespace at the beginning of my XQuery file: ### xquery version "1.0" encoding "utf-8"; declare namespace db="http://docbook.org/ns/docbook"; declare namespace saxon="http://saxon.sf.net/"; declare namespace ac="https://www.atlassian.com/schema/confluence/6/ac"; declare option saxon:output "version=1.0"; declare option saxon:output "omit-xml-declaration=yes"; declare option saxon:output "indent=yes"; ### Because of the namespace declaration for "ac" at the beginning the transformation results in this: ### ### Without this declaration the transformation stops with an error message that a declaration for namespace ?ac? is missing. Is it possible to omit the xmlns:ac attribute somehow? Thanks in advance! Regards Michael From mike at saxonica.com Wed Apr 19 02:38:31 2017 From: mike at saxonica.com (Michael Kay) Date: Wed, 19 Apr 2017 10:38:31 +0100 Subject: [xquery-talk] Omit namespace attributes in output file In-Reply-To: <7cb4c226-d6bf-79a0-b4d8-6d40b55c1228@docbook-autor.de> References: <7cb4c226-d6bf-79a0-b4d8-6d40b55c1228@docbook-autor.de> Message-ID: <2CA2F29B-33CD-49AB-BFE6-A21979075AED@saxonica.com> XQuery output has to be well-formed (and namespace-well-formed) XML, so you can't output an element name like unless the "ac" prefix is declared and bound to a namespace URI. Why would you want to? Does Confluence really use non-namespace-aware XML? Michael Kay Saxonica > On 19 Apr 2017, at 09:51, xquery at docbook-autor.de wrote: > > > Hi, > > I?m transforming some DocBook data into an XML file using XQuery. The > transformation works perfectly so far. > > My problem is, that I have to use some confluence namespace tags like > in the XML output file. > > So I have to declare the respective namespace at the beginning of my > XQuery file: > > ### > xquery version "1.0" encoding "utf-8"; > > declare namespace db="http://docbook.org/ns/docbook"; > declare namespace saxon="http://saxon.sf.net/"; > declare namespace ac="https://www.atlassian.com/schema/confluence/6/ac"; > > declare option saxon:output "version=1.0"; > declare option saxon:output "omit-xml-declaration=yes"; > declare option saxon:output "indent=yes"; > ### > > Because of the namespace declaration for "ac" at the beginning the > transformation results in this: > > ### > ac:name="warning"/> > ### > > Without this declaration the transformation stops with an error message > that a declaration for namespace ?ac? is missing. > > Is it possible to omit the xmlns:ac attribute somehow? > > Thanks in advance! > > Regards > Michael > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From xquery at docbook-autor.de Wed Apr 19 03:10:51 2017 From: xquery at docbook-autor.de (xquery at docbook-autor.de) Date: Wed, 19 Apr 2017 12:10:51 +0200 Subject: [xquery-talk] Omit namespace attributes in output file In-Reply-To: <2CA2F29B-33CD-49AB-BFE6-A21979075AED@saxonica.com> References: <7cb4c226-d6bf-79a0-b4d8-6d40b55c1228@docbook-autor.de> <2CA2F29B-33CD-49AB-BFE6-A21979075AED@saxonica.com> Message-ID: <28f19ab2-ebbc-e8c1-2c80-eec76b9b430f@docbook-autor.de> Hi, > XQuery output has to be well-formed (and namespace-well-formed) XML, > so you can't output an element name like unless the > "ac" prefix is declared and bound to a namespace URI. Why would you > want to? Does Confluence really use non-namespace-aware XML? my xml output file will be some Confluence wiki page saved as file on the server so Confluence will load it on its next start-up. Inside Clonfluence the namespace "ac" surely will be well-formed but that is part of the higher-level "frame" where my xml file is loaded into. BTW: The Confluence Storage Format for wiki pages uses all its namespaces without namespace declaration inside the respective wiki page itself. That seems to be part of the Confluence framework. It is correct to demand the declaration of namespaces. I do not question that. But with declare option saxon:output "omit-xml-declaration=yes"; I can omit the xml declaration at the beginning of the xml output file. I need some parameter/option to omit every namespace declaration. Kind of: declare option saxon:output "omit-all-ns-declaration=yes"; So I declare the following namespace as I do it now: declare namespace ac="https://www.atlassian.com/schema/confluence/6/ac"; If not there will be an error message due to a missing namespace declaration. But the option above would leave the Confluence namespaced tags in my output file as they are: Is there a possibility to achieve this with XQuery or Saxon? Best regards from Germany Michael From mike at saxonica.com Wed Apr 19 03:28:16 2017 From: mike at saxonica.com (Michael Kay) Date: Wed, 19 Apr 2017 11:28:16 +0100 Subject: [xquery-talk] Omit namespace attributes in output file In-Reply-To: <28f19ab2-ebbc-e8c1-2c80-eec76b9b430f@docbook-autor.de> References: <7cb4c226-d6bf-79a0-b4d8-6d40b55c1228@docbook-autor.de> <2CA2F29B-33CD-49AB-BFE6-A21979075AED@saxonica.com> <28f19ab2-ebbc-e8c1-2c80-eec76b9b430f@docbook-autor.de> Message-ID: <41CBF406-E29A-4518-A77C-829534272DB1@saxonica.com> Sorry, but the XPath/XQuery data model has no way of representing an element node whose name has an undeclared prefix. XPath and XQuery work only with namespace-well-formed XML. If you really need this badly enough, you could either (a) post-process the serialized XML to strip off the namespace declarations (e.g. with a non-XML tool such as sed or awk), or (b) customize the Saxon serializer. Subclass net.sf.saxon.serialize.XMLEmitter to override the namespace() method, subclass net.sf.saxon.lib.SerializerFactory overriding the newXMLEmitter() method to instantiate your XMLEmitter subclass, and nominate your subclassed SerializerFactory using Configuration.setSerializerFactory() - not actually that difficult if you're comfortable with Java programming. Michael Kay Saxonica > On 19 Apr 2017, at 11:10, xquery at docbook-autor.de wrote: > > > Hi, > >> XQuery output has to be well-formed (and namespace-well-formed) XML, >> so you can't output an element name like unless the >> "ac" prefix is declared and bound to a namespace URI. Why would you >> want to? Does Confluence really use non-namespace-aware XML? > > my xml output file will be some Confluence wiki page saved as file on > the server so Confluence will load it on its next start-up. > > Inside Clonfluence the namespace "ac" surely will be well-formed but > that is part of the higher-level "frame" where my xml file is loaded into. > > BTW: The Confluence Storage Format for wiki pages uses all its > namespaces without namespace declaration inside the respective wiki page > itself. That seems to be part of the Confluence framework. > > It is correct to demand the declaration of namespaces. I do not question > that. But with > > declare option saxon:output "omit-xml-declaration=yes"; > > I can omit the xml declaration at the beginning of the xml output file. > I need some parameter/option to omit every namespace declaration. > > Kind of: > > declare option saxon:output "omit-all-ns-declaration=yes"; > > So I declare the following namespace as I do it now: > > declare namespace ac="https://www.atlassian.com/schema/confluence/6/ac"; > > If not there will be an error message due to a missing namespace > declaration. > > But the option above would leave the Confluence namespaced tags in my > output file as they are: > > > > Is there a possibility to achieve this with XQuery or Saxon? > > Best regards from Germany > Michael > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From xquery at docbook-autor.de Wed Apr 19 03:58:53 2017 From: xquery at docbook-autor.de (xquery at docbook-autor.de) Date: Wed, 19 Apr 2017 12:58:53 +0200 Subject: [xquery-talk] Omit namespace attributes in output file In-Reply-To: <41CBF406-E29A-4518-A77C-829534272DB1@saxonica.com> References: <7cb4c226-d6bf-79a0-b4d8-6d40b55c1228@docbook-autor.de> <2CA2F29B-33CD-49AB-BFE6-A21979075AED@saxonica.com> <28f19ab2-ebbc-e8c1-2c80-eec76b9b430f@docbook-autor.de> <41CBF406-E29A-4518-A77C-829534272DB1@saxonica.com> Message-ID: <6157690b-9dad-90eb-75e2-745f860924da@docbook-autor.de> Hi Michael, > (a) post-process the serialized XML to strip off the namespace declarations (e.g. with a non-XML tool such as sed or awk), or ok, first I have to check, whether Confluence is able to deal with namespace declarations inside a wiki page anyway. If yes anything is fine. If not the post-processing should do it. I'm starting the transformation with a script file so it should be easy to delete some text in the xml output file by script too. Fumbling around with standard sources is never a good idea (or at least should be the very last choice IMHO). Thanks for your quick help! Best regards from Germany Michael