[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: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Tue, 07 Jan 2003 05:36:01 +0100
simon heinicke
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.

Regards,

Joerg

Corey Snow wrote:
I may have answered my own question by experimentation.

This xsl fragment seems to work:

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

By only returning a string representation of the first node in this set.
Is this the "right" way to accomplish this or is there a better/more
preferred way?

Thanks again,

Corey Snow


-----Original Message-----
From: Corey Snow Sent: Monday, January 06, 2003 3:54 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Hello and quick question



Hi all- good to be back on the list; I got bounced from my old job and haven't been in a position to collect a lot of email in that time.


I have a quick question for you XSLT-guru types: How can I obtain the first node of a set of nodes that meets a given set of criteria? In my case, I have an XML document that contains zero or more nodes in a particular element, like so:

<ROOT>
<Client>
... Various elements here ...
<Contacts>

<Contact ContactId='5'>
... Contact information ...
<IsReferrer>1</IsReferrer>
</Contact>

<Contact ContactId='10'>
... Contact information ...
<IsReferrer>0</IsReferrer>
</Contact>

<Contact ContactId='25'>
... Contact information ...
<IsReferrer>1</IsReferrer>
</Contact>

</Client>
</ROOT>

I have no real control over the order of these elements, and what I need to be able to do is obtain the first Contact element which has zero
('0') in the IsReferrer element. Actually, I need to get the value of a child element (ContactFirstName) of this element.


I can do something like: /ROOT/Client/Contacts/Contact[IsReferrer='0']/ContactFirstName
but that returns a node-set, not a single node. I assume I need to do something with the position() function, but I'm not sure how to go about it.


Thanks in advance for any assistance,

Corey M. Snow, Delivery Consultant


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.