This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: variable with node in xsl:choose
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: inchi2000 at gmx dot de
- Cc: XSL-List at lists dot mulberrytech dot com
- Date: Tue, 23 Jul 2002 11:28:02 +0100
- Subject: Re: [xsl] variable with node in xsl:choose
- Organization: Jeni Tennison Consulting Ltd
- References: <18033.1027418330@www33.gmx.net>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Markus,
> I want to use a variable in a for:each... so it works fine:
>
> <xsl:variable name="anzrows" select="//user/nokeyuser/name"/>
> <xsl:for-each select="$anzrows">
>
> But I want the select in the variable choosen by a condition like this:
>
> <xsl:choose>
> <xsl:when test="$anznokeyuser > $anzkeyuser"><xsl:variable name="anzrows"
> select="//user/nokeyuser/name"/></xsl:when>
> <xsl:otherwise><xsl:variable name="anzrows"
> select="//user/keyuser/name"/></xsl:otherwise>
> </xsl:choose>
You have to use a bit of a trick to get this to work. You want to get
the //user/nokeyuser/name element(s) if $anznokeyuser is more than
$anzkeyuser, and //user/keyuser/name otherwise. The best way to do
this is to create a union of the //user/nokeyuser/name (if
$anznokeyuser > $anzkeyuser):
(//user/nokeyuser/name)[$anznokeyuser > $anzkeyuser]
and //user/nokeyuser/name (if $anznokeyuser <= $anzkeyuser):
(//user/keyuser/name)[not($anznokeyuser > $anzkeyuser)]
So use:
<xsl:variable name="anzrows"
select="(//user/nokeyuser/name)[$anznokeyuser > $anzkeyuser] |
(//user/keyuser/name)[not($anznokeyuser > $anzkeyuser)]"/>
<xsl:for-each select="$anzrows">
...
</xsl:for-each>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list