..." />
The Planets
</TITLE>
<PLANETS>
The first three planets are: <xsl:apply-templates select="PLANET"/>
</PLANETS>
</DOCUMENT>
</xsl:template>
<xsl:template match="PLANET">
<xsl:if test="NAME[not(text())]">
<xsl:message terminate="yes">
Each planet must have a name!
</xsl:message>
</xsl:if>
<xsl:value-of select="NAME"/>
<xsl:choose>
<xsl:when test="position()!=last()">, </xsl:when>
<xsl:when test="position()=last()-1">and </xsl:when>
<xsl:otherwise>.</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Вот как это работает; этот код дает тот же результат, что и код, проверяющий позицию элементов <PLANET> при помощи <xsl:if>:
<?xml version="1.0" encoding="UTF-8"?>
<DOCUMENT>
<TITLE>
The Planets
</TITLE>
<PLANETS>
The first three planets are: Mercury, Venus, and Earth.
</PLANETS>