I'd been wondering whether there was a way in a FLWOR statement to get the index position. I'd tried a few things that I'd hoped might work but I couldn't find a decent way to get back to the context whenever I got to the return portion of the statement.
It became apparent that in some (not all) contexts, I could rely on this example as a quick (and cheap) workaround:
Yields this:
Update - John Snelson advised me on the correct way to deal with position in XQuery - using for and at when starting the FLWOR statement:
Also worth considering:
And another useful positional trick, suggested by Jason Booth:
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2010
(43)
-
▼
June
(8)
- XQDT: Notes for installing the current Milestone o...
- MarkLogic: XQuery: performance with Maps
- Java: Using Jersey with JAXB to output XML or JSON.
- MarkLogic: XQuery: hacking the position() - a basi...
- MarkLogic: XQuery: and / and-not query examples
- MarkLogic: XQuery: UNIX Timestamp to xs:dateTime C...
- MarkLogic: XCC/J: Passing a node() into a Query as...
- MarkLogic: XQuery: Typeswitching based on input "t...
-
▼
June
(8)
2 comments:
Try this:
for $record at $position in $recordset/record
return element item {attribute index {$position}, $record//name/text()}
That's excelllent, John - thanks so much for posting!
Post a Comment