Using XSLT Keys to Increase Performance

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XSLT Developer's Guide

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.