Olivier Mengué schrieb:
2008/4/10, David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>:
in xslt1 you have to be in the right document already, which means
that in teh restricted context of xsl:sort you can only use a key if
your mappig element is in teh same document as the nodes over which
you are iterating.
Does it means that I can not use a key on the default input document
when I'm iterating (for-each) on nodes of another document (which
contains constants similar to Michael's categories) ?
In general, you *can*, by switching back to the default document using
the following idiom:
<xsl:key name="bla-lookup" match="ABC" use="@bla"/>
<!-- top level variable -->
<xsl:variable name="main-doc" select="/"/>
<!-- in some template -->
<xsl:for-each select="document($secondary-doc)/A/B">
<xsl:variable name="bla" select="@bla"/>
<xsl:for-each select="$main-doc">
<xsl:value-of select="key('bla-lookup', $bla)"/>
...
But in the case of xsl:sort, you *cannot* use this idiom, as xsl:sort
does not allow you to embed a context switch so you're restricted to
what's visible within the context of the secondary document. You must
use a variable in this case, which, of course, is unfortunate if the
node-set to search is large.
At least that's what I understood.
This seems to be an issue I currently have. I'm using xsltproc, so
XSLT 1.0.
In XSLT 2.0, this is much easier as the key() function takes a third
argument providing the context. So you can embed the context switch
within xsl:sort.
Michael
--~------------------------------------------------------------------
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>
--~--