How can we generate dynamic ID using XQuery
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
Hello,
XQuery does not provide an equivalent of generate-id() from XSLT. You can construct an ID based on the index of each of the ancestors of a given node in the list with all the siblings of that ancestor, as in the id function below:
Regards,
Sorin
XQuery does not provide an equivalent of generate-id() from XSLT. You can construct an ID based on the index of each of the ancestors of a given node in the list with all the siblings of that ancestor, as in the id function below:
Code: Select all
declare function local:pos($x) {
let $parent := $x/..
for $child at $p in $parent/*
return (if ($child is $x) then $p else ())
};
declare function local:id($x) {
string-join(for $n in ($x/ancestor::node(),$x) return string(local:pos($n)), "/")
};
<test>
{
for $node in //*
return
<nameAndId>
{ concat(name($node), " --- ", local:id($node) ) }
</nameAndId>
}
</test>
Sorin
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service