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

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.