I was reading Bob DuCharme's article titled "Sorting in XSLT" ( I saw the following code that causes me some confusion:
<xsl:template match="employees">
<xsl:apply-templates>
<xsl:sort select="salary"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="employee">
Last: <xsl:apply-templates select="last"/>
First: <xsl:apply-templates select="first"/>
Salary: <xsl:apply-templates select="salary"/>
Hire Date: <xsl:apply-templates select="@hireDate"/>
<xsl:text>
</xsl:text>
</xsl:template>
My question is, what is the purpose of using <xsl:apply-templates select="{node}"/> for a selected node when you haven't defined a specific template to match it? For example, the XSL element above --
<xsl:apply-templates select="last"/>
-- doesn't seem to be referencing a specific template. So, what template(s) is it applying? Wouldn't using the this --
<xsl:value-of select="last"/>
-- give the save results?
Am I just missing some subtle functionality of this element that makes it a better choice in this situation? I thought I understood when to use <xsl:apply-templates>, but now I'm not so sure.
thanx,
Mark
<xsl:template match="employees">
<xsl:apply-templates>
<xsl:sort select="salary"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="employee">
Last: <xsl:apply-templates select="last"/>
First: <xsl:apply-templates select="first"/>
Salary: <xsl:apply-templates select="salary"/>
Hire Date: <xsl:apply-templates select="@hireDate"/>
<xsl:text>
</xsl:text>
</xsl:template>
My question is, what is the purpose of using <xsl:apply-templates select="{node}"/> for a selected node when you haven't defined a specific template to match it? For example, the XSL element above --
<xsl:apply-templates select="last"/>
-- doesn't seem to be referencing a specific template. So, what template(s) is it applying? Wouldn't using the this --
<xsl:value-of select="last"/>
-- give the save results?
Am I just missing some subtle functionality of this element that makes it a better choice in this situation? I thought I understood when to use <xsl:apply-templates>, but now I'm not so sure.
thanx,
Mark