Share via


Tree Representation and XPath

 

The XSLT processor does not work on raw XML data directly out of an XML document file. Instead, the raw XML data is first parsed into an XML DOM object that represents the XML elements as a tree of nodes. This tree representation allows you to build expressions in the XPath language syntax to query XML document elements. A template rule is invoked when the specified element, as expressed in an XPath pattern, is matched.

In the Hello, World! example, the template rule (<xsl:template match="/hello-world">) uses an XPath expression (/hello-world). This expression specifies that the template rule is applied to the top-level <hello-world> element in the source XML document. If you use match="hello-world" and the source document has multiple occurrences of the <hello-world> element, the template rule is applied to all of them.

If a pattern specified in an XSLT style sheet does not match any element in the source document, the associated template rule is ignored. This is possible if you make mistakes when you build the XPath expression. Therefore, proficiency in the XPath language is crucial for writing an XSLT style sheet effectively. To learn more about XPath, see the XPath Reference in this documentation.