2

I am looping through each element in a list and outputting a certain value:

<xsl:for-each select="properties/property">
    <xsl:value-of select="name"/>
</xsl:for-each>

This simply outputs a concatenation of the name node of property.

I want to add delimiter, such as ; between each element. How can this be done?

I listed XSLT versions 1.0, 2.0 and 3.0 as functionalities might differ between different versions.

1 Answers1

3

If you are using XSLT 2.0 or above, you can drop the xsl:for-each and just do it in a single statement

<xsl:value-of select="properties/property/name" separator=";" />

In XSLT 1.0, you would need to do more work though....

<xsl:for-each select="properties/property">
   <xsl:if test="position() > 1">;</xsl:if>
   <xsl:value-of select="name"/>
</xsl:for-each>

The difference between XSLT 2.0 and XSLT 1.0 is because in XSLT 2.0, xsl:value-of will return the value of all the nodes returned by the "select" statement, but in XSLT 1.0, it only returns the value of the first node should there be more than one.

Tim C
  • 70,053
  • 14
  • 74
  • 93