I'm trying to understand the basic idea how XSLT 1.0 works. I'm using Firefox browser for learning. Following example is not practical in any way but rather illustrates base for my question.
For source XML document:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="helloworld.xsl"?>
<messages>
<greeting>Hello World!</greeting>
<farewell>Bye World!</farewell>
</messages>
And stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" encoding="UTF-8" />
<xsl:template match="greeting">
<b><xsl:value-of select="." /></b>
</xsl:template>
<xsl:template match="farewell">
<b><xsl:value-of select="." /></b>
</xsl:template>
</xsl:stylesheet>
I get "Hello Word!" and "Bye World!" rendered bold. If i use following stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" encoding="UTF-8" />
<xsl:template match="greeting">
<b><xsl:value-of select="." /></b>
</xsl:template>
<xsl:template match="greeting">
<i><xsl:value-of select="." /></i>
</xsl:template>
</xsl:stylesheet>
Then "Bye World!" as expected is not bold, but "Hello World" also is not bold, only in italic. What happened? In first version of stylesheet it seems that both templates where executed - both matched document node. In second version seems like only second was executed or it's output has overwritten the first one. I would be very grateful for explanation on what basis XSLT processor matches nodes with templates in both stylesheets.
From what I understand: at the beginning of transformation document node is selected as context. XSLT processor iterates through nodes in context and tries to find template for each node to match and execute. Context is the synonym for "current node". What I don't understand is: does processor iterate through nodes being children of current node (so in my example only message node, as it is an only child of document node) or through all nodes being descendant of current node?