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

Re: use variable in <xsl:if test=

Subject: Re: use variable in <xsl:if test=
From: Robert Sösemann <robert.soesemann@xxxxxx>
Date: Sat, 2 Mar 2002 09:52:43 +0100
xsl if test variable
Sorry for only explaining the half of my problem.

Instead of writing

<xsl:if test="*//author='C. J. Date']"/>

10 times in my stylesheet I want to use ONE variable or constant
to set it once at the beginning and then use it like that:

<xsl:if test=variable/>

How must I declare this variable and how do I use it in xsl:if???????????

----- Original Message -----
From: "Matt Gushee" <mgushee@xxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Saturday, March 02, 2002 12:33 AM
Subject: Re:  use variable in <xsl:if test=


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@xxxxxxxxxxxxx
http://www.havenrock.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 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.