O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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] string generate-id(node-set?)
[2.0] xs:string generate-id()
[2.0] xs:string generate-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 that generate-id() will generate the same ID the second time around. All of tomorrow’s calls (during one transformation) to generate-id() will generate the same ID, but that ID might not be the one generated today.

  • The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required