This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: xsl:variable doesn't work here


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@web.de)
>
>  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@mulberrytech.com
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]