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

Weird variable scoping rules

Subject: Weird variable scoping rules
From: Graham Ashton <gashton@xxxxxxxxxxx>
Date: 15 May 2002 17:21:02 +0100
scoping rules
If you take the following snippet of markup, how would a template that
processed a cell element work out the *maximum* number of <label>
elements in any of the <row>'s <cell> elements?

    <row>
      <cell>
        <vgroup>
          <label value="foo"/>
        </vgroup>
      </cell>
      <cell>
        <vgroup>
          <label value="bar"/>
          <label value="baz"/>
        </vgroup>
      </cell>
      <cell/>
    </row>

I tried to iterate over the cells and store the number of labels in a
"variable" (i.e. a param), keeping track of the maximum number seen for
any cell, but my attempts to keep track of the maximum value seen so far
aren't working.

Here's a template that runs on a single cell:

<xsl:template match="cell">

  <xsl:param name="max_vgroup_size" select="0"/>

  <xsl:for-each select="../cell">
    <xsl:param name="vgroup_size" select="count(vgroup/*)"/>
    <xsl:if test="$vgroup_size > $max_vgroup_size">
      <xsl:param name="max_vgroup_size" select="$vgroup_size"/>
    </xsl:if>
  </xsl:for-each>

  <td>
    vgroup: <xsl:value-of select="$max_vgroup_size"/>
    <xsl:apply-templates/>
  </td>

</xsl:template>

The assignment to $max_vgroup_size in the <xsl:if/> block works fine,
but by the time I want to use it (in the <td> at the bottom) the
$max_vgroup_size variable defined in the <xsl:if/> block has gone out of
scope.

How should I be approaching this? Thanks....

-- 
Graham Ashton


 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.