Walking Through Our Example
Let’s revisit our example and see how the XSLT processor transforms our document:
The XSLT stylesheet is parsed and converted into a tree structure.
The XML document is also parsed and converted into a tree structure. Don’t worry too much about what that tree looks like or how it works; for now, just assume that the XSLT processor knows everything that’s in the XML document and the XSLT stylesheet. After the first two steps are done, when we describe various things using XSLT and XPath, the processor knows what we’re talking about.
The XSLT processor is now at the root of the XML document. This is the original context.
There is an
xsl:templatethat matches the document root:<xsl:template match="/"> <xsl:apply-templates select="greeting"/> </xsl:template>
A single forward slash (
/) is an XSLT pattern (written in XPath) that matches “document nodes.”Now the process begins again inside the
xsl:template. Our only instruction here is to apply whateverxsl:templates might apply to anygreetingelements in the current context. The current context inside this template is defined by thematchattribute of thexsl:templateelement. This means the XSLT processor is looking for anygreetingelements at the document root.Because one
greetingelement is at the document root, the XSLT processor must deal with it. (If more than one element matches in the current context, the XSLT processor deals with each one in the order in which they appear in the document; this is known ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access