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

XSLT variables and for-each loop

Subject: XSLT variables and for-each loop
From: Oleg Konovalov <olegkon@xxxxxxxxx>
Date: Fri, 13 May 2005 10:42:11 -0400
xslt variable for each
 Hi,

I am new to XSLT, trying to significantly modify somebody
else's XSL. That is not 2.0.

I need to create min & max variable(s)
to be used in many templates and sub-templates
based on certain conditions (not always).

It can't be calculated at the beginning of the file
(depends on other variables),
so seems like it has to be made local variable(s).

Since it's not easy to calculate (20-50 lines of code each)
probably makes sense to make a template out of it.

What I don't know is:
1) how to make template to return a value, something like
[that's not XSLT
2.0]:
 <xsl:variable min><call-template
name="calculate-min"/></xsl:variable>

2) how to declare a global variable and then assign it much
later in the
code;

3) Also, it there a way to compare a node value with a previous
value within a for-each loop like (to find a max value of the
nodes):
<xsl:for-each mystruct/mystuct1>
 <xsl:if test="position() &gt; 1  and
   var2 &gt; var2(position()-1)">...do something...
 </xsl:if>
</xsl:for-each>
Would that work ?

4) Can I get access to a value from another branch
from within for-each (where var2 and var3 are "brothers")?

Imagine you have an XML tree which has the structure like:
mystruct/myvar1[i]/myvar/var2 and
mystruct/myvar2[i]/myvar/var3

I need to compare the values of them for the same index "i".
Can I do it in for-each loop like that:
<xsl:for-each mystruct/myvar1[i]/myvar>
  <xsl:if test="number(var2) &gt; number(../../myvar2[i]/myvar/var3)">
   ...do something...
  </xsl:if>
</xsl:for-each>)

Any help is very appreciated.

Thank you in advance,
Oleg

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.