Output a comma if it's not the last one in the node : last « XSLT stylesheet « XML






Output a comma if it's not the last one in the node



File: Data.xml


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="xml" omit-xml-declaration="yes" indent="no" />

  <xsl:template match="figure/title">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="para" />

</xsl:stylesheet>

File: Transform.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="xml" omit-xml-declaration="yes" />

  <xsl:template match="title">
    <xsl:text>title ancestors:</xsl:text>
    <xsl:for-each select="ancestor::*">
      <xsl:value-of select="name()" />
      <xsl:if test="position() != last()">
        <xsl:text>,</xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="para" />

  
</xsl:stylesheet>

 








Related examples in the same category

1.last() as index
2.use last() function to get the context size