[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] xsl:variable doesn't work here
Subject: Re: [xsl] xsl:variable doesn't work here
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 01 Mar 2002 15:29:56 -0500
|
Robert,
At 03:02 PM 3/1/2002, you wrote:
Instead of
<xsl:if test=".//article[.//author='C. J. Date']">
..
<xsl:copy-of select=".//article[.//author='C. J. Date']"/>
i want to store the condition in a variable condition and write
<xsl:variable name="condition">.//article[.//author='C. J.
Date']</xsl:variable>
<xsl:if test="$condition">
..
<xsl:copy-of select="$condition"/>
What's happening is that you're storing a string ".//article[.//author='C. J.
Date']" in your variable, not the node. (Actually it's a result tree
fragment with one text node child, but this amounts to the same thing as a
string when you test on it.) Given that the variable is assigned and the
string is not empty, when evaluated as a Boolean (as it is in an if test),
it always tests as true.
You can assign the node itself (themselves: as far as the processor knows
there could be more than one) to the variable by declaring it like so:
<xsl:variable name="condition" select=".//article[.//author='C. J. Date']"/>
and that should work for you.
But why test for the existence of these nodes at all? If you merely say
<xsl:copy-of select=".//article[.//author='C. J. Date']"/>
the nodes will be copied if they exist, but if they don't ... they won't.
If you have to do more than just copy the nodes or apply templates to them
based on your condition (namely whether any exist), then assigning them to
a variable to test, and then do your stuff, makes sense.
Cheers,
Wendell
But this does not work. I also tried {$condition} instead of $condition.
Whats wrong?
............................................................................
..........
ROBERT SÖSEMANN (robert.soesemann@xxxxxx)
schwärzlocherstr. 29/1 | 72070 tübingen
tel : 07071 / 400 880
icq# : 100 467 870
pgp-keys : www.webspace-journey.de/pgp.asc
............................................................................
..........
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
======================================================================
Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|