This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Referencing nodes from an out-of-scope xsl:for-each loop
- To: "Joel P Thornton" <joelt at tlchoices dot com>
- Subject: Re: [xsl] Referencing nodes from an out-of-scope xsl:for-each loop
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Fri, 18 May 2001 08:16:41 +0100
- CC: "Xsl-List" <xsl-list at lists dot mulberrytech dot com>
- Organization: Jeni Tennison Consulting Ltd
- References: <NDBBJLODDMKIOFAANFMHCEGGCNAA.joelt@tlchoices.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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