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

Re: XSL attribute?

Subject: Re: XSL attribute?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 1 Nov 2001 18:33:34 +0000
xsl attribute name media
Hi Greg,

> I need help pulling a file name from an element name through an
> attribute. My media is listed under a media items section and then
> referenced in the text by an attribute. Is there any way of
> referencing an element from an attribute?

Yes. Set up a key that indexes all the media_item elements by their
identifier attribute with xsl:key. The name is anything you like (e.g.
'media'), the match attribute is a pattern that matches the elements
that you want to index (i.e. media_item elements) and the use
attribute is an expression that takes you from those elements to the
value you want to use to reference them (i.e. a path from media_item
elements to their identifier attributes). The key could look like:

<xsl:key name="media" match="media_item" use="@identifier" />

With that key in place, you can retrieve elements using the key()
function. The first argument is the name of the key (i.e. 'media') and
the second argument is the value of the identifier for the element
(e.g. 'medad59010005'):

  key('media', 'medad59010005')

>         <instruction_content>
>             <media_ref media_alias="medad59010005"/>
>         </instruction_content>
>
> I need the <access_name> in place of the <media_ref> tag

OK. Have a template that matches media_ref elements:

<xsl:template match="media_ref">
  ...
</xsl:template>

In that template, you can use the path @media_alias to access the
value of the media_alias attribute, and pass that as the second
argument to the key() function to get the relevant media_item:

  key('media', @media_alias)

>From that media_item, you can journey down to the access_name element
as follows:

  key('media', @media_alias)/access_name

So your template is:

<xsl:template match="media_ref">
  <xsl:value-of select="key('media', @media_alias)/access_name" />
</xsl:template>

I hope that helps,

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.