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
-
►
2011
(35)
-
►
June
(6)
- MarkLogic/XCC: Copying a Module with User Content ...
- MarkLogic: clearing a forest in a database program...
- MarkLogic: Enabling debug options when using the S...
- Linux: SCP syntax and structure note
- MarkLogic/XCC: Installing Modules Programatically
- Eclipse: Installing XQDT (and DLTK) on Eclipse Ind...
-
►
June
(6)
-
▼
2010
(43)
-
►
September
(7)
- MarkLogic: Creating Multiple Range Element Indexes...
- MarkLogic: Listing all Collections in a Database
- MarkLogic: Basic Database Cloning Script
- MarkLogic: Estimating the number of documents cont...
- MarkLogic: Search: Compound OR Queries
- MarkLogic: XQuery: Check for the presence of an el...
- MarkLogic: XQuery: Type Validation using xsi:type
-
▼
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...
-
►
September
(7)
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