Re: [xsl] References to elements in predicates

Subject: Re: [xsl] References to elements in predicates
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Wed, 23 Sep 2009 14:27:09 +0200
rowan@xxxxxxxxxxxxxxxxxxxxx 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/

Current Thread