xsl-list
[Top] [All Lists]

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

2011-08-04 08:16:22
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(_dot_)alakeel(_at_)gmail(_dot_)com> 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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





-- 
Andrew Welch
http://andrewjwelch.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>