Name
generate-id()
Generates a unique ID (an XML name) for a given
node. If no node-set is given, generate-id()
generates an ID for
the context node.
Syntax
[1.0] stringgenerate-id(
node-set?
)
[2.0] xs:stringgenerate-id(
)
[2.0] xs:stringgenerate-id(
node()?
)
Inputs
[1.0] An optional node-set. If no
node-set is given, this function generates an ID for the context
node. If the node-set is empty, generate-id()
returns an empty
string.
[2.0] An optional node. If no node is given, this function generates an ID for the context node. If the argument is the empty sequence, the result is a zero-length string.
In XSLT 1.0, passing a node-set to the generate-id()
function generated a
unique ID for the first item in the node-set; all nodes after the
first were ignored. In XSLT 2.0, it is an error to pass
a sequence with more than one node to
generate-id()
.
Output
A unique ID, or an empty string if an empty node-set is
given. Several things about the generate-id()
function are important
to know:
For a given transformation, every time you invoke
generate-id()
against a given node, the XSLT processor must return the same ID. The ID can’t change while you’re doing a transformation. If you ask the XSLT processor to transform your document with this stylesheet tomorrow, there’s no guarantee thatgenerate-
id()
will generate the same ID the second time around. All of tomorrow’s calls (during one transformation) togenerate-id()
will generate the same ID, but that ID might not be the one generated today.The ...
Get XSLT, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.