Using XSLT Keys to Increase Performance
Using XSLT to process a large XML document with many data points can involve many performance issues, especially when specific nodes within the document are to be processed repeatedly within a single transformation.
For example, a document representing a publishing company's book catalog might contain data about hundreds or thousands of books. In a given transformation, many of these book titles might be referenced a dozen times, not only in the descriptions of the books, but also in an index of all titles, a list of featured titles, and so on. Searching or cross-referencing the document many times for a given title or a title that matches a specific condition can result in unacceptable performance.
XSLT solves this problem by supporting the use of keys to uniquely identify a node or class of nodes. Each key is used by the XSLT processor to build an index, which the processor can reference when a particular value is needed. This index enables the processor to retrieve the keyed node without searching for it. Using keys can also greatly simplify the coding of XPath expressions.
- Deciding whether to Use IDs or Keys
- Using the <xsl:key> Element
- Using the key() Function
- Using XSLT Keys to Group Data
- Sample XML Data File for XSLT Keys (booksvariant.xml)
- Sample XSLT File for XSLT Keys (lib_cat.xsl)