This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: use variable in <xsl:if test=
- From: Matt Gushee <mgushee at havenrock dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Fri, 1 Mar 2002 16:33:03 -0700
- Subject: Re: [xsl] use variable in <xsl:if test=
- References: <00a501c1c177$d24c0170$e4a1fea9@webspace>
- Reply-to: xsl-list at lists dot mulberrytech dot com
On Sat, Mar 02, 2002 at 12:21:29AM +0100, Robert Sösemann wrote:
> How in the world ;-) can i use a variable in <xsl:if test=..>
>
> <xsl:variable name="condition" select="*[.//author='C. J. Date']"/>
>
> <xsl:template match="node()[name()=$entity]">
> <xsl:if test="boolean(string($condition))">
There is nothing syntactically wrong with this. It would help if
you explained what result you are expecting.
> This does not work neigther with
> {$condition}
It shouldn't. You can't use attribute value templates in <xsl:if test="">.
You just put the variable reference in the attribute value, as in your
example. And it's okay to use the variable as an argument to a function,
and to nest functions.
Maybe you just have the wrong idea about what your XPath expression
is doing. In particular, I can't see a reason why you would need to
use both boolean() and string(). If $condition is an empty node-set,
then both boolean($condition) and string($condition) should evaluate
to false.
Ah, wait. I think I see the problem. It looks like you are defining
the variable at the top level of the stylesheet, aren't you? In that
case, it's always going to be false. '*' means 'any child _element_
of the current context node'. At the top level of the stylesheet,
there are no child elements.
You should probably define the variable within a template, where you
have more context information to work with.
--
Matt Gushee
Englewood, Colorado, USA
mgushee@havenrock.com
http://www.havenrock.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list