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

Re: Hello and quick question

Subject: Re: Hello and quick question
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 07 Jan 2003 14:01:05 -0500
Re:  Hello and quick question
What's worse, the expression:

/ROOT/Client/Contacts/Contact[isReferrer='0'][1]/ContactFirstName

will give results that are counterintuitive, since the [1] predicate operates not on the expression as a whole, but only on that particular step of that expression,

"Contact[isReferrer='0'][1]"

which (as all XSLT users certainly know!) is short for

child::Contact[isReferrer='0'][position()=1]

which means you'll get, not the first such Contact node in the document, but every Contact node (that meets the isReferrer criterion) *that is the first such child of its parent*.

To get around this, you can say

(/ROOT/Client/Contacts/Contact[isReferrer='0'])[1]/ContactFirstName

(Grouping the entire expression indicates the predicate [1] applies to the expression as a whole.)

But I actually rather like Corey's solution

string(/ROOT/Client/Contacts/Contact[isReferrer='0']/ContactFirstName)

...although were I to use it in a stylesheet, I'd certainly explain it in a comment -- as something non-obvious that might be expected to break if, say, the rules of how node-sets are converted into strings should change....

Cheers,
Wendell

At 11:36 PM 1/6/2003, Joerg's wrote:
Maybe you can better use some possible optimizations of the proceesor by adding [1] into the expression:

/ROOT/Client/Contacts/Contact[isReferrer='0'][1]/ContactFirstName

Furthermore you sometimes need a node set (even it's a single node) and not a string, e.g. <xsl:apply-templates select="/ROOT/Client/Contacts/Contact[isReferrer='0'][1]/ContactFirstName"/>, that won't work with string().

Simon has a little error in his expression. He selects the first Contact element, independent of [isReferrer='0'] or not. If this first Contact element does not have a child 'isReferrer' with text value '0', his node set would be empty.


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