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.
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.
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.
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.
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