Tuesday, May 23, 2017

Conver the xslt element to comma seperated value output

Transformation:
<xsl:template match="/">

    <tns:Input>

      <tns:STATUS>

        <xsl:variable name="set" select="/ns0:Root-Element/ns0:STATUS"/>

        <xsl:variable name="count" select="count($set)"/>

        <xsl:for-each select="/ns0:Root-Element/ns0:STATUS">

          <xsl:variable name="i" select="position()-1"/>

          <xsl:value-of select="concat(/ns0:Root-Element/ns0:STATUS[$i+1]/text(),',')"/>

        </xsl:for-each>

      </tns:STATUS>

    </tns:Input>


Input:

<Root-Element>
<STATUS>X</STATUS>
<STATUS>Y</STATUS>
<STATUS>Z</STATUS>
</Root-Element>

Output:

<Input>
<STATUS>X,Y,Z</STATUS>
</Input>