Re: [xsl] How to do this without updating a variable?

Subject: Re: [xsl] How to do this without updating a variable?
From: JBryant@xxxxxxxxx
Date: Wed, 7 Sep 2005 17:20:42 -0500
Here's one way:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:template match="/">
    <html>
      <body>
        <table border="1">
          <tr>
            <th>Node</th><th>Start</th><th>End</th>
          </tr>
          <xsl:apply-templates/>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="top">
    <xsl:for-each select="descendant::reg">
      <xsl:choose>
        <xsl:when test="position() = 1">
          <tr>
            <td><xsl:value-of select="."/></td><td>1</td><td><xsl:value-of 
select="@count"/></td>
          </tr>
        </xsl:when>
        <xsl:otherwise>
          <tr>
            <td><xsl:value-of select="."/></td><td><xsl:value-of 
select="sum(preceding::reg/@count) + 1"/></td><td><xsl:value-of 
select="sum(preceding::reg/@count) + @count"/></td>
          </tr>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

I'm sure there are other ways (in fact, I have already thought of 
another).

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)






"Agnisys Technology \(P\) Ltd." <agnisys@xxxxxxxxx> 
09/07/2005 04:28 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
cc

Subject
[xsl] How to do this without updating a variable?






Hi, 
  I have seen past postings about the fact that variables cannot be 
updated. But I'm not sure how
to solve the following problem without variable update!

Input:

<top>
  <a>
    <reg count="5"> A0 </reg>
    <reg count="10"> A1 </reg>
  </a>
  <a>
    <reg count="10"> A2 </reg>
  </a>
</top>

Output:

  Node : start      end
  A0   :   1    -    5
  A1   :   6    -   15
  A2   :  16    -   25

--------------------------
So basically output of any node <reg> is based on all the <reg> nodes that 
have been processed
before it. If I could use a temporary variable, I would have just kept a 
running total of the
total "count" prior to processing that node.

Could someone suggest a solution or give me some pointer?

Thanks,
Anupam.



 
 
______________________________________________________
Click here to donate to the Hurricane Katrina relief effort.
http://store.yahoo.com/redcross-donate3/

Current Thread