Q

XSL code question

I am fairly new to this. What I want to do is pass an attribute called Formula to the format number function in

XSLT that calculates the Total Columns of a table. Examples of the attribute value :( sum(//M1000) , (sum(//M1005) div (sum(//M1003) + sum(//M1004)))*100 ). If I hard code, everything works but I want something dynamic. The problem appears to be that the value is passed as a string and thus the calc is not executed. Here is a snippet of the XSL:

 <xsl:for-each select="//Row[1]/*[@Type='Data']" >
      <xsl:variable name = "N" ><xsl:value-of select ="@Formula"/></xsl:variable>
      <xsl:choose >
       <xsl:when test ="@Format='0'"> 
           <td  class="Tablebody2" align="left" ><font size='1'><xsl:value-of select="format-number($N,'$ #,###,###')"/></font></td>
         </xsl:when> 
         <xsl:when test ="@Format='1'"> 
    <td  class="Tablebody2" align="left" ><font size='1'><xsl:value-of select="format-number($N,'0.0')"/></font></td>             
         </xsl:when> 
         <xsl:when test ="@Format='2'"> 
    <td  class="Tablebody2" align="left" ><font size='1'><xsl:value-of select="format-number($N,'0.00')"/></font></td>             
         </xsl:when> 
         <xsl:when test ="@Format='D'"> 
    <td  class="Tablebody2" align="left" ><font size='1'><xsl:value-of select="format-number($N,'$ #,###,###')"/></font></td>         
         </xsl:when> 
         <xsl:when test ="@Format='P'"> 
    <td  class="Tablebody2" align="left" ><font size='1'><xsl:value-of select="format-number($N,'##.##')"/>%</font></td>           
         </xsl:when> 
         
          <xsl:otherwise> 
          </xsl:otherwise> 
      </xsl:choose> 
 </xsl:for-each>
Thanks for your help in advance.
Details will depend on your XSLT implementation. Refer to the documentation on your XSLT implementation for parameter details of internal and extension functions.
This was first published in May 2002

Dig deeper on XML and XML schema

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close