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

RE: test expression in predicates - is this one legal?

Subject: RE: test expression in predicates - is this one legal???
From: Stuart Brown <sbrown@xxxxxxxxxxx>
Date: Wed, 2 Apr 2003 11:15:36 +0100
xpath test expression
Hi Jian,

> <xsl:template match="bar[$foobar='number']">
> number
> </xsl:template>
...
> is it legal?
...

This is perfectly legal. The contents of a predicate simply have to be able
to be evaluated to true or false[1], and individual nodes are included or
excluded accordingly. The fact that a predicate "starts at" the context
node, and that most of the time you want to evaluate something in the
context of each specific potential inclusion does not prohibit you from
doing this kind of thing. You can predicate your expression on the value of
a variable/parameter, a node in a completely different part of the document
(using an absolute XPath starting with "/"), on the contents of another
document (using the document() function), or even (using extension
functions) only on a Tuesday.

> is this way considered a normal way of working?
> althou i'd prefer to use <xsl:choose/>

This is just a design decision. Personally, I use xsl:choose when there is a
small difference in handling, and predicated templates when there is a
significant variation. I know one person who believes that, for human
readability, no single XPath should be longer than one line, and therefore
almost always uses xsl:choose, but he's going to have problems the minute
XPath 2 is finalized anyway. People who have a better understanding of how
XSLT processors actually work will probably be able to offer better
recommendations of design practice based upon system expense.

In your instance, of the two templates which could potentially match "bar",
the processor selects that which is most specific. The fact that the
predicate does not actually reference the context node does not stop the
fact that there is a greater degree of specificity in the match value of the
first template.

Hope this helps,

Stuart

[1] Note that, for instance, "myNode[1]" is shorthand for "myNode[position()
= 1]".

 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.