1

I want to concat all the numbers (like 1+0+1+1+1). Note the comma separated values may increase or decrease. Here is xml xsl code:

xml:

    <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="class.xsl"?>
<root><LIST>
 <ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>s1</ROLE>
<STATUS>d</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>yes</STATUS>
</LIST>
</root>

xsl:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/"><html>
    <h2>
<xsl:variable name="orgactcount">
    <xsl:for-each select="/root/LIST">
    <xsl:if test = "STATUS='yes'">
<xsl:value-of select="'1,'"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$orgactcount"/>
</h2></html>
    </xsl:template>
</xsl:stylesheet>

orgactcount variable has 1,1, value, it has to concated like 1+1....i am trying to split all the comma separated values and then manipulation ... but i could not ...does anyone have idea

ezhil
  • 977
  • 6
  • 15
  • 36

1 Answers1

2

I Edited your XSLT by adding translate function.

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <h2>

        <xsl:variable name="orgactcount">
          <xsl:for-each select="/root/LIST">
            <xsl:if test = "STATUS='yes'">
              <xsl:value-of select="'1,'"/>
            </xsl:if>
          </xsl:for-each>
        </xsl:variable>

        <xsl:variable name="formattedorgactcount" select="translate($orgactcount, ',', '+' )"/>
        <xsl:value-of select="$formattedorgactcount"/>

      </h2>
    </html>
  </xsl:template>
</xsl:stylesheet>

Following will also helpful to you.

XSLT string replace

Community
  • 1
  • 1
Madurika Welivita
  • 890
  • 1
  • 10
  • 19