|
[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








