From andrew.j.welch at gmail.com Thu May 5 05:44:34 2011 From: andrew.j.welch at gmail.com (Andrew Welch) Date: Thu, 5 May 2011 13:44:34 +0100 Subject: [xquery-talk] Is there any point of using xml:id with an xml db? Message-ID: Hi, Is there any benefit to using xml:id with an xml database, over a plain old id attribute with a range index? (lookup performance rather than uniqueness checking) Out of interest, if you did use xml:id and then create a range index for that, which would get used? -- Andrew Welch http://andrewjwelch.com From james.fuller.2007 at gmail.com Thu May 5 05:54:42 2011 From: james.fuller.2007 at gmail.com (James Fuller) Date: Thu, 5 May 2011 14:54:42 +0200 Subject: [xquery-talk] Is there any point of using xml:id with an xml db? In-Reply-To: References: Message-ID: On Thu, May 5, 2011 at 2:44 PM, Andrew Welch wrote: > Hi, > > Is there any benefit to using xml:id with an xml database, over a > plain old id attribute with a range index? ?(lookup performance rather > than uniqueness checking) lookup will be faster > Out of interest, if you did use xml:id and then create a range index > for that, which would get used? I would hope that a database would rewrite id() expressions to use a built-in index ... will check around to see what xml databases actually do. J ps: John Snelson, if you are listening this is probably a good candidate rule for your optimization rewrites ala http://www.xmlprague.cz/2011/sessions.html#Declarative-XQuery-Rewrites-for-Profit-or-Pleasure From mike at saxonica.com Thu May 5 07:17:23 2011 From: mike at saxonica.com (Michael Kay) Date: Thu, 05 May 2011 15:17:23 +0100 Subject: [xquery-talk] Is there any point of using xml:id with an xml db? In-Reply-To: References: Message-ID: <4DC2B173.7080307@saxonica.com> On 05/05/2011 13:44, Andrew Welch wrote: > Hi, > > Is there any benefit to using xml:id with an xml database, over a > plain old id attribute with a range index? (lookup performance rather > than uniqueness checking) > > Out of interest, if you did use xml:id and then create a range index > for that, which would get used? > > Well, it all rather depends on the implementation, doesn't it? Saxon automatically builds an index for ID values, but it only uses it to support the id() function. Should change that, really, since using [@xml:id='abc'] is generally more robust. Michael Kay Saxonica From andrew.j.welch at gmail.com Thu May 5 07:31:46 2011 From: andrew.j.welch at gmail.com (Andrew Welch) Date: Thu, 5 May 2011 15:31:46 +0100 Subject: [xquery-talk] Is there any point of using xml:id with an xml db? In-Reply-To: <4DC2B173.7080307@saxonica.com> References: <4DC2B173.7080307@saxonica.com> Message-ID: On 5 May 2011 15:17, Michael Kay wrote: > On 05/05/2011 13:44, Andrew Welch wrote: >> >> Hi, >> >> Is there any benefit to using xml:id with an xml database, over a >> plain old id attribute with a range index? ?(lookup performance rather >> than uniqueness checking) >> >> Out of interest, if you did use xml:id and then create a range index >> for that, which would get used? >> >> > Well, it all rather depends on the implementation, doesn't it? It started as a bit of a discussion on twitter about using xml:id in xquery... and then I thought what's the point - is there any when a db is involved? Using Saxon on the filesystem then I guess it would be a way of improving lookup performance by making up for the lack of keys in xquery... (guessing again), but in a db where you have range indexes it seems redundant. Also fwiw, there is a gotcha in going from //@id = '123' to id('123') as it will silently produce no output because of the NCName restriction (using Saxon)... -- Andrew Welch http://andrewjwelch.com From andrew.j.welch at gmail.com Fri May 6 00:15:21 2011 From: andrew.j.welch at gmail.com (Andrew Welch) Date: Fri, 6 May 2011 08:15:21 +0100 Subject: [xquery-talk] how can I compare each node with it's prior node In-Reply-To: References: Message-ID: On 6 May 2011 07:40, Kunal Chauhan wrote: > Hi, > > I have a document like > > > > > ???????? abc > ???????? 124 > ???????? xyz > ????????? 56 > > > > ????????? abc > ????????? 124 > ????????? xyz > ?????????? 56 > > > > > Now I want to chekc whether all price nodes are followed by item only. > How can I check this ? price/following-sibling::*[1][self:item] (your xml suggests item should be followed by price, but your description asks for the other way around...) -- Andrew Welch http://andrewjwelch.com From rpbourret at rpbourret.com Fri May 6 08:18:32 2011 From: rpbourret at rpbourret.com (Ronald Bourret) Date: Fri, 06 May 2011 08:18:32 -0700 Subject: [xquery-talk] how can I compare each node with it's prior node In-Reply-To: References: Message-ID: <4DC41148.2070505@rpbourret.com> You should also consider restructuring your XML so that it is clear which price belongs to which item. For example: abc xyz ... or: abc 124 xyz 56 ... -- Ron Kunal Chauhan wrote: > Hi, > > I want to check which node is above the price node. I want that node. > > > Thanks > > On Fri, May 6, 2011 at 12:45 PM, Andrew Welch > wrote: > > On 6 May 2011 07:40, Kunal Chauhan > wrote: > > Hi, > > > > I have a document like > > > > > > > > > > abc > > 124 > > xyz > > 56 > > > > > > > > abc > > 124 > > xyz > > 56 > > > > > > > > > > Now I want to chekc whether all price nodes are followed by item > only. > > How can I check this ? > > > price/following-sibling::*[1][self:item] > > (your xml suggests item should be followed by price, but your > description asks for the other way around...) > > > -- > Andrew Welch > http://andrewjwelch.com > > > > > -- > *Kunal Chauhan* > mail4ck at gmail.com > [+918655517141] > [+919904983614] > > > ------------------------------------------------------------------------ > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > > > ------------------------------------------------------------------------ > > No virus found in this message. > Checked by AVG - www.avg.com > Version: 10.0.1321 / Virus Database: 1500/3618 - Release Date: 05/05/11 > From gandhi.mukul at gmail.com Fri May 6 08:42:11 2011 From: gandhi.mukul at gmail.com (Mukul Gandhi) Date: Fri, 6 May 2011 21:12:11 +0530 Subject: [xquery-talk] how can I compare each node with it's prior node In-Reply-To: References: Message-ID: On Fri, May 6, 2011 at 1:14 PM, Kunal Chauhan wrote: > I want to check which node is above the price node. I want that node. There is no formal terminology as "above" in XPath data model. I think you would be meaning parent, preceding-sibling or a preceding direction. If it's parent, you can access that as .. or parent::* ; or using other axes as appropriate. Though, I agree with Ron, that restructuring your XML may help you query the data more easily. -- Regards, Mukul Gandhi From trubliphone at googlemail.com Fri May 6 16:29:16 2011 From: trubliphone at googlemail.com (trubliphone) Date: Fri, 6 May 2011 16:29:16 -0700 Subject: [xquery-talk] creating tree from sequence (from tree) Message-ID: Hello, I have an algorithmic problem I haven't been able to solve. I was hoping somebody on this list could offer me some advice. Suppose I have some arbitrary XML file: one two three four five Now, suppose there is a user-provided XPath expression to find particular nodes in that file: $query := "//foo/bar" I can evaluate that expression as follows: $doc := doc("myDocument.xml") $nodes := util:eval(concat("$doc",$query) This will return a sequence: (one, two, three, four, five) But I need to recreate the original hierarchical structure of those nodes. So what I really want is this: one two three four five To help, I can get the "context path" of each node as follows: $cp := string-join( for $ancestor in $node/ancestor-or-self::node() let $name := $ancestor/name() let $position := count($ancestor/preceding-sibling::node()[name()=$name])+1 return concat("/",$name,"[",$position,"]") ,"/") In the above example, this will return the following values for each node: one: /root[1]/foo[1]/bar[1] two: /root[1]/foo[1]/foo[1]/bar[1] three: /root[1]/foo[1]/foo[2]/bar[1] four: /root[1]/foo[2]/bar[1] five: /root[1]/foo[2]/foo[1]/foo[1]/bar[1] So I have the following sequence to work with: ( one, two, three, four, five ) My question is how to turn that into a tree that recreates the original hierarchical structure? Many thanks for your help. From gfourny at inf.ethz.ch Sat May 7 00:43:29 2011 From: gfourny at inf.ethz.ch (Ghislain Fourny) Date: Sat, 7 May 2011 07:43:29 +0000 Subject: [xquery-talk] creating tree from sequence (from tree) In-Reply-To: References: Message-ID: <88D94870-C138-4324-8085-3BB1D3632290@inf.ethz.ch> Hi, Would something like the following help? It organizes the selected nodes according to the hierarchy of their parents, which is my understanding of the problem statement (but I could be wrong). declare function local:filter($tree as node(), $selected-nodes as node()*) { let $selected-child := $selected-nodes[some $child in $tree/node() satisfies . is $child] let $recursively-filtered-children := for $n in $tree/node() return local:filter($n, $selected-nodes) return if ($selected-child) then element { name($selected-child[1]) } { $selected-child/attribute(), $selected-child/text(), $recursively-filtered-children } else $recursively-filtered-children }; I tested it with local:filter($doc, $nodes) with $doc and $nodes defined in your e-mail, and obtained the desired result. Kind regards, Ghislain From gkholman at CraneSoftwrights.com Sat May 7 05:16:17 2011 From: gkholman at CraneSoftwrights.com (G. Ken Holman) Date: Sat, 07 May 2011 08:16:17 -0400 Subject: [xquery-talk] creating tree from sequence (from tree) In-Reply-To: References: Message-ID: <7.0.1.0.2.20110507081049.024c6368@wheresmymailserver.com> At 2011-05-06 16:29 -0700, trubliphone wrote: >I have an algorithmic problem I haven't been able to solve. I was >hoping somebody on this list could offer me some advice. > >Suppose I have some arbitrary XML file: Given the nested in this file, I was immediately drawn to using XSLT and not XQuery. After solving the problem very succinctly in XSLT, that guided me in the writing of an XQuery solution. >Now, suppose there is a user-provided XPath expression to find >particular nodes in that file: > >$query := "//foo/bar" My solution is not so parameterized because neither XSLT nor XQuery have an eval() that would allow such an XPath expression to be dynamically evaluated as either a select expression or a match expression. Plus, I think starting at the bar elements presupposes an inefficient pull-style solution rather than a push-style solution. So you can ignore my answer if you wish, but for a push-style solution, please see the code below. >My question is how to turn that into a tree that recreates the >original hierarchical structure? I think it is more efficient to work from the original hierarchical structure and create the tree that you need. I hope you find the solutions below helpful. . . . . . . . . . Ken T:\ftemp>type t.xml one two three four five T:\ftemp>xquery t.xq onetwo three fourfive T:\ftemp>type t.xq declare function local:match( $nodes as node()* ) as node()* { for $node in $nodes return typeswitch( $node ) case element(foo) return if( $node/bar ) then {local:match(($node/bar/node(),$node/foo))} else local:match( $node/foo ) default return if( $node/self::text()/parent::bar ) then $node else () }; local:match( doc('t.xml')/root/* ) T:\ftemp>xslt t.xml t.xsl onetwothreefourfive T:\ftemp>type t.xsl T:\ftemp> -- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/q/ G. Ken Holman mailto:gkholman at CraneSoftwrights.com Legal business disclaimers: http://www.CraneSoftwrights.com/legal From gkholman at CraneSoftwrights.com Sat May 7 06:03:48 2011 From: gkholman at CraneSoftwrights.com (G. Ken Holman) Date: Sat, 07 May 2011 09:03:48 -0400 Subject: [xquery-talk] creating tree from sequence (from tree) In-Reply-To: References: Message-ID: <7.0.1.0.2.20110507085406.024bff58@wheresmymailserver.com> I took it as a challenge to use an arbitrary node set as you posited. At 2011-05-06 16:29 -0700, trubliphone wrote: >Now, suppose there is a user-provided XPath expression to find >particular nodes in that file: > >$query := "//foo/bar" > >I can evaluate that expression as follows: > >$doc := doc("myDocument.xml") >$nodes := util:eval(concat("$doc",$query) Lucky you ... I'm unfamiliar with util:eval() and so in my solution I just use standard XQuery. I'll just use the following in place of your code above: let $nodes:= doc('t.xml')//foo/bar >This will return a sequence: > >(one, two, three, four, >five) > >But I need to recreate the original hierarchical structure of those >nodes. So what I really want is this: > >one > two > three > >four > five > Which again means, I feel, it is easier to walk the original tree and only produce nodes when you need them. But with your constraint of building a sequence of candidate nodes to work with, that changes the way nodes in the tree are identified. So I used node identity to determine while walking the tree if the node I'm at is one of the nodes of interest. I hope the solution below helps. . . . . . . . Ken T:\ftemp>type t.xml one two three four five T:\ftemp>xquery t.xq onetwo three fourfive T:\ftemp>type t.xq declare function local:generate-id( $node as node() ) as xs:string { (:replace this in the future with a standard implementation of generate-id:) concat('N',count($node/preceding::node())) }; declare function local:outDescendants( $nodes as node()* ) as node()* { let $nodeIds := $nodes/local:generate-id(.) for $node in $nodes return let $ancestors := $node/ancestor::*/(* except $node)[local:generate-id(.) = $nodeIds] let $descendants := $node/..//(* except $node)[local:generate-id(.) = $nodeIds] return if ( $ancestors ) then () (:this node has already been handled:) else if ( $descendants ) then (:this node's descendants are in the list:) element { local-name($node) } { ( $node/text(), local:outDescendants( $descendants ) ) } else (:this is a leaf node and belongs in the result:) $node }; let $nodes:= doc('t.xml')//foo/bar return local:outDescendants( $nodes ) T:\ftemp> -- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/q/ G. Ken Holman mailto:gkholman at CraneSoftwrights.com Legal business disclaimers: http://www.CraneSoftwrights.com/legal From gkholman at CraneSoftwrights.com Sat May 7 06:11:42 2011 From: gkholman at CraneSoftwrights.com (G. Ken Holman) Date: Sat, 07 May 2011 09:11:42 -0400 Subject: [xquery-talk] creating tree from sequence (from tree) In-Reply-To: <7.0.1.0.2.20110507085406.024bff58@wheresmymailserver.com> References: <7.0.1.0.2.20110507085406.024bff58@wheresmymailserver.com> Message-ID: <7.0.1.0.2.20110507090839.024c6368@wheresmymailserver.com> At 2011-05-07 09:03 -0400, I wrote: >I took it as a challenge to use an arbitrary node set as you posited. The solution below might run a bit faster than my earlier solution ... I was checking ancestors and descendants at every level for the given node, when I need only exclude the given node from the set of ancestors and descendants. I hope this helps. . . . . . . . . Ken T:\ftemp>type t.xml one two three four five T:\ftemp>xquery t.xq onetwo three fourfive T:\ftemp>type t.xq declare function local:generate-id( $node as node() ) as xs:string { (:replace this in the future with a standard implementation of generate-id:) concat('N',count($node/preceding::node())) }; declare function local:outDescendants( $nodes as node()* ) as node()* { let $nodeIds := $nodes/local:generate-id(.) for $node in $nodes return let $ancestors := ($node/ancestor::*/* except $node)[local:generate-id(.) = $nodeIds] let $descendants := ($node/..//* except $node)[local:generate-id(.) = $nodeIds] return if ( $ancestors ) then () (:this node has already been handled:) else if ( $descendants ) then (:this node's descendants are in the list:) element { local-name($node) } { ( $node/text(), local:outDescendants( $descendants ) ) } else (:this is a leaf node and belongs in the result:) $node }; let $nodes:= doc('t.xml')//foo/bar return local:outDescendants( $nodes ) T:\ftemp> -- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/q/ G. Ken Holman mailto:gkholman at CraneSoftwrights.com Legal business disclaimers: http://www.CraneSoftwrights.com/legal From joewiz at gmail.com Sun May 8 09:20:57 2011 From: joewiz at gmail.com (Joe Wicentowski) Date: Sun, 8 May 2011 12:20:57 -0400 Subject: [xquery-talk] Is there any point of using xml:id with an xml db? In-Reply-To: References: Message-ID: Hi Andrew, > Is there any benefit to using xml:id with an xml database, over a > plain old id attribute with a range index? ?(lookup performance rather > than uniqueness checking) > > Out of interest, if you did use xml:id and then create a range index > for that, which would get used? In the case of eXist, eXist by default creates an index for @xml:id values, which it uses to resolve calls to fn:id(), so you don't need to define an extra range index on @xml:id if you're only using fn:id(). However, if you are making a general comparison, i.e. //node[@xml:id = 'abc'], then defining an additional range index will speed up your query. For a bit more on this (including attributes defined as ID in a DTD), see the "Database Tuning" article http://exist-db.org/tuning.html#N10382. Cheers, Joe From trubliphone at googlemail.com Tue May 10 12:30:18 2011 From: trubliphone at googlemail.com (trubliphone) Date: Tue, 10 May 2011 12:30:18 -0700 Subject: [xquery-talk] creating tree from sequence (from tree) In-Reply-To: <88D94870-C138-4324-8085-3BB1D3632290@inf.ethz.ch> References: <88D94870-C138-4324-8085-3BB1D3632290@inf.ethz.ch> Message-ID: Hi, Thanks very much for this. It basically does the trick. There are some nuances in the real problem that need addressing, but you've got me 90% of the way there. On Sat, May 7, 2011 at 12:43 AM, Ghislain Fourny wrote: > Hi, > > Would something like the following help? It organizes the selected nodes according to the hierarchy of their parents, which is my understanding of the problem statement (but I could be wrong). > > declare function local:filter($tree as node(), $selected-nodes as node()*) { > ?let $selected-child := > ? ?$selected-nodes[some $child in $tree/node() satisfies . is $child] > ?let $recursively-filtered-children := > ? ?for $n in $tree/node() return local:filter($n, $selected-nodes) > ?return > ? ?if ($selected-child) > ? ?then > ? ? ?element > ? ? ?{ name($selected-child[1]) } > ? ? ?{ $selected-child/attribute(), > ? ? ? ?$selected-child/text(), > ? ? ? ?$recursively-filtered-children } > ? ?else > ? ? ?$recursively-filtered-children > }; > > I tested it with local:filter($doc, $nodes) with $doc and $nodes defined in your e-mail, and obtained the desired result. > > Kind regards, > Ghislain > > From daniel.ebner at uni-koeln.de Wed May 11 04:22:48 2011 From: daniel.ebner at uni-koeln.de (Daniel Ebner) Date: Wed, 11 May 2011 13:22:48 +0200 Subject: [xquery-talk] Querying XSD Message-ID: <4DCA7188.3040300@uni-koeln.de> Hi everyone! I'm currently looking for a xQuery Script that allows to query an XML Schema file. I'm writing an XML-Editor that allows the user to mark up text. When the user selects parts of the XML he/she should see all possible Elements which he/sche can insert. I have the context of the selection as a XPath. No I'm looking fpr an XQuery Script that querys an XSD an gives back all possible children elements. Has anyone seen, tried, implemented or thought of somthing like this? Thanks Daniel -- Daniel Ebner Dipl.-Medienwissenschaftler, Wiss. Mitarbeiter Historisch-Kulturwissenschaftliche Informationsverarbeitung University at Cologne Albertus-Magnus-Platz D 50923 Cologne daniel.ebner at uni-koeln.de Tel.: +49 - 221 - 470 7736 Fax: +49 - 221 - 470 7737 www.hki.uni-koeln.de From dlee at calldei.com Wed May 11 04:27:45 2011 From: dlee at calldei.com (David Lee) Date: Wed, 11 May 2011 07:27:45 -0400 Subject: [xquery-talk] Querying XSD In-Reply-To: <4DCA7188.3040300@uni-koeln.de> References: <4DCA7188.3040300@uni-koeln.de> Message-ID: <002e01cc0fce$742f2c70$5c8d8550$@calldei.com> XSD is complex especially in the presence of types and imports. What I did to accomplish a similar thing was to preprocess the XSD with the Apache Schema API and produce a "simpler" XML file which was more amenable to querying. But "simpler" means less information. I extracted what I wanted and omitted the rest. The Apache Schema API will handle resolving types and let you start with all global elements and walk down through the structure to all child elements and attributes even as it crosses type, inherited, and import boundaries. ---------------------------------------- David A. Lee dlee at calldei.com http://www.xmlsh.org -----Original Message----- From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of Daniel Ebner Sent: Wednesday, May 11, 2011 7:23 AM To: talk at x-query.com Subject: [xquery-talk] Querying XSD Hi everyone! I'm currently looking for a xQuery Script that allows to query an XML Schema file. I'm writing an XML-Editor that allows the user to mark up text. When the user selects parts of the XML he/she should see all possible Elements which he/sche can insert. I have the context of the selection as a XPath. No I'm looking fpr an XQuery Script that querys an XSD an gives back all possible children elements. Has anyone seen, tried, implemented or thought of somthing like this? Thanks Daniel -- Daniel Ebner Dipl.-Medienwissenschaftler, Wiss. Mitarbeiter Historisch-Kulturwissenschaftliche Informationsverarbeitung University at Cologne Albertus-Magnus-Platz D 50923 Cologne daniel.ebner at uni-koeln.de Tel.: +49 - 221 - 470 7736 Fax: +49 - 221 - 470 7737 www.hki.uni-koeln.de _______________________________________________ talk at x-query.com http://x-query.com/mailman/listinfo/talk From mike at saxonica.com Wed May 11 05:25:53 2011 From: mike at saxonica.com (Michael Kay) Date: Wed, 11 May 2011 13:25:53 +0100 Subject: [xquery-talk] Querying XSD In-Reply-To: <4DCA7188.3040300@uni-koeln.de> References: <4DCA7188.3040300@uni-koeln.de> Message-ID: <4DCA8051.5070203@saxonica.com> On 11/05/2011 12:22, Daniel Ebner wrote: > Hi everyone! > > I'm currently looking for a xQuery Script that allows to query an XML > Schema file. I'm writing an XML-Editor that allows the user to mark up > text. When the user selects parts of the XML he/she should see all > possible Elements which he/sche can insert. I have the context of the > selection as a XPath. No I'm looking fpr an XQuery Script that querys > an XSD an gives back all possible children elements. > > Has anyone seen, tried, implemented or thought of somthing like this? > > Thanks Daniel > Working from raw schema documents is tricky, because you essentially have to reproduce all the logic of translating from the XML representation to the schema component model. It's better to work from the component model directly. Saxon's schema processor will generate an SCM file which is a rather literal XML dump of the schema components. It also includes a dump of the finite state machines for validating against complex types, which you might be able to take advantage of. Michael Kay Saxonica From wcandillon at gmail.com Wed May 11 07:14:08 2011 From: wcandillon at gmail.com (William Candillon) Date: Wed, 11 May 2011 14:14:08 +0000 Subject: [xquery-talk] Second Zurich XQuery Meetup, July 7th 2011 Message-ID: Hi gang, The second Zurich XQuery Meetup will be held in ETH Dozentenfoyer on July 7th 2011. More details at http://xquery.pbworks.com/Zurich-Meetup-2. Registration is done on the wiki. You can checkout pictures and talks from last year meetup at http://xquery.pbworks.com/Zurich-Meetup Best regards, William From mattio.valentino at gmail.com Wed May 11 17:51:24 2011 From: mattio.valentino at gmail.com (Mattio Valentino) Date: Wed, 11 May 2011 20:51:24 -0400 Subject: [xquery-talk] Roman numeral kata in XQuery Message-ID: Hello, I hope this isn't too odd of a request. I wanted a little XQuery practice so I decided to try to port some code katas. I did the Roman numeral one first. Would anyone mind reviewing the solution I have here? http://bitbucket.org/mattio/xquery-katas/src/5ffd02da6f83/src/roman-numerals.xq There's no point practicing if I'm just going to reinforce bad habits! ;-) Thanks, Mattio From andrew.j.welch at gmail.com Thu May 12 00:37:48 2011 From: andrew.j.welch at gmail.com (Andrew Welch) Date: Thu, 12 May 2011 08:37:48 +0100 Subject: [xquery-talk] Roman numeral kata in XQuery In-Reply-To: References: Message-ID: On 12 May 2011 01:51, Mattio Valentino wrote: > Hello, > > I hope this isn't too odd of a request. > > I wanted a little XQuery practice so I decided to try to port some > code katas. I did the Roman numeral one first. > > Would anyone mind reviewing the solution I have here? > http://bitbucket.org/mattio/xquery-katas/src/5ffd02da6f83/src/roman-numerals.xq Looks good to me. There are a couple of small things: - you could use eq instead of = when comparing single items, eg $input eq 'M'. This will cause an exception if for some reason either side becomes a sequence of multiple items instead of a single one... whereas the set operator '=' will just carry on working and is likely to produce incorrect results. - you could use the 'as' to type your variables: let $numbers as xs:integer+ := .... An alternative to the if-then-else that you ask about could be done like this: declare variable $letters as xs:string+ := ('I', 'V', 'X', 'L', 'C', 'D', 'M'); declare variable $numbers as xs:integer+ := (1,5,10,50,100,500,1000); ($numbers[index-of($letters, 'I')], 0)[1] The two sequences are global variables so they only get created once, and then you use the position (index-of) of the letter in its sequence to get the corresponding number. The ( ...., 0)[1] is a common way of defaulting to a value (zero here) if the first part returns nothing. cheers andrew -- Andrew Welch http://andrewjwelch.com From matthias.brantner at 28msec.com Mon May 16 10:37:08 2011 From: matthias.brantner at 28msec.com (Matthias Brantner) Date: Mon, 16 May 2011 10:37:08 -0700 Subject: [xquery-talk] Roman numeral kata in XQuery In-Reply-To: References: Message-ID: Mattio, some XQuery processors (e.g. Zorba) already implement the latest working draft of XQuery 3.0 (see http://www.w3.org/TR/xquery-30/). This provides two interesting features related to your example. 1. A switch expression (http://www.w3.org/TR/xquery-30/#id-switch) switch ($input) case "I" return 1 case "V" return 5 case "X" return 10 case "L" return 50 case "C" return 100 case "D" return 500 case "M" return 1000 default return 0 2. The XQuery 3.0 function library (see http://www.w3.org/TR/xpath-functions-30/#func-format-integer) provides a function for the reverse conversion (i.e. integer to roman numeral). For example, format-integer(55, 'I'). Best regards Matthias On May 11, 2011, at 5:51 PM, Mattio Valentino wrote: > Hello, > > I hope this isn't too odd of a request. > > I wanted a little XQuery practice so I decided to try to port some > code katas. I did the Roman numeral one first. > > Would anyone mind reviewing the solution I have here? > http://bitbucket.org/mattio/xquery-katas/src/5ffd02da6f83/src/roman-numerals.xq > > There's no point practicing if I'm just going to reinforce bad habits! ;-) > > Thanks, > Mattio > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From schassan at hab.de Tue May 24 06:57:58 2011 From: schassan at hab.de (Torsten Schassan) Date: Tue, 24 May 2011 15:57:58 +0200 Subject: [xquery-talk] sorting problem Message-ID: <4DDBB966.2080203@hab.de> Hi considered strings like these: 11 Aug. 2? 10 Aug. 4? 3.1.1 Aug. 2? A Aug. 2? 1 Weiss. How would I sort them using XQuery according to this succession - letters in the middle first (Aug etc) - the sizes (2? etc) - "front" letters before numbers - numbers according to their position before the dots Sorting result for the examples above would then be: A Aug. 2? 3.1.1 Aug. 2? 11 Aug. 2? 10 Aug. 4? 1 Weiss. Would that be done best with tokenize() or matches()? Best, Torsten -- Torsten Schassan Digitale Editionen Abteilung Handschriften und Sondersammlungen Herzog August Bibliothek, Postfach 1364, D-38299 Wolfenbuettel Tel.: +49-5331-808-130 (Fax -165), schassan {at} hab.de http://www.hab.de/forschung/projekte/europeana-regia.htm http://www.hab.de/forschung/projekte/weiss64.htm From gfourny at inf.ethz.ch Tue May 24 07:16:25 2011 From: gfourny at inf.ethz.ch (Ghislain Fourny) Date: Tue, 24 May 2011 14:16:25 +0000 Subject: [xquery-talk] Parse XQuery for Predicates In-Reply-To: References: Message-ID: <9C5163DF-AD96-484F-9C70-E12DB5842AFD@inf.ethz.ch> Hi Sri, XQuery also exists as XQueryX, which is in XML format (it is kind of an XML representation of the program's abstract syntax tree). http://www.w3.org/TR/xqueryx/ If you can convert your program to XQueryX and treat it as an XML document, then you can use... XQuery to navigate to all the predicates it contains. Something simple like: //xqx:predicate might be enough, but of course the possibilities are only limited by Turing-completeness. Also, you might need to do the conversion back to the XQuery syntax. Does it make sense? Kind regards, Ghislain From gkholman at CraneSoftwrights.com Tue May 24 09:29:02 2011 From: gkholman at CraneSoftwrights.com (G. Ken Holman) Date: Tue, 24 May 2011 12:29:02 -0400 Subject: [xquery-talk] sorting problem In-Reply-To: <4DDBB966.2080203@hab.de> References: <4DDBB966.2080203@hab.de> Message-ID: <7.0.1.0.2.20110524105429.024a8448@wheresmymailserver.com> At 2011-05-24 15:57 +0200, Torsten Schassan wrote: >Hi >... >considered strings like these: > >11 Aug. 2? >10 Aug. 4? >3.1.1 Aug. 2? >A Aug. 2? >1 Weiss. > > >How would I sort them using XQuery according to this succession > >- letters in the middle first (Aug etc) >- the sizes (2? etc) >- "front" letters before numbers >- numbers according to their position before the dots > >... > >Sorting result for the examples above would then be: > >A Aug. 2? >3.1.1 Aug. 2? >11 Aug. 2? >10 Aug. 4? >1 Weiss. > > > >Would that be done best with tokenize() or matches()? Between the two, since matches() returns only true/false, only tokenize() would return meaningful values, but I don't think that will help you. The only way I could do it was rearranging the content in the order desired by using replace(), and then taking advantage of a Saxon-specific collation order "alphanumeric" to address the field with the numbers and dots. I think it would take quite a bit of code to address the alphanumeric collation requirement other than with a custom collation. I hope the running example below helps as it matches your requirement. . . . . . . . . . . Ken ~/t/ftemp $ sh t.sh + cat torsten.xquery declare variable $s := ( '11 Aug. 2?', '10 Aug. 4?', '3.1.1 Aug. 2?', 'A Aug. 2?', '1 Weiss.' ); " ===Input: ", for $each in $s return ( $each," " ) ,"===Result: ", for $each in $s order by replace( $each, "(([A-Za-z]+)|([0123456789.]+))\s+(\S+)\s*([^\s]*)", "1 $4 $5 $2ZZZ$3" ) collation "http://saxon.sf.net/collation?alphanumeric=yes" return ( $each, " " ) + xquery torsten.xquery ===Input: 11 Aug. 2? 10 Aug. 4? 3.1.1 Aug. 2? A Aug. 2? 1 Weiss. ===Result: A Aug. 2? 3.1.1 Aug. 2? 11 Aug. 2? 10 Aug. 4? 1 Weiss. + cat torsten-explain.xquery declare variable $s := ( '11 Aug. 2?', '10 Aug. 4?', '3.1.1 Aug. 2?', 'A Aug. 2?', '1 Weiss.' ); " ===Input: ", for $each in $s return ( $each," " ) ,"===Parts: ", let $srq := for $each in $s return replace( $each, "(([A-Za-z]+)|([0123456789.]+))\s+(\S+)\s*([^\s]*)", "1 '$4' '$5' '$2'ZZZ'$3'" ) let $sr := for $each in $s return replace( $each, "(([A-Za-z]+)|([0123456789.]+))\s+(\S+)\s*([^\s]*)", "1 $4 $5 $2ZZZ$3" ) return ( for $each in $srq return ( $each, " " ),'==(no quotes) ', for $each in $sr return ( $each, " " ) ,"===Parts ordered: ", for $each in $sr order by $each return ( $each, " " ) ,"===Parts ordered alphanumeric: ", for $each in $sr order by $each collation "http://saxon.sf.net/collation?alphanumeric=yes" return ( $each, " " ) ) ,"===All you need for your result: ", for $each in $s order by replace( $each, "(([A-Za-z]+)|([0123456789.]+))\s+(\S+)\s*([^\s]*)", "1 $4 $5 $2ZZZ$3" ) collation "http://saxon.sf.net/collation?alphanumeric=yes" return ( $each, " " ) + xquery torsten-explain.xquery ===Input: 11 Aug. 2? 10 Aug. 4? 3.1.1 Aug. 2? A Aug. 2? 1 Weiss. ===Parts: 1 'Aug.' '2?' ''ZZZ'11' 1 'Aug.' '4?' ''ZZZ'10' 1 'Aug.' '2?' ''ZZZ'3.1.1' 1 'Aug.' '2?' 'A'ZZZ'' 1 'Weiss.' '' ''ZZZ'1' ==(no quotes) 1 Aug. 2? ZZZ11 1 Aug. 4? ZZZ10 1 Aug. 2? ZZZ3.1.1 1 Aug. 2? AZZZ 1 Weiss. ZZZ1 ===Parts ordered: 1 Aug. 2? AZZZ 1 Aug. 2? ZZZ11 1 Aug. 2? ZZZ3.1.1 1 Aug. 4? ZZZ10 1 Weiss. ZZZ1 ===Parts ordered alphanumeric: 1 Aug. 2? AZZZ 1 Aug. 2? ZZZ3.1.1 1 Aug. 2? ZZZ11 1 Aug. 4? ZZZ10 1 Weiss. ZZZ1 ===All you need for your result: A Aug. 2? 3.1.1 Aug. 2? 11 Aug. 2? 10 Aug. 4? 1 Weiss. ~/t/ftemp $ -- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/q/ G. Ken Holman mailto:gkholman at CraneSoftwrights.com Legal business disclaimers: http://www.CraneSoftwrights.com/legal From Gunther.Rademacher at softwareag.com Wed May 25 04:06:19 2011 From: Gunther.Rademacher at softwareag.com (Rademacher, Gunther) Date: Wed, 25 May 2011 13:06:19 +0200 Subject: [xquery-talk] sorting problem In-Reply-To: <4DDBB966.2080203@hab.de> References: <4DDBB966.2080203@hab.de> Message-ID: It can be done using tokenize() and matches() by directly translating your requirements into a list of ordering specifications: for $string in ( "11 Aug. 2?", "10 Aug. 4?", "3.1.1 Aug. 2?", "A Aug. 2?", "1 Weiss." ) order by tokenize($string, " ")[2], tokenize($string, " ")[3], matches($string, "^[A-Za-z]") descending, number(tokenize($string, "[. ]")[1]) return $string Software AG - Group Executive Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Arnd Zinnhardt, Mark Edwards, David Broadbent, Dr. Hans Kraus, Dr. Wolfram Jost, Kamyar Niroumand, Ivo Totev Sitz/Registered office: Uhlandstra?e 12, 64297 Darmstadt, Germany, - Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/ Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), David Broadbent, Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/ Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com/ -----Original Message----- From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of Torsten Schassan Sent: Tuesday, May 24, 2011 15:58 To: XQuery Mailingliste Subject: [xquery-talk] sorting problem Hi considered strings like these: 11 Aug. 2? 10 Aug. 4? 3.1.1 Aug. 2? A Aug. 2? 1 Weiss. How would I sort them using XQuery according to this succession - letters in the middle first (Aug etc) - the sizes (2? etc) - "front" letters before numbers - numbers according to their position before the dots Sorting result for the examples above would then be: A Aug. 2? 3.1.1 Aug. 2? 11 Aug. 2? 10 Aug. 4? 1 Weiss. Would that be done best with tokenize() or matches()? From leo.studer at varioweb.ch Thu May 26 03:42:35 2011 From: leo.studer at varioweb.ch (Leo Studer) Date: Thu, 26 May 2011 12:42:35 +0200 Subject: [xquery-talk] namespace declarations in an element Message-ID: Hello can anyone help how I get the three namespaces out of with xpath/xquery? Thanks in advance Leo From gfourny at inf.ethz.ch Thu May 26 04:01:56 2011 From: gfourny at inf.ethz.ch (Ghislain Fourny) Date: Thu, 26 May 2011 11:01:56 +0000 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: References: Message-ID: Hi Leo, The only XPath/XQuery standard I am aware of which provides namespace axes is XPath 1.0: http://www.w3.org/TR/xpath/#axes You can navigate to the corresponding nodes using path expressions. If I am correct, they were then deprecated in subsequent versions of XPath, and XQuery does not support them either. However, I can imagine that an implementation may provide its own functions for querying the namespace bindings. I hope this helps? Kind regards, Ghislain On May 26, 2011, at 12:42 PM, Leo Studer wrote: > Hello > > can anyone help how I get the three namespaces out of with xpath/xquery? > > > > > > > > > Thanks in advance > Leo > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From mike at saxonica.com Thu May 26 04:08:45 2011 From: mike at saxonica.com (Michael Kay) Date: Thu, 26 May 2011 12:08:45 +0100 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: References: Message-ID: <4DDE34BD.109@saxonica.com> On 26/05/2011 11:42, Leo Studer wrote: > Hello > > can anyone help how I get the three namespaces out of with xpath/xquery? > > > > > > > > > Thanks in advance > Leo > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > When you say "get them out", do you mean "retrieve them" or "remove them"? Excuse my poor American. Michael Kay Saxonica From leo.studer at varioweb.ch Thu May 26 06:11:57 2011 From: leo.studer at varioweb.ch (Leo Studer) Date: Thu, 26 May 2011 15:11:57 +0200 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <4DDE34BD.109@saxonica.com> References: <4DDE34BD.109@saxonica.com> Message-ID: <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> Hello I would like to do something like for $i in /root/namespaces ... to use them for further processing in a query. Cheers Leo On 26.05.2011, at 13:08, Michael Kay wrote: On 26/05/2011 11:42, Leo Studer wrote: > Hello > > can anyone help how I get the three namespaces out of with xpath/xquery? > > > > > > > > > Thanks in advance > Leo > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > When you say "get them out", do you mean "retrieve them" or "remove them"? Excuse my poor American. Michael Kay Saxonica _______________________________________________ talk at x-query.com http://x-query.com/mailman/listinfo/talk From mike at saxonica.com Thu May 26 06:34:50 2011 From: mike at saxonica.com (Michael Kay) Date: Thu, 26 May 2011 14:34:50 +0100 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> References: <4DDE34BD.109@saxonica.com> <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> Message-ID: <4DDE56FA.8030000@saxonica.com> On 26/05/2011 14:11, Leo Studer wrote: > Hello > > I would like to do something like > > for $i in /root/namespaces ... > > to use them for further processing in a query. > You can do this using the functions fn:in-scope-prefixes() and fn:namespace-uri-for-prefix() Michael Kay Saxonica From gfourny at inf.ethz.ch Thu May 26 06:53:13 2011 From: gfourny at inf.ethz.ch (Ghislain Fourny) Date: Thu, 26 May 2011 13:53:13 +0000 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <4DDE56FA.8030000@saxonica.com> References: <4DDE34BD.109@saxonica.com> <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> <4DDE56FA.8030000@saxonica.com> Message-ID: Hi Michael, True, I forgot about in-scope-prefixes :-) So this is a standardized way of accessing namespace bindings. Thanks a lot for the correction! The links are here: http://www.w3.org/TR/xpath-functions/#func-in-scope-prefixes http://www.w3.org/TR/xpath-functions/#func-namespace-uri-for-prefix Kind regards, Ghislain On May 26, 2011, at 3:34 PM, Michael Kay wrote: > On 26/05/2011 14:11, Leo Studer wrote: >> Hello >> >> I would like to do something like >> >> for $i in /root/namespaces ... >> >> to use them for further processing in a query. >> > > You can do this using the functions fn:in-scope-prefixes() and fn:namespace-uri-for-prefix() > > Michael Kay > Saxonica > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From leo.studer at varioweb.ch Thu May 26 07:14:21 2011 From: leo.studer at varioweb.ch (Leo Studer) Date: Thu, 26 May 2011 16:14:21 +0200 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: References: <4DDE34BD.109@saxonica.com> <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> <4DDE56FA.8030000@saxonica.com> Message-ID: <22E67E80-DA4A-4696-8B3B-E87960D237E8@varioweb.ch> Hi Michael and Ghislain thank you for your input. Indeed with those two functions I get the prefixes and the namespaces as I need them. Now a related question. How do I generate such namespaces in an element with xQuery? to create root with a namespace I do with element{QName("http://test.ch", "root")}{...} but how to get other namespace declarations in an element I ignore. Thanks again for caring Leo From gfourny at inf.ethz.ch Thu May 26 07:23:33 2011 From: gfourny at inf.ethz.ch (Ghislain Fourny) Date: Thu, 26 May 2011 14:23:33 +0000 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <22E67E80-DA4A-4696-8B3B-E87960D237E8@varioweb.ch> References: <4DDE34BD.109@saxonica.com> <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> <4DDE56FA.8030000@saxonica.com> <22E67E80-DA4A-4696-8B3B-E87960D237E8@varioweb.ch> Message-ID: Hi Leo, In XQuery 3.0 you have namespace node constructors which might be what you are looking for. Or you can also simply build the elements a:test, b:test, c:test just like the root element and let the serializer do the job, but the namespace declarations might not end up at the same place in the output document. I hope this helps. Kind regards, Ghislain On May 26, 2011, at 4:14 PM, Leo Studer wrote: > Hi Michael and Ghislain > > thank you for your input. Indeed with those two functions I get the prefixes and the namespaces as I need them. > > Now a related question. How do I generate such namespaces in an element with xQuery? > > > > > > > > to create root with a namespace I do with > element{QName("http://test.ch", "root")}{...} > > but how to get other namespace declarations in an element I ignore. > > Thanks again for caring > Leo > > > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From mike at saxonica.com Thu May 26 07:27:35 2011 From: mike at saxonica.com (Michael Kay) Date: Thu, 26 May 2011 15:27:35 +0100 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <22E67E80-DA4A-4696-8B3B-E87960D237E8@varioweb.ch> References: <4DDE34BD.109@saxonica.com> <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> <4DDE56FA.8030000@saxonica.com> <22E67E80-DA4A-4696-8B3B-E87960D237E8@varioweb.ch> Message-ID: <4DDE6357.9040404@saxonica.com> On 26/05/2011 15:14, Leo Studer wrote: > Hi Michael and Ghislain > > thank you for your input. Indeed with those two functions I get the prefixes and the namespaces as I need them. > > Now a related question. How do I generate such namespaces in an element with xQuery? > XQuery 1.0 does not have a facility for generating namespaces dynamically (i.e. namespaces that aren't known at compile time, and aren't used in element or attribute names.) This is fixed in 3.0. There's a workaround invented by David Carlisle which I can't lay my hands on at the moment. It involves using a computed attribute constructor to create an attribute in the desired namespace, copying this attribute to the target element, then discarding the attribute again - but I forget the details. Michael Kay Saxonica From davidc at nag.co.uk Thu May 26 07:32:36 2011 From: davidc at nag.co.uk (David Carlisle) Date: Thu, 26 May 2011 15:32:36 +0100 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: References: <4DDE34BD.109@saxonica.com> <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> <4DDE56FA.8030000@saxonica.com> <22E67E80-DA4A-4696-8B3B-E87960D237E8@varioweb.ch> Message-ID: <4DDE6484.60404@nag.co.uk> On 26/05/2011 15:23, Ghislain Fourny wrote: > Hi Leo, > > In XQuery 3.0 you have namespace node constructors which might be what you are looking for. > > Or you can also simply build the elements a:test, b:test, c:test just like the root element and let the serializer do the job, but the namespace declarations might not end up at the same place in the output document. > > I hope this helps. > > Kind regards, > Ghislain > If you do need to generate namespace declarations (perhaps for namespace values in attribute values such as xpath or xsd types rather than element names) in xquery 1 rather than 3 you can use http://fgeorges.blogspot.com/2006/08/add-namespace-node-to-element-in.html David ________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________ From gfourny at inf.ethz.ch Thu May 26 07:37:00 2011 From: gfourny at inf.ethz.ch (Ghislain Fourny) Date: Thu, 26 May 2011 14:37:00 +0000 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <4DDE6357.9040404@saxonica.com> References: <4DDE34BD.109@saxonica.com> <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> <4DDE56FA.8030000@saxonica.com> <22E67E80-DA4A-4696-8B3B-E87960D237E8@varioweb.ch> <4DDE6357.9040404@saxonica.com> Message-ID: Hi Michael, I think this might be what you are referring to (you sent the link in an earlier message): > There's a workaround described here: > > http://fgeorges.blogspot.com/2006/08/add-namespace-node-to-element-in.html > > (It's not that dissimilar from the workaround you have to use in XSLT 1.0.) > > Michael Kay > Saxonica Kind regards, Ghislain > There's a workaround invented by David Carlisle which I can't lay my hands on at the moment. It involves using a computed attribute constructor to create an attribute in the desired namespace, copying this attribute to the target element, then discarding the attribute again - but I forget the details. > > Michael Kay > Saxonica > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From davidc at nag.co.uk Thu May 26 07:36:55 2011 From: davidc at nag.co.uk (David Carlisle) Date: Thu, 26 May 2011 15:36:55 +0100 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <4DDE6357.9040404@saxonica.com> References: <4DDE34BD.109@saxonica.com> <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> <4DDE56FA.8030000@saxonica.com> <22E67E80-DA4A-4696-8B3B-E87960D237E8@varioweb.ch> <4DDE6357.9040404@saxonica.com> Message-ID: <4DDE6587.7090705@nag.co.uk> On 26/05/2011 15:27, Michael Kay wrote: > here's a workaround invented by David Carlisle which I can't lay my > hands on at the moment. so had I but I did http://lmgtfy.com/?q=xquery+generate+namespace and surprisingly enough it was the first returned result:-) David ________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________ From lists at fgeorges.org Thu May 26 07:39:57 2011 From: lists at fgeorges.org (Florent Georges) Date: Thu, 26 May 2011 15:39:57 +0100 (BST) Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <4DDE6357.9040404@saxonica.com> Message-ID: <918235.46927.qm@web29507.mail.ird.yahoo.com> Michael Kay wrote: Hi, > There's a workaround invented by David Carlisle which I > can't lay my hands on at the moment. It involves using a > computed attribute constructor to create an attribute in the > desired namespace, copying this attribute to the target > element, then discarding the attribute again - but I forget > the details. You dynamically construct an element within the namespace you want, with the prefix you want, and add your element to that temporary wrapper, then select it back. This copy must thus inherit the namespace declaration (but you get a copy of course): http://fgeorges.blogspot.com/2006/08/add-namespace-node-to-element-in.html Regards, -- Florent Georges http://fgeorges.org/ From leo.studer at varioweb.ch Thu May 26 07:40:19 2011 From: leo.studer at varioweb.ch (Leo Studer) Date: Thu, 26 May 2011 16:40:19 +0200 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <4DDE6357.9040404@saxonica.com> References: <4DDE34BD.109@saxonica.com> <8DA84772-4117-42FD-8C48-B0EA5DAA1D43@varioweb.ch> <4DDE56FA.8030000@saxonica.com> <22E67E80-DA4A-4696-8B3B-E87960D237E8@varioweb.ch> <4DDE6357.9040404@saxonica.com> Message-ID: <4E60DFD8-B0FB-4566-9E9F-660CC4582B1F@varioweb.ch> Thanks Michael and Ghislain for your fast answers. Always Leo From dflorescu at mac.com Thu May 26 11:24:43 2011 From: dflorescu at mac.com (daniela florescu) Date: Thu, 26 May 2011 11:24:43 -0700 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <918235.46927.qm@web29507.mail.ird.yahoo.com> References: <918235.46927.qm@web29507.mail.ird.yahoo.com> Message-ID: This solution looses the original types, which for semi-structured data are essential. Cheers Dana On May 26, 2011, at 7:39 AM, Florent Georges wrote: > Michael Kay wrote: > > Hi, > >> There's a workaround invented by David Carlisle which I >> can't lay my hands on at the moment. It involves using a >> computed attribute constructor to create an attribute in the >> desired namespace, copying this attribute to the target >> element, then discarding the attribute again - but I forget >> the details. > > You dynamically construct an element within the namespace you > want, with the prefix you want, and add your element to that > temporary wrapper, then select it back. This copy must thus > inherit the namespace declaration (but you get a copy of course): > > http://fgeorges.blogspot.com/2006/08/add-namespace-node-to-element-in.html > > Regards, > > -- > Florent Georges > http://fgeorges.org/ > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From davidc at nag.co.uk Thu May 26 11:46:04 2011 From: davidc at nag.co.uk (David Carlisle) Date: Thu, 26 May 2011 19:46:04 +0100 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: References: <918235.46927.qm@web29507.mail.ird.yahoo.com> Message-ID: <4DDE9FEC.9030900@nag.co.uk> On 26/05/2011 19:24, daniela florescu wrote: > This solution looses the original types, which for semi-structured data are essential. I'm not sure I understand that comment, the solution is about adding a namespace node to a constructed element, that dpesn't lose type information. If the data you are outputting is placed into am element attribute or content then that's essentially just outputting its string value and losing type information unless the constructed element is re-validated, but adding a namespace node isn't the cause of that loss. David From dflorescu at mac.com Thu May 26 12:50:00 2011 From: dflorescu at mac.com (daniela florescu) Date: Thu, 26 May 2011 12:50:00 -0700 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <4DDE9FEC.9030900@nag.co.uk> References: <918235.46927.qm@web29507.mail.ird.yahoo.com> <4DDE9FEC.9030900@nag.co.uk> Message-ID: If the input element was already schema validated: this transformation will add indeed a namespace, but will loose the original type annotation of the element that was given as result of schema validation. The result will end up untyped (unlike the original element). That's a serious problem for semi-structured databases. It's the fault of the semantics of node copying. Cheers Dana On May 26, 2011, at 11:46 AM, David Carlisle wrote: > On 26/05/2011 19:24, daniela florescu wrote: >> This solution looses the original types, which for semi-structured data are essential. > > I'm not sure I understand that comment, the solution is about adding a namespace node to a constructed element, that dpesn't lose type information. If the data you are outputting is placed into am element attribute or content then that's essentially just outputting its string value and losing type information unless the constructed element is re-validated, but adding a namespace node isn't the cause of that loss. > > David > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From davidc at nag.co.uk Thu May 26 14:22:35 2011 From: davidc at nag.co.uk (David Carlisle) Date: Thu, 26 May 2011 22:22:35 +0100 Subject: [xquery-talk] namespace declarations in an element In-Reply-To: References: <918235.46927.qm@web29507.mail.ird.yahoo.com> <4DDE9FEC.9030900@nag.co.uk> Message-ID: <4DDEC49B.70503@nag.co.uk> On 26/05/2011 20:50, daniela florescu wrote: > If the input element was already schema validated: this transformation will add indeed a namespace, > but will loose the original type annotation of the element that was given as result of schema validation. > ah yes, OK. (or not OK, depending:-) David From lists at fgeorges.org Thu May 26 16:16:04 2011 From: lists at fgeorges.org (Florent Georges) Date: Fri, 27 May 2011 00:16:04 +0100 (BST) Subject: [xquery-talk] namespace declarations in an element In-Reply-To: <4DDE9FEC.9030900@nag.co.uk> Message-ID: <436860.36552.qm@web29514.mail.ird.yahoo.com> David Carlisle wrote: Hi, > the solution is about adding a namespace node to a constructed > element, that dpesn't lose type information. If the data you > are outputting is placed into am element attribute or content > then that's essentially just outputting its string value and > losing type information unless the constructed element is > re-validated, but adding a namespace node isn't the cause of > that loss. Well, actually it is, because this solution does not add namespace declarations to an existing node, but instead returns a copy of the initial node with some extra namespace declarations. And if you want to add them to an existing node, you have to copy it in XQuery 1.0. Fortunately, in XQuery 3.0, you can add dynamically generated namespace nodes to an element directly in its sequence constructor. Regards, -- Florent Georges http://fgeorges.org/ From wcandillon at gmail.com Sun May 29 05:24:30 2011 From: wcandillon at gmail.com (William Candillon) Date: Sun, 29 May 2011 14:24:30 +0200 Subject: [xquery-talk] bringing XQuery to the Silicon Valley In-Reply-To: <533DF95B-A0B9-4285-8A9F-F6C8BEEAE1A8@mac.com> References: <533DF95B-A0B9-4285-8A9F-F6C8BEEAE1A8@mac.com> Message-ID: Hi, Videos and slides are finally available at http://xquery.pbworks.com/Silicon-Valley-Meetup. Don't forget the Zuerich meetup in July 7th ;-) http://xquery.pbworks.com/Zurich-Meetup-2 Kind regards, William On Sat, Mar 26, 2011 at 10:27 AM, daniela florescu wrote: > Dear all, > > we just had the XQuery Meetup in Prague last night (no pictures, whatever happens in Prague > after dark stays in Prague .... :-) > > Now maybe it's time to bring some XML and XQuery to the sunny Silicon Valley. > > Next XQuery Meetup will be held on April 26, in Menlo Park, Silicon Valley, California. > http://xquery.pbworks.com/w/page/38118647/Silicon-Valley-Meetup > > Please register soon ?such that we arrange for the optimal local organization. > > Looking forward to see you ! > > Best regards > Dana > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > From gfourny at inf.ethz.ch Mon May 30 00:29:32 2011 From: gfourny at inf.ethz.ch (Ghislain Fourny) Date: Mon, 30 May 2011 07:29:32 +0000 Subject: [xquery-talk] Associate external css style sheet with xquery output In-Reply-To: <615904.87659.qm@web30601.mail.mud.yahoo.com> References: <615904.87659.qm@web30601.mail.mud.yahoo.com> Message-ID: <5FA195EC-E36D-4267-BF1D-3726A66BB33C@inf.ethz.ch> Hi Hisham, This stylesheet information is called a processing instruction (PI) and it is supported by XQuery. My guess is that you can use a direct PI constructor - note however that you will need a comma between it and your root element node (if it is at the top level of the query) for the query to parse: , If the content of the PI must be dynamically constructed, you can use a computed PI constructor, like: processing-instruction { "xml-stylesheet" } { 'href="style1_1_1.css" type="text/css"'}, where you can put any expression in each of the curly braces. I hope this helps? Kind regards, Ghislain On May 30, 2011, at 7:26 AM, hisham ben otman wrote: > Hi > > How can I associate an external css style sheet with my xquery output. The xml declaration is generated automatically by the saxon processor. How can I change it to include my stylesheet information, e.g. > > > I am using saxon-B api for .Net > > If this is not possible, is there another way to include css inline formatting in the output? > Thank you > Hisham > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From dflorescu at mac.com Tue May 31 09:11:12 2011 From: dflorescu at mac.com (Daniela Florescu) Date: Tue, 31 May 2011 09:11:12 -0700 Subject: [xquery-talk] eval in XQuery implementations Message-ID: <640298A3-58B0-4777-8A79-C9022B2232D2@mac.com> Dear all, what implementations of XQuery do support eval() or something along the lines of dynamic invocations ? I would greatly appreciate help from query processors implementors with pointers to such existing solutions, and/or eval use cases from users. Thanks !! Dana From dlee at calldei.com Tue May 31 09:14:58 2011 From: dlee at calldei.com (David Lee) Date: Tue, 31 May 2011 12:14:58 -0400 Subject: [xquery-talk] eval in XQuery implementations In-Reply-To: <640298A3-58B0-4777-8A79-C9022B2232D2@mac.com> References: <640298A3-58B0-4777-8A79-C9022B2232D2@mac.com> Message-ID: <00ad01cc1fad$e35e40b0$aa1ac210$@calldei.com> I know of MarkLogic and eXist both support a form of eval as proprietary extensions. Also xmlsh provides an extension function to xpath/xslt/xquery which provides for an xmlsh eval() which can invoke xquery (among other things). This is saxon based. http://www.xmlsh.org/XPathExtension ---------------------------------------- David A. Lee dlee at calldei.com http://www.xmlsh.org -----Original Message----- From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of Daniela Florescu Sent: Tuesday, May 31, 2011 12:11 PM To: talk at x-query.com Talk Subject: [xquery-talk] eval in XQuery implementations Dear all, what implementations of XQuery do support eval() or something along the lines of dynamic invocations ? I would greatly appreciate help from query processors implementors with pointers to such existing solutions, and/or eval use cases from users. Thanks !! Dana _______________________________________________ talk at x-query.com http://x-query.com/mailman/listinfo/talk From adam.retter at googlemail.com Tue May 31 10:20:25 2011 From: adam.retter at googlemail.com (Adam Retter) Date: Tue, 31 May 2011 19:20:25 +0200 Subject: [xquery-talk] eval in XQuery implementations In-Reply-To: <640298A3-58B0-4777-8A79-C9022B2232D2@mac.com> References: <640298A3-58B0-4777-8A79-C9022B2232D2@mac.com> Message-ID: We support eval() in eXist-db and have a number of over loaded functions which allow you to manipulate the context for the eval, e.g. inherit, new or some other context... IMHO eval() is a very very evil thing and can usually be avoided through the provision of a set of 'parse' functions and some functions that enable you to construct dynamic HoF calls... It is my goal to eventually remove eval() from eXist-db once HoF in 3.0 settles down and is proven in use. On 31 May 2011 18:11, Daniela Florescu wrote: > Dear all, > > what implementations of XQuery do support eval() or something along the > lines of dynamic > invocations ? > > I would greatly appreciate help from query processors implementors with > pointers to such > existing solutions, ?and/or eval use cases from users. > > Thanks !! > Dana > > > > > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > -- Adam Retter skype: adam.retter tweet: adamretter http://www.adamretter.org.uk From mike at saxonica.com Tue May 31 13:57:23 2011 From: mike at saxonica.com (Michael Kay) Date: Tue, 31 May 2011 21:57:23 +0100 Subject: [xquery-talk] eval in XQuery implementations In-Reply-To: References: <640298A3-58B0-4777-8A79-C9022B2232D2@mac.com> Message-ID: <4DE55633.9090903@saxonica.com> On 31/05/2011 18:20, Adam Retter wrote: > We support eval() in eXist-db and have a number of over loaded > functions which allow you to manipulate the context for the eval, e.g. > inherit, new or some other context... > > IMHO eval() is a very very evil thing and can usually be avoided > through the provision of a set of 'parse' functions and some functions > that enable you to construct dynamic HoF calls... > It is my goal to eventually remove eval() from eXist-db once HoF in > 3.0 settles down and is proven in use. > It's true enough that the equivalent exslt:evaluate() has often been abused as a poor man's substitute for higher order functions. On the other hand there are also some very legitimate use cases. If you want a user interface that provides a form-based query (like the search interface in Bugzilla) by far the easiest way to do it is to construct a dynamic query. I've also seen examples where XPath expressions defining business rules were held in a configuration file for ease of editing and interpreted by the XSLT processor; it's hard to argue that this was a bad design. It would be easier to argue against eval() in XQuery if there weren't so many things in the language that are impossible to specify dynamically, like the collation for sorting or the choice of ascending/descending. Michael Kay Saxonica