XSLT Concatenating the values with comma (,)

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

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.

回答1:

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.



回答2:

In XSLT 2.0 you can use the string-join function.

<xsl:value-of  select="string-join(/element/whatever, ',')"/>


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!