From john.snelson at marklogic.com Tue Sep 4 02:37:35 2012 From: john.snelson at marklogic.com (John Snelson) Date: Tue, 04 Sep 2012 10:37:35 +0100 Subject: [xquery-talk] Looping in Xquery In-Reply-To: References: Message-ID: <5045CBDF.7070300@marklogic.com> You're close - the missing part is that you want to use the sum() function, ie: { sum( for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//short-definition return string-length($shrtdesc/p/text) ) } John On 04/09/12 10:15, Mailing Lists Mail wrote: > Dear Xquery Adults, > > I am very new here.. I have some issues with getting my requirements > working.. I guess, this should be very simple, but dont seem to get my > heads around... THe following is what I want.. > > I have loads of XMLs in the Data Store ( markLogic) > > I have to run a query to do the return the string lengths of certain > elements from 100 XMLs./ > > So my pseudo code will be : > > > For all XMLs in the Data store > { > > > > {length of desc at //xx/y/desc } > > > > > { > string-length ( //xx//yy/short-desc) > } > > > > > > > > > My attempts: > > > declare namespace dict = "http://www.lexis-nexis.com/glp/dict"; > for $ltnfiles in doc() > let $NAME:= document-uri($ltnfiles) > return ( > > > {$NAME} > > > {string-length(string($ltnfiles//subtopic[@id = > 'DEF']/short-definition/p/text))} > > > ) > THe above works fine, if there is only one short-definition.. FOr more > than one shortdefiitions, it comes up with the error message obviously > because the string does not allow 2 arguments, while the stuff passed > into the function is a sequence... > > How do I do another loop inside the first one, for each short-defiitin > ... SOmething like : > > for $ltnfiles in doc() > let $NAME:= document-uri($ltnfiles) > return ( > > > {$NAME} > > { > for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//short-definition > > { > string-length( $shrtdesc/p/text) > } > > } > > ) > DOEstNT WORK .. :( This wont give me what I want as What I want is a > sum (string-lengths of all the short-def) .. But atleast i thought i > would get something like > > 100 > 344 > > ( I would have liked 444 ) > > ANy help would be highly appreciated .. > > Thanks > > Dak. > > -- John Snelson, Lead Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com From stadler at weber-gesamtausgabe.de Tue Sep 4 02:44:18 2012 From: stadler at weber-gesamtausgabe.de (Peter Stadler) Date: Tue, 4 Sep 2012 11:44:18 +0200 Subject: [xquery-talk] Looping in Xquery In-Reply-To: <5045CBDF.7070300@marklogic.com> References: <5045CBDF.7070300@marklogic.com> Message-ID: <582B9354-AA34-4C5E-A49C-0141DD9CA5CA@weber-gesamtausgabe.de> An alternative would be to use string-join(). First join all the strings and then calculate the length: {string-length(string-join($ltnfiles//subtopic[@id = 'DEF']/short-definition/p/text), '')} All the best Peter PS: A great resource for xquery functions is http://www.xqueryfunctions.com/ You will find lots of stuff there ... Am 04.09.2012 um 11:37 schrieb John Snelson: > You're close - the missing part is that you want to use the sum() function, ie: > > { > sum( > for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//short-definition > return string-length($shrtdesc/p/text) > ) > } > > John > > On 04/09/12 10:15, Mailing Lists Mail wrote: >> Dear Xquery Adults, >> >> I am very new here.. I have some issues with getting my requirements >> working.. I guess, this should be very simple, but dont seem to get my >> heads around... THe following is what I want.. >> >> I have loads of XMLs in the Data Store ( markLogic) >> >> I have to run a query to do the return the string lengths of certain >> elements from 100 XMLs./ >> >> So my pseudo code will be : >> >> >> For all XMLs in the Data store >> { >> >> >> >> {length of desc at //xx/y/desc } >> >> >> >> >> { >> string-length ( //xx//yy/short-desc) >> } >> >> >> >> >> >> >> >> >> My attempts: >> >> >> declare namespace dict = "http://www.lexis-nexis.com/glp/dict"; >> for $ltnfiles in doc() >> let $NAME:= document-uri($ltnfiles) >> return ( >> >> >> {$NAME} >> >> >> {string-length(string($ltnfiles//subtopic[@id = >> 'DEF']/short-definition/p/text))} >> >> >> ) >> THe above works fine, if there is only one short-definition.. FOr more >> than one shortdefiitions, it comes up with the error message obviously >> because the string does not allow 2 arguments, while the stuff passed >> into the function is a sequence... >> >> How do I do another loop inside the first one, for each short-defiitin >> ... SOmething like : >> >> for $ltnfiles in doc() >> let $NAME:= document-uri($ltnfiles) >> return ( >> >> >> {$NAME} >> >> { >> for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//short-definition >> >> { >> string-length( $shrtdesc/p/text) >> } >> >> } >> >> ) >> DOEstNT WORK .. :( This wont give me what I want as What I want is a >> sum (string-lengths of all the short-def) .. But atleast i thought i >> would get something like >> >> 100 >> 344 >> >> ( I would have liked 444 ) >> >> ANy help would be highly appreciated .. >> >> Thanks >> >> Dak. >> >> > > > -- > John Snelson, Lead Engineer http://twitter.com/jpcs > MarkLogic Corporation http://www.marklogic.com > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk -- Peter Stadler Carl-Maria-von-Weber-Gesamtausgabe Arbeitsstelle Detmold Gartenstr. 20 D-32756 Detmold Tel. +49 5231 975-665 Fax: +49 5231 975-668 stadler at weber-gesamtausgabe.de www.weber-gesamtausgabe.de From john.snelson at marklogic.com Tue Sep 4 03:04:20 2012 From: john.snelson at marklogic.com (John Snelson) Date: Tue, 04 Sep 2012 11:04:20 +0100 Subject: [xquery-talk] Looping in Xquery- Braces? In-Reply-To: References: Message-ID: <5045D224.1060102@marklogic.com> I think this error depends on the context of the two expressions you've given below - which in and of themselves look fine. In an expression context, you need a comma between two direct element constructors: , When directly inside another direct element constructor, no comma is necessary (because the syntax is emulating XML itself): When you use curly braces inside a direct element constructor, you return to an expression context, so commas are necessary again: { , } You can mix the two styles: { , } John On 04/09/12 10:58, Mailing Lists Mail wrote: > Here is what Stumps me about the braces.. Since JOhn's solution worked, > I wanted to do the same for other element lengths... > so I did > > { > sum( > > for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//short-definition > return string-length($shrtdesc/p/__text) > ) > } > > > { > sum( > > for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//long-definition > return string-length($shrtdesc/p/__text) > ) > } > > > Ended up getting the following error... > > > At line 24 column 3: > > 22. > 23. > 24. { > 25. sum( > 26. > > > ANy Ideas please? > > > > > > > On Tue, Sep 4, 2012 at 10:37 AM, John Snelson > > wrote: > > You're close - the missing part is that you want to use the sum() > function, ie: > > { > sum( > > for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//short-definition > return string-length($shrtdesc/p/__text) > ) > } > > John > > > On 04/09/12 10:15, Mailing Lists Mail wrote: > > Dear Xquery Adults, > > I am very new here.. I have some issues with getting my requirements > working.. I guess, this should be very simple, but dont seem to > get my > heads around... THe following is what I want.. > > I have loads of XMLs in the Data Store ( markLogic) > > I have to run a query to do the return the string lengths of certain > elements from 100 XMLs./ > > So my pseudo code will be : > > > For all XMLs in the Data store > { > > > > {length of desc at //xx/y/desc } > > > > > { > string-length ( //xx//yy/short-desc) > } > > > > > > > > > My attempts: > > > declare namespace dict = > "http://www.lexis-nexis.com/__glp/dict > "; > for $ltnfiles in doc() > let $NAME:= document-uri($ltnfiles) > return ( > > > {$NAME} > > > {string-length(string($__ltnfiles//subtopic[@id = > 'DEF']/short-definition/p/__text))} > > > ) > THe above works fine, if there is only one short-definition.. > FOr more > than one shortdefiitions, it comes up with the error message > obviously > because the string does not allow 2 arguments, while the stuff > passed > into the function is a sequence... > > How do I do another loop inside the first one, for each > short-defiitin > ... SOmething like : > > for $ltnfiles in doc() > let $NAME:= document-uri($ltnfiles) > return ( > > > {$NAME} > > { > for $shrtdesc in $ltnfiles//subtopic[@id = > 'DEF']//short-definition > > { > string-length( $shrtdesc/p/text) > } > > } > > ) > DOEstNT WORK .. :( This wont give me what I want as What I > want is a > sum (string-lengths of all the short-def) .. But atleast i thought i > would get something like > > 100 > 344 > > ( I would have liked 444 ) > > ANy help would be highly appreciated .. > > Thanks > > Dak. > > > > > -- > John Snelson, Lead Engineer http://twitter.com/jpcs > MarkLogic Corporation http://www.marklogic.com > _________________________________________________ > talk at x-query.com > http://x-query.com/mailman/__listinfo/talk > > > -- John Snelson, Lead Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com From james.fuller.2007 at gmail.com Tue Sep 4 04:42:14 2012 From: james.fuller.2007 at gmail.com (James Fuller) Date: Tue, 4 Sep 2012 13:42:14 +0200 Subject: [xquery-talk] Looping in Xquery In-Reply-To: References: <5045CBDF.7070300@marklogic.com> <582B9354-AA34-4C5E-A49C-0141DD9CA5CA@weber-gesamtausgabe.de> Message-ID: if you mean curly braces, they are just a way of when to engage xquery processing here is a simple example, if your entire query was 1 + 1 then when you process this it would emit exactly the same thing e.g. 1 + 1 but if you did {1 + 1} then the stuff in the braces would get evaluated by xquery processor e.g. the output would look like 2 keep on asking questions ... Jim Fuller On Tue, Sep 4, 2012 at 11:51 AM, Mailing Lists Mail wrote: > Thanks a lot folks... > I still dont clearly understand the fundamentals of braces in this > language.. > May be i should start biting the books / WHich I will.. I am hoping to be > contributing to this list in like 4-5 months. > Thanks again.. Your solution works.. > Vasu > > > On Tue, Sep 4, 2012 at 10:44 AM, Peter Stadler > wrote: >> >> An alternative would be to use string-join(). First join all the strings >> and then calculate the length: >> {string-length(string-join($ltnfiles//subtopic[@id = >> 'DEF']/short-definition/p/text), '')} >> >> All the best >> Peter >> >> PS: A great resource for xquery functions is >> http://www.xqueryfunctions.com/ >> You will find lots of stuff there ... >> >> Am 04.09.2012 um 11:37 schrieb John Snelson: >> >> > You're close - the missing part is that you want to use the sum() >> > function, ie: >> > >> > { >> > sum( >> > for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//short-definition >> > return string-length($shrtdesc/p/text) >> > ) >> > } >> > >> > John >> > >> > On 04/09/12 10:15, Mailing Lists Mail wrote: >> >> Dear Xquery Adults, >> >> >> >> I am very new here.. I have some issues with getting my requirements >> >> working.. I guess, this should be very simple, but dont seem to get my >> >> heads around... THe following is what I want.. >> >> >> >> I have loads of XMLs in the Data Store ( markLogic) >> >> >> >> I have to run a query to do the return the string lengths of certain >> >> elements from 100 XMLs./ >> >> >> >> So my pseudo code will be : >> >> >> >> >> >> For all XMLs in the Data store >> >> { >> >> >> >> >> >> >> >> {length of desc at //xx/y/desc } >> >> >> >> >> >> >> >> >> >> { >> >> string-length ( //xx//yy/short-desc) >> >> } >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> My attempts: >> >> >> >> >> >> declare namespace dict = "http://www.lexis-nexis.com/glp/dict"; >> >> for $ltnfiles in doc() >> >> let $NAME:= document-uri($ltnfiles) >> >> return ( >> >> >> >> >> >> {$NAME} >> >> >> >> >> >> {string-length(string($ltnfiles//subtopic[@id = >> >> 'DEF']/short-definition/p/text))} >> >> >> >> >> >> ) >> >> THe above works fine, if there is only one short-definition.. FOr more >> >> than one shortdefiitions, it comes up with the error message obviously >> >> because the string does not allow 2 arguments, while the stuff passed >> >> into the function is a sequence... >> >> >> >> How do I do another loop inside the first one, for each short-defiitin >> >> ... SOmething like : >> >> >> >> for $ltnfiles in doc() >> >> let $NAME:= document-uri($ltnfiles) >> >> return ( >> >> >> >> >> >> {$NAME} >> >> >> >> { >> >> for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//short-definition >> >> >> >> { >> >> string-length( $shrtdesc/p/text) >> >> } >> >> >> >> } >> >> >> >> ) >> >> DOEstNT WORK .. :( This wont give me what I want as What I want is a >> >> sum (string-lengths of all the short-def) .. But atleast i thought i >> >> would get something like >> >> >> >> 100 >> >> 344 >> >> >> >> ( I would have liked 444 ) >> >> >> >> ANy help would be highly appreciated .. >> >> >> >> Thanks >> >> >> >> Dak. >> >> >> >> >> > >> > >> > -- >> > John Snelson, Lead Engineer http://twitter.com/jpcs >> > MarkLogic Corporation http://www.marklogic.com >> > _______________________________________________ >> > talk at x-query.com >> > http://x-query.com/mailman/listinfo/talk >> >> -- >> Peter Stadler >> Carl-Maria-von-Weber-Gesamtausgabe >> Arbeitsstelle Detmold >> Gartenstr. 20 >> D-32756 Detmold >> Tel. +49 5231 975-665 >> Fax: +49 5231 975-668 >> stadler at weber-gesamtausgabe.de >> www.weber-gesamtausgabe.de >> >> >> >> >> > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From mike at saxonica.com Fri Sep 7 08:22:52 2012 From: mike at saxonica.com (Michael Kay) Date: Fri, 07 Sep 2012 16:22:52 +0100 Subject: [xquery-talk] Replacing an attribute In-Reply-To: References: <5049FF0F.30504@ifactory.com> <220256FDE771B74FB662165BC562CF59411AEC38@BL2PRD0811MB410.namprd08.prod.outlook.com> Message-ID: <504A114C.8080704@saxonica.com> > Yes. I saw that If I write an XSLT stylesheet, then I can call that > from marklogic and it all works good... > I am not too sure, if XSLT is a good approach or if Xquery is a better > way of doing things? > Generally, XQuery is better than XSLT for extracting specific information out of an XML document, and XSLT is better at making small changes to a document while leaving most of the content unchanged. Or to put it another way, XQuery is better at query and XSLT is better at transformation. (XQuery Update is an alternative, though, if available). Michael Kay Saxonica From dflorescu at mac.com Wed Sep 19 10:12:56 2012 From: dflorescu at mac.com (daniela florescu) Date: Wed, 19 Sep 2012 10:12:56 -0700 Subject: [xquery-talk] [xml-dev] XQuery 3.0 implementations vs the XQuery 3.0 Test Suite In-Reply-To: References: Message-ID: <2F2E3E18-9818-4EE4-8E9D-FBBC67DD9341@mac.com> Jim, I expect Zorba to report results by the end of the year, hopefully 100%. We implement all the features, including the optional ones. Best Dana On Sep 17, 2012, at 6:55 PM, Jim Melton wrote: > Gentle friends, > > The XML Query WG, jointly with the XSLT Working Group, are nearly ready to several several of the "3.0" suite of specifications from Last Call Working Draft to Candidate Recommendation. The exceptions are Serialization 3.0, which will be submitted for a second Last Call comment period, and XSLT 3.0, which has not yet entered the Last Call phase. (The documents being considered for advancement are XQuery 3.0, XQueryX 3.0, XPath 3.0, XDM 3.0, and F&O 3.0.) > > We already have in place a very substantial test suite for XQuery 3.0, although we do not claim that it is as complete as we wish it to be. We are currently in the process of reviewing the test suite to determine what additional tests are needed to ensure that we can determine our specs to be implementable as required by W3C policies. > > The purpose of Candidate Recommendation is, as implied above, to determine whether the specs are implementable, particularly that each feature can be implemented by two or more implementations compatibly. Therefore, as documents are transitioned to Candidate Recommendation, a Call for Implementations is issued. Implementations respond to that call by submitting their results from running the test suite and by reporting bugs they've discovered as a result. > > When we transition to Candidate Recommendation, we are required to indicate a date through which we will accept test suite results and other comments before we consider a further transition to Proposed Recommendation. At this point, we honestly cannot predict whether implementors will require two weeks, two months, or two quarters before they're able to submit results. > > If you are responsible for an XQuery 3.0 implementation, please respond to this message with your best estimate of how long from, say, mid-October 2012 it will be until you are able to submit test suite results. > > Many thanks! > Jim > > ======================================================================== > Jim Melton --- Editor of ISO/IEC 9075-* (SQL) Phone: +1.801.942.0144 > Chair, ISO/IEC JTC1/SC32 and W3C XML Query WG Fax : +1.801.942.3345 > Oracle Corporation Oracle Email: jim dot melton at oracle dot com > 1930 Viscounti Drive Alternate email: jim dot melton at acm dot org > Sandy, UT 84093-1063 USA Personal email: SheltieJim at xmission dot com > ======================================================================== > = Facts are facts. But any opinions expressed are the opinions = > = only of myself and may or may not reflect the opinions of anybody = > = else with whom I may or may not have discussed the issues at hand. = > ======================================================================== > > _______________________________________________________________________ > > XML-DEV is a publicly archived, unmoderated list hosted by OASIS > to support XML implementation and development. To minimize > spam in the archives, you must subscribe before posting. > > [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/ > Or unsubscribe: xml-dev-unsubscribe at lists.xml.org > subscribe: xml-dev-subscribe at lists.xml.org > List archive: http://lists.xml.org/archives/xml-dev/ > List Guidelines: http://www.oasis-open.org/maillists/guidelines.php > From andrew.j.welch at gmail.com Mon Sep 24 01:59:21 2012 From: andrew.j.welch at gmail.com (Andrew Welch) Date: Mon, 24 Sep 2012 09:59:21 +0100 Subject: [xquery-talk] Looking for help restricting results per input? In-Reply-To: References: Message-ID: On 24 September 2012 07:47, Jeremy Botto wrote: > let $keywords := ("keyworda", "keywordb", "keywordc") > for $keyword in $keywords, > $v in doc('test')//document/item > where $v/quote contains text {$keyword} > return ( > {$v/comment} > {$v/buyer}) > > There are three things I am trying to add to this query: > > 1) I'd like to get only two results per $keyword in $keywords, but I am > currently getting 20-30 results per keyword. You've got a "cartesian cross product" in your for expression.... is that really what you want? > 2) I'd like to search for case-insensitive keywords. Covert both items to lower-case() before comparing, or use your xquery vendors custom extensions. > 3) Because I am trying to receive only 2 results, I want to prioritize > results whose 'quote' element also contain round braces "(" and ")". Use order by - if if the quote contains round brackets return 1 else return 0, then sort by number descending. -- Andrew Welch http://andrewjwelch.com