Neo
Neo

Reputation: 16219

how to concatenate foreach inside xslt?

I have following structure in my xslt -

   <Identification>
                    <xsl:for-each select="DataPartner">                 

 <xsl:variable name="var:v30" select="userCSharp:LogicalEq(string(../../Demo/@name) , &quot;Description&quot;)" />
                        <xsl:if test="string($var:v30)='true'">
                          <Identifier>
                              <xsl:value-of select="Demo/demo/text()" />
                              <xsl:text>,</xsl:text>
                          </Identifier>
                        </xsl:if>
                      </xsl:for-each>

                    </Identification>

input xml -

<DataPartner>
                      <Demo name="Description">
            <demo>demo11</demo>
          </Demo>
           <Demo name="Description">
            <demo>demo12</demo>
          </Demo>
                            <DataPartner>

expected output-

demo11 , demo12

Upvotes: 0

Views: 1735

Answers (1)

Tim C
Tim C

Reputation: 70618

If the intention is to to concatenate all the demo element text, where the Demo name is "Description", then this is how you might do it....

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html" indent="yes" />

  <xsl:template match="DataPartner">
    <Identifier>
      <xsl:for-each select="Demo[@name='Description']">
        <xsl:if test="position() &gt; 1">, </xsl:if>
        <xsl:value-of select="demo" />
      </xsl:for-each>
    </Identifier>
  </xsl:template>
</xsl:stylesheet>

Upvotes: 2

Related Questions