XSLT Concatenating the values with comma (,)

2019-04-20 05:35发布

i need to loop through all the nodes in the xml document and append the values with comma ( , ) finally after the last element i should not have commma (,)

can any body help me.

thanking you, Ramana kumar.

标签: xslt
3条回答
beautiful°
2楼-- · 2019-04-20 06:03

In XSLT 2.0 (or greater) you can use xsl:value-of with a separator:

<xsl:value-of select="/element/whatever" separator=","/>

If the separator attribute is present, then the effective value of this attribute is used to separate adjacent items in the result sequence

查看更多
三岁会撩人
3楼-- · 2019-04-20 06:06

In XSLT 2.0 (or greater) you can use the string-join function.

<xsl:value-of  select="string-join(/element/whatever, ',')"/>
查看更多
Evening l夕情丶
4楼-- · 2019-04-20 06:20

You can do something like this:

<xsl:for-each select="element">
    <xsl:value-of select="whatever" />
    <xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>

The position() function returns the index of the current element in the for-each context, and last() returns the index of the last element.

The Conditional Processing with xsl:if section of the XSLT documentation provides more information about this example.

查看更多
登录 后发表回答