Re: [xsl] accessing xml elements from current and external file

Subject: Re: [xsl] accessing xml elements from current and external file
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Thu, 4 Aug 2011 14:16:12 +0100
In case you're interested, a good way of doing this is to use a key:

<xsl:key name="config-options" match="d:options" use="."/>

then you can do:

<xsl:when test="key('config-options', /s:root/s:element[s:id = 1],
$config-doc)">

where $config-doc is

<xsl:variable name="config-doc" select="doc('configuration.xml')"/>

It should be more efficient, and avoids the need to keep pointers in
variables.

cheers
andrew


On 4 August 2011 13:58, Mansour Al Akeel <mansour.alakeel@xxxxxxxxx> wrote:
> Thank you all for the fast response.
> Yep putting the root in a variable seems to be what I need.
> It helped ! :)
>
> Thank you.
>
>
> On Thu Aug 04,2011 08:42 am, Murray McDonald wrote:
>>
>> Hi Mansour,
>>
>> It's a problem of context -- you need to put a "pointer" to "/s:root" into
a
>> varible and then access it that way:
>>
>> <xsl:variable name="docroot" select="/s:root"/>
>>
>>
>> Here is some code that explains what I am doing:
>>             <xsl:for-each
>> select="document('configuration.xml')/d:config/d:options">
>>             <option>
>>                 <xsl:attribute name="label" >
>>                 <xsl:choose>
>>                     <xsl:when test="$docroot/s:element[ s:id=1 ]= ." >
>>                     <xsl:value-of select="'true'" />
>>                     </xsl:when>
>>                 </xsl:choose>
>>                 </xsl:attribute>
>>             </option>
>>             </xsl:for-each>
>>
>> Murray
>
>



--
Andrew Welch
http://andrewjwelch.com

Current Thread