Specific template for the first element.
Posted
by Kalinin
on Stack Overflow
See other posts from Stack Overflow
or by Kalinin
Published on 2010-05-19T07:23:18Z
Indexed on
2010/05/19
7:30 UTC
Read the original article
Hit count: 201
I have a template:
<xsl:template match="paragraph">
...
</xsl:template>
I call it:
<xsl:apply-templates select="paragraph"/>
For the first element I need to do:
<xsl:template match="paragraph[1]">
...
<xsl:apply-templates select="."/><!-- I understand that this does not work -->
...
</xsl:template>
How to call <xsl:apply-templates select="paragraph"/>
(for the first element paragraph
) from the template <xsl:template match="paragraph[1]">
?
So far that I have something like a loop.
I solve this problem so (but I do not like it):
<xsl:for-each select="paragraph">
<xsl:choose>
<xsl:when test="position() = 1">
...
<xsl:apply-templates select="."/>
...
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
© Stack Overflow or respective owner