[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to do this without updating a variable?

Subject: Re: How to do this without updating a variable?
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Thu, 8 Sep 2005 22:03:13 +0530
xsl update a variable
Hi Anupam,
   Please try this stylesheet

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

<xsl:output method="text" />

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

</xsl:stylesheet>

Regards,
Mukul

On 9/8/05, Agnisys Technology (P) Ltd. <agnisys@xxxxxxxxx> wrote:
> 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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.