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

Re: Novice question: selecting an element based on an

Subject: Re: Novice question: selecting an element based on an attribute id
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 20 Mar 2002 17:56:51 +0000
Re:  Novice question: selecting an element based on an
Hi Ohmson,

> As you can see, based on "myIdRef", I am supposed to retrieve the
> original string. In this example, the referent and the reference are
> close but sometimes in a big document, they could be far apart. I
> bet I can do this inefficiently by keeping state of all the
> referents in XSL variables but you folks probably have an better
> idea on how to do this efficiently.

Use a key. You can set up a key so that all the elements that have a
myId attribute are indexed by their myId attribute:

<xsl:key name="values" match="*[@myId]" use="@myId" />

And then retrieve an element with a particular value for its myId
attribute using the key() function. For example, to get the element
whose myId attribute is 28, you can use:

  key('values', 28)

If the current node has a myIdRef attribute, then you can use that to
provide the second argument to the call for the key:

  key('values', @myIdRef)

The call to the key() function actually returns the node; you can
apply templates to it, for example, to process it:

  <xsl:apply-templates select="key('values', @myIdRef)" />

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.