XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
(Deleted User) Subject: how can i declare a variable and use the same variable in different tags?
Author: (Deleted User)
Date: 29 Jun 2007 01:41 AM
Originally Posted: 29 Jun 2007 01:38 AM

hi,

i have to declare a variable and do the below operation using xslt.

<a>
want to declare a variable and initialise with 1.(for ex: a=1)
</a>
<b>
i want to increment the value of a in this tag.(a=a++)
</b>
<c>
i want to store the final value of a in this tag.
</c>

is this possible in xslt? if so can i have code for doing this.


Regards,
yasodhara.

Postnext
(Deleted User) Subject: how can i declare a variable and use the same variable in different tags?
Author: (Deleted User)
Date: 29 Jun 2007 04:01 AM
Hi yasodhara,
XSLT is not a procedural language like C++ or Java, so it doesn't supports this kind of programming. Variables are read-only, and counters are deeply discouraged.
Try rewriting your logic to use recursion instead of counters.

Hope this helps,
Alberto

Postnext
(Deleted User) Subject: how can i declare a variable and use the same variable in different tags?
Author: (Deleted User)
Date: 29 Jun 2007 04:39 AM
hi Alberto,

can u explain with an example how can i use recursion for solving this problem.

Regards,
Yasodhar.

Postnext
(Deleted User) Subject: how can i declare a variable and use the same variable in different tags?
Author: (Deleted User)
Date: 29 Jun 2007 06:31 AM
An example is writing a template that accepts a "count" parameter, that in its code calls itself with the value count+1. But it could well be that your application doesn't need a counter at all, but only to store the number of nodes that match some condition.... but without seeing your XML and XSLT and knowing which version of Stylus and which XSLT processor you are using it's hard to be more specific.

Alberto

Postnext
(Deleted User) Subject: how can i declare a variable and use the same variable in different tags?
Author: (Deleted User)
Date: 29 Jun 2007 08:15 AM
Thankyou for your immediate reply.

i am using enterprise version of stylus studio. i didnt configure any specific processor. its in default state. i hope this version uses XSLT 2.0. so just give me an idea so that i can work it out.

<a>
<b>aaaaaaaaaa</b>
<c>aaaaaaaa1</c>
</a>
<d>
<e>140</e>
</d>
<f>
final value
</f>

my xml looks like this. when i read tag "<a>", i have to declare a varialble and initialize with 1. when i read tag "<d>", i have to increment and the final value to be stored in tag "<f>". i hope you got my requirement.

Regards,
yasodhar.

Posttop
(Deleted User) Subject: how can i declare a variable and use the same variable in different tags?
Author: (Deleted User)
Date: 29 Jun 2007 08:54 AM
Hi yasodhar,
the use case is still unclear (for instance, are you trying to process the XML in-place, or do you start from a different XML? Do you expect to find more than one <d> tag? What happens if the <a> tag is not present?).
From what I can guess (you are iterating over the parent tag of <a>,<d> and <f>, <a> must be present, <d> can be present multiple times), you could write a

<f>
<xsl:if test="a">
<xsl:value-of select="count(d)+1"/>
</xsl:if>
</f>

Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.