[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:variable doesn't work here

Subject: Re: xsl:variable doesn't work here
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 01 Mar 2002 15:29:56 -0500
xsl variable condition
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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.