XSLT and XPath between them provide several ways to locate items, and to index and link them using identifiers and keys that express relationships between elements.
id() function in XPath 2.0 enables you to find element nodes having attributes of type
xs:ID, and it can be useful when the source schema or DTD is accessible. However, there are some limitations that result from the rules set by the XML specification for attribute values.
<xsl:key> declaration and the matching XSLT
key() function overcome these limitations, enabling you to locate source-tree nodes by matching either elements or attributes of any type.
When there are no obvious identifier values to use in the source data, you can use the XSLT
generate-id() function to associate nodes with one another. In any single execution of a stylesheet, this function will always cause an identical unique value to be generated for a given node. This property can be used to associate related items and generate linking information.
In this chapter you will do the following:
Review some characteristics of the
IDREF datatypes used in XML documents to uniquely identify items and refer to them.
Learn how to use the XPath 2.0
id() function on ID attributes to locate source items, and appreciate its limitations.
<xsl:key> and the
key() function to work with more complex cross-reference structures, and locate non-unique items for processing.
generate-id() function to index the lines of ...