The generate-id() Function
Before we leave the topic of linking, we’ll go over the details
of the generate-id()
function.
This function takes a node-set as its argument, and it works as
follows:
For a given transformation, every time
generate-id()
is invoked against a given node, it returns the same ID. The ID doesn’t change while you’re doing a given transformation. If you run the transformation again tomorrow, there’s no guarantee thatgenerate-id()
will generate the same ID that it generated today. As long as the XSLT processor is running, however,generate-id()
returns the same ID for the same node every time.If you invoke
generate-id()
against two different nodes, the two generated IDs will be different.[1.0] Given a node-set,
generate-id()
returns an ID for the node in the node-set that occurs first in document order.[2.0] It is a fatal error in XSLT 2.0 to pass a sequence of more than one item to
generate-id()
.If the node-set you pass to the function is empty (you invoke
generate-id(fleeber)
, and there are no<fleeber>
elements in the current context),generate-id()
returns an empty string.If no node-set is passed in (you invoke
generate-id()
), the function generates an ID for the context node.
Note
The generate-id()
function is not required to check whether an ID it generates
duplicates an ID that’s already in the document. In other words, if
your document has an attribute of type ID
with a value of sdk3829a
, there’s a possibility that an ID
returned by generate-id()
will also ...
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.