XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – round three / Keys and identifiers
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 3.)
To improve processing performance, or as tools for recognizing and associating nodes, XSLT provides several instructions (XSLT elements) and corresponding functions:
Recognizing declared identifiers with id()
The functionid()finds elements identified by actual identifiers of type ID, using the identifier value. It relies on the attribute’sIDdeclaration in the DTD, so it does not need the identifier’s actual name: the value itself must be unique anyway.
Generating runtime identifiers with generate-id()
If the same node must be accessed several times during processing and the output contexts should have aID-IDREFrelationship, the functiongenerate-id()can create an artificial, temporary identifier that provides precisely this functionality.
Creating and reading node indexes – xsl:key and key()
Finally, keys can create another temporary index of specific elements with predefined properties or content. This is done with the instructionxsl:key. The functionkey()provides access to this index, avoiding time-consuming searches through the document with XPath expressions, which are demanding for the XSLT processor.
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the printed edition: the work and all its parts are protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn