Example 1 of <xsl:if>
In this example, the names in a group of names are formatted as a comma-separated list.
XML File (names.xml)
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="ifcomma.xsl" ?>
<namelist>
<name>Albert</name>
<name>Terrance</name>
<name>Will</name>
<name>Sylvia</name>
<name>Timothy</name>
<name>Gordon</name>
<name>James</name>
<name>Robert</name>
<name>Dan</name>
<name>Sasha</name>
</namelist>
XSLT File (ifcomma.xsl)
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="namelist/name">
<xsl:apply-templates/>
<xsl:if test="position()!=last()">, </xsl:if>
</xsl:template>
</xsl:stylesheet>
Output
This is the formatted output:
Albert, Terrance, Will, Sylvia, Timothy, Gordon, James, Robert, Dan, Sasha
This is the processor output:
<?xml version="1.0" encoding="UTF-16"?>Albert, Terrance, Will, Sylvia, Timothy, Gordon, James, Robert, Dan, Sasha
See Also
Concepts
Example 2 of <xsl:if>
Example 3 of <xsl:if>
Example 4 of <xsl:if>