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

RE: Using id() when id and idref are in 2 different fi

Subject: RE: Using id() when id and idref are in 2 different files
From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx>
Date: Mon, 13 Dec 2004 10:49:38 -0000
xsl idref
> So I have tried using document() to read the castlist into a
> variable called $cast. Now I can use <xsl:value-of
> select="$cast//@id" /> to output the required values but I
> can't get it to work with the id()function. <xsl:value-of
> select="id(@who)" /> just fails, which doesn't surprise me.
> However <xsl:value-of select="$cast//role[@id = @who]" />
> also returns nothing. Is it because it is now looking for
> @who within $cast?

Using the id() function relies on the XML getting validated against a
DTD (that specifies that attribute as type ID) - are you sure your
imported files are being validated?  Even then I'm not sure it's
possible...

As an alternative to the id() function, you could use a key:

<xsl:key name="ids" match="*" use="@id"/>

and then access the values:

<xsl:value-of select="key('ids', @who)"/>

Remember to change the context nodes to the referenced XML when you want
to key into that:

<xsl:variable name="who" select="@who"/>
<xsl:for-each select="$cast">
  <xsl:value-of select="key('ids',$who)"/>
</xsl:for-each>

In XSLT 2.0 this can be shortened to:

<xsl:value-of select="key('ids', @who, $cast)"/>

...which is great because you don't need the variable anymore.

cheers
andrew

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.