Re: [xsl] XPath 1.0 id() function

Subject: Re: [xsl] XPath 1.0 id() function
From: Nadia.Swaby@xxxxxx
Date: Tue, 23 Aug 2005 10:23:18 -0400
Hi David,

Can I do the following:

<xsl:variable name="xlabel" select="key('id', $target)/@xreflabel"/>
?

Nadia


                                                                                                                                
                      David Carlisle                                                                                            
                      <davidc@xxxxxxxx         To:      xsl-list@xxxxxxxxxxxxxxxxxxxxxx                                         
                      k>                       cc:                                                                              
                                               Subject: Re: [xsl] XPath 1.0 id() function                                       
                      2005-08-23 10:11                                                                                          
                      Please respond                                                                                            
                      to xsl-list                                                                                               
                                                                                                                                
                                                                                                                                





>
> <xsl:variable name="xlabel">
>       <xsl:value-of select="id($target)/@xreflabel"/>
> </xsl:variable>
>

don't use a variable with content here (even when id() works) use a
select attribute:

<xsl:variable name="xlabel"select="id($target)/@xreflabel"/>

>
> I have to resort to this:
> <xsl:variable name="xlabel">
>       <xsl:for-each select="//*[@id = $idd]">
>             <xsl:value-of select="@xreflabel"/>
>       </xsl:for-each>
> </xsl:variable>


Again you don't want to use a variable with content, or a for-each:


<xsl:variable name="xlabel" select="//*[@id = $idd]"/>

However if you are accessing that more than once it's more efficient to
use keys which are documented as being for use in exactly this case
(when id() is not available)

<xsl:key name="id" match="*[@id]" use="@id"/>
....
<xsl:variable name="xlabel" select="key('id',$idd)"/>

> the id() function only works when the DTD is
> declared in the XML Document.  Does anyone know if this is true?

That's what it says in the spec, how else would XSLT know which
attributes are of type ID (XML attatches no special significance to
attributes with name id).

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread