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

Re: Referencing nodes from an out-of-scope xsl:for-eac

Subject: Re: Referencing nodes from an out-of-scope xsl:for-each loop
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 18 May 2001 08:16:41 +0100
xsl parameter out of scope
Hi Joel,

> Currently, I <xsl:for-each> through the collection of <row> nodes,
> and then <xsl:for-each> through each of the <column>s for each row.
> The problem is, I have a <xsl:template match="sql-field"> template
> which matches the <sql-field> tags within the <column> tags. But I
> don't know how to get that template to "know" which row it is
> currently on. I tried using <xsl:variable> but I'm being told that,
> within the sql-field template, the variable is out of scope.

You need to pass a parameter into the template.  In the template, you
need to define the parameter that you're expecting, and you can give a
default value for it if you want:

<xsl:template match="sql-field">
   <xsl:param name="row" select="/.." />
   ...
</xsl:template>

(This sets the default to an empty node set - that's the default I
usually use when I'm expecting the template to be passed a node set.)

When you apply templates to sql-field, you need to pass the row in
with the parameter:

   <xsl:apply-templates select="sql-field">
      <xsl:with-param name="row" select="$row" />
   </xsl:apply-templates>

One thing that you should be careful of here is that parameters are
only passed if they're *explicitly* passed from template to template -
it's very easy to lose them accidentally if you use the built-in
templates to get some default processing.  So for example if you
applied templates to the column rather than the sql-field, and didn't
have a template for the column that accepted and passed on the $row
parameter, then you'd lose it.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.