Ask the Expert

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.

    Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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: