1

I have an Xml like below:

<data>
  <record id="1"/>
  <record id="2"/>
  <record id="3"/>
  <record id="4"/>
  <record id="5"/>
  <record id="6"/>
</data>

I want to print this xml as

**TRIM("1"-"2"-"3"-"4"-"5"-"6")**

I am using simple xsl like below

<xsl:for-each select="descendant-or-self::*/record">
    <xsl:text>TRIM("</xsl:text>
    <xsl:value-of select="@id"/>
    <xsl:text>"-"</xsl:text>
    <xsl:text>)</xsl:text>
</xsl:for-each>

the first item only requires <xsl:text>TRIM("</xsl:text> and last item requires <xsl:text>)</xsl:text>. How to achieve this in order to get the result TRIM("1"-"2"-"3"-"4"-"5"-"6")

  • 1
    Possible duplicate of [XSLT concat string, remove last comma](http://stackoverflow.com/questions/798269/xslt-concat-string-remove-last-comma) –  Jan 06 '16 at 03:51

1 Answers1

0

I got an answer. it is

<xsl:for-each select="descendant-or-self::*/record">
    <xsl:if test="position() = 1">
        <xsl:text>TRIM("</xsl:text>
    </xsl:if>
    <xsl:value-of select="@id"/>
    <xsl:text>"-"</xsl:text>
    <xsl:if test="position() = last()">
        <xsl:text>)</xsl:text>
    </xsl:if>
</xsl:for-each>