Link to home
Start Free TrialLog in
Avatar of tracim
tracim

asked on

XML If Statement

I am trying to get the sum of 3 Periods in XMl.  Does anyone know what the solution would be to get the total of the 3 Periods?

     <xsl:for-each select="Report/Billing/E">
      <xsl:if test="@Period = '4' ">
         <td><xsl:value-of select="@PhoneIns" />&#160;</td>
      </xsl:if>
      <xsl:if test="@Period = '5' ">
         <td><xsl:value-of select="@PhoneIns" />&#160;</td>
      </xsl:if>
      <xsl:if test="@Period = '6' ">
          <td><xsl:value-of select="@PhoneIns" />&#160;</td>
      </xsl:if>
     <xsl:if test="@Period = '6' and @Period = '7' and @Period = '8' "> 
          <td><xsl:value-of select="@PhoneIns" />&#160;</td>
      </xsl:if>
    </xsl:for-each>
Avatar of Justin Pilditch
Justin Pilditch
Flag of United Kingdom of Great Britain and Northern Ireland image

have you tried
<xsl:value-of select="sum(@PhoneIns)" />

Open in new window

Hi,

Murfurs solution will not work inside the for each.
an element can only have one attribute with the same name, so sum(@PhoneIns) will never sum more than one attribute

If you need the full total regardless of the @Period,
you will need to replace the for-each with
<td><xsl:value-of select="Report/Billing/E/@PhoneIns" />&#160;</td>

If you need the sum of the three periods mentioned above, thus being more selective
<td><xsl:value-of select="Report/Billing/E["@Period = '6' or "@Period = '7' or "@Period = '8' ]/@PhoneIns" />&#160;</td>

it would have helped us if you showed a part of the XML source
Avatar of tracim
tracim

ASKER

Hi Gertone,

I am getting the syntax error when I try your option - it something missing.  Yes, I have attached the XML Source procedure.
LCS-Perfomance.txt
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tracim

ASKER

Thank you for quick, excellent solution!