How to generate an Identifer in XQuery

Hi ! :slight_smile:

I’m looking for a solution to generate an identifier in a XQuery query. But apparently I think that one cannot use functions XSLT in XQuery ( generate-id() ). Then another solution would have to generate a ID with XQuery, for example by using the Relations between the nodes: Parent, Children, Siblings, Ancestors, Descendants; kind of : “count (preceding:: noeudx) +1” , but I don’t know how to write it properly.

Thanks for help !!

Hi nice,

as far as I know there is no such thing as generate-id in XQuery nor in Tamino.
A node is uniquely identified by the ino:id of the document it is contained in and
a list of integers identifying the number of the child to select.

The following pair of user-defined functions should do it:

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((string(tf:getInoId($x)),
for $ant in ($x/ancestor::node(),$x)
return string(local:pos($ant))),
“/”) };

I have only tried this with element nodes.

Regards,
Juliane.