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

Re: Using variables or parameters in tests

Subject: Re: Using variables or parameters in tests
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 02 Mar 2005 11:03:00 -0500
xsl test date
Playing tag-team with David....

At 06:33 PM 3/1/2005, he wrote:
datetest = (date >= 20050228)

variables hold values not expressions, so you while this

<xsl:value-of
select="sum(/statement/item[$datetest and $electricitytest]/amount)"/>

is legal; $datetest would be a constant holding whatever value it is
bound to, it wouldn't get a new value relative to each item node.

Note that if the test were not relative to the context node, everything would work fine.


That is, if instead of needing to test "date >= 20050228" (is the value of any date child element >= 20050228?), you needed to test "//date >= 20050228" (is the value of any date in the document >= 20050228?), then you could do:

datetest = (//date >= 20050228)

$datetest would be a Boolean with value "true" or "false", allowing you to perform the test anywhere the variable is in scope just by saying test="$datetest" or "expr[$datetest]".

Since the test is an absolute, global test, it makes sense to bind it to a variable at the top level so it has global scope.

I've used this technique on occasion and it works fine. The local version, scoped to a template, also works, but naturally gives you less bang for your buck (how many times do you have to do the same test in a given template)?

The essence of why this won't work with a relative expression inside a predicate is that the expression "date >= 20050228" is not actually the same test every time: when the context node is different, the test is different. This would be true in XSLT 2.0 too, which is why this limitation persists (although being able to define a function, as David shows, provides another way to approach the problem).

Cheers,
Wendell


====================================================================== 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 ======================================================================

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.