This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Need help with parameters and Indexes
- To: "Daniel Newman" <daniel dot newman at bis-web dot net>
- Subject: Re: [xsl] Need help with parameters and Indexes
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Tue, 27 Feb 2001 17:45:00 +0000
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <NEBBJGCDKMLHOAAONGKDIEKECAAA.daniel.newman@bis-web.net>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Daniel,
> In my code you'll notice I pass the parameter $count. Now this is
> either 1 or 2. When I run this transformation, I always get the
> result of ANNUALFORECAST[1]/ESTIMATEDATA, even though when I print
> the value of $count on the page, the first time it's 1, and the
> second time it's 2. Also, if I manually ask for
> ANNUALFORECAST[2]/ESTIMATEDATA, I get it. So, why aren't the indexes
> responding to the value I'm asking for? Do you have to change the
> data type of $count or something?
When you put $count in a predicate, then it will be interpreted as a
boolean unless it's a number.
I bet that you're setting your parameter with:
<xsl:with-param name="count">2</xsl:with-param>
or:
<xsl:with-param name="count">
<xsl:value-of select="..." />
</xsl:with-param>
In these cases, the parameter $count is set to a result tree fragment.
When you test an RTF in a boolean context, it always returns true
(because it always has a root node). So if you've set the value as
above then:
ANNUALFORECAST[$count]
will always select all the ANNUALFORECAST children of the current
node. If you take the *value* of this node set, then you get the
string value of the *first* node in it - the first ANNUALFORECAST
child. So you get the same result whatever value you give $count.
Two ways around it: you can convert $count to a number explicitly
with:
ANNUALFORECAST[number($count)]
and it will be interpreted as a position.
Or you can pass the parameter value using the select attribute, such
as:
<xsl:with-param name="count" select="2" />
or:
<xsl:with-param name="count" select="..." />
where ... is whatever you had in your xsl:value-of.
But be aware with either of the two above that the value *has* to
evaluate to a number to get it to work. It's no good producing a
string or node set value, for example.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list