xsl-list
[Top] [All Lists]

Re: [xsl] References to elements in predicates

2009-09-23 08:27:35
rowan(_at_)sylvester-bradley(_dot_)org wrote:

    <xsl:template match="item[string-length(ref)&gt;0]">
        <xsl:variable name="ref" select="ref"/>
        <xsl:copy-of select="//items/item[name=$ref]"/>
    </xsl:template>

But why do I need the variable? What do I have to write in the predicate to
compare the value of the name element in items as I search the file in the
copy-of with the ref element in the current node?

You can use current() e.g.
          <xsl:copy-of select="//items/item[name = current()/ref]"/>

You should however define a key e.g.
    <xsl:key name="k1" match="item" use="name"/>
and then do
    <xsl:copy-of select="key('k1', ref)"/>


--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
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>