posted 14 years ago
<?xml version="1.0"?><!-- greeting.xml -->
<greeting>
Hello, World!
</greeting>
----------------------------------------
Here's an XSLT stylesheet that defines how to transform the XML document:
<?xml version="1.0"?>
<!-- greeting.xsl -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl : output method="html"/>
<xsl:template match="/">
<xsl:apply-templates select="greeting"/>
</xsl:template>
<xsl:template match="greeting">
<html>
<body>
<h1>
<xsl:value-of select="."/>
</h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
--------------------------------------------
In the above example greeting.xml is being transformed using greeting.xsl.
My confusion is in <xsl:apply-templates select="greeting"/>. When apply-templates is encountered, xsl will look for the element that is specified in the select and will apply ntemplate to that element. The template that is applied to it is the template below. Does the template below has to be named as "greeting" ? what happens if template below is named something diffrent (say, "hello" instead of greeting) ? will it sttill be applied to this element ?
<xsl:template match="hello">
<html>
<body>
<h1>
<xsl:value-of select="."/>
</h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
If the template is named like this, will it still apply to the <xsl:apply-templates select="greeting"/> ? Is it required that whatever element is specified in tha apply-templates section has to be defined below ?
Please explain this, I did a lot of reading, bit did not find convincing answer to the basic confusion.