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]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to