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

Variable Scope

Subject: Variable Scope
From: Stuart Wilson <coracle@xxxxxxxxxxxxxx>
Date: Thu, 9 Nov 2000 12:15:30 +0000
xml variable scope
Hi,
  I've been looking through the FAQ and have a question about one of the 
examples under the "Basic Troubleshooting/Tables" section. The input is

<?xml version='1.0'?>
<TASKS>
  <TASK>
    <COMPONENTS>
      <COMPONENT>A</COMPONENT>
      <COMPONENT>B</COMPONENT>
      <COMPONENT>C</COMPONENT>
      <COMPONENT>D</COMPONENT>
      <COMPONENT>E</COMPONENT>
      <COMPONENT>F</COMPONENT>
      <COMPONENT>G</COMPONENT>
      <COMPONENT>H</COMPONENT>
      <COMPONENT>I</COMPONENT>
      <COMPONENT>J</COMPONENT>
      <COMPONENT>K</COMPONENT>
    </COMPONENTS>
  </TASK>
</TASKS>


and the XSL includes

<xsl:template match="TASKS/TASK/COMPONENTS">
  <xsl:variable name="t-size" select="count(COMPONENT)"/>
  <xsl:variable name="half" select="ceiling($t-size div 2)"/>

<TABLE>
  <xsl:for-each select="COMPONENT[position() &lt;= $half]">
   <xsl:variable name="here" select="position()"/>
        <TR>
      <TD><xsl:value-of select="."/><xsl:value-of select="$here"/></TD>
      <TD>
        <xsl:choose>
	  <xsl:when test="../COMPONENT[$here+$half]">
	    <xsl:value-of select="../COMPONENT[$here+$half]"/>
          </xsl:when>
          <xsl:otherwise></xsl:otherwise>
        </xsl:choose>
      </TD>
    </TR>
  </xsl:for-each>
</TABLE>

</xsl:template>

What I'm not clear about is why the 'here' variable is updatable as the 
for-each iterates, it was my understanding that variable values cannot be 
changed. 
Could someone explain ?

Thank you.

Totalise - the Users ISP
----------------------
To become a member and a shareholder
visit http://www.totalise.net

-----------------------
"Get the latest Ericsson 2618, Nokia 6210 and Samsung M100 at our 
Mobile Store, Visit www.totalisetelecom.net/store"    


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.