Hi Mark. Have you tried the function fn(index-of)? That will capture the sequence length and your current pointer location to cast against it.
If you are dealing with an external variable defined outside of our corb transform (like in your uri-get script) the location of the sequence will still probably be in the uri-get script but you will also capture this index information and deliver that with the sequence element to the transform script for each iteration. https://docs.marklogic.com/fn:index-of Sent from my iPhone On Jun 20, 2015, at 1:31 PM, Mark Shanks <[email protected]<mailto:[email protected]>> wrote: Hi, So I’m looking for a xquery function that I would have thought would be quite common, but searching has turned up a blank (partly because the search terms I can think of are too generic). Say if you have the following documents: <book> <title>Moby Dick</title> <chapter>Chapter 1 title</chapter> <chapter>Chapter 2 title</chapter> </book> <book> <title>War of the Worlds</title> <chapter>Chapter 1 title</chapter> <chapter>Chapter 2 title</chapter> <chapter>Chapter 3 title</chapter> </book> You can import all of the documents into corb using the following get-uris.xqy: xquery version "1.0-ml"; let $uris := cts:uris('', 'document') return (count($uris), $uris) I would then like to add another element to each book document that gives the number of chapters in each of the books, i.e., the resulting documents should be like this: <book> <title>Moby Dick</title> <chapter>Chapter 1 title</chapter> <chapter>Chapter 2 title</chapter> <total chapters>2</total chapters> </book> <book> <title>War of the Worlds</title> <chapter>Chapter 1 title</chapter> <chapter>Chapter 2 title</chapter> <chapter>Chapter 3 title</chapter> <total chapters>3</total chapters> </book> What xquery would one use in the transform-docs.xqy to do this? Inserting another element is easy (xdmp:node-insert-child) but actually counting up the number of a particular element for each document is what I’m not sure of. Any insight appreciated. Thanks, Mark _______________________________________________ General mailing list [email protected]<mailto:[email protected]> Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
