[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Sorting using helper structure, position(), xsl:ke

Subject: Re: Sorting using helper structure, position(), xsl:key
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Tue, 15 Apr 2008 18:18:42 +0200
Re:  Sorting using helper structure
Olivier Mengui schrieb:
2008/4/10, David Carlisle <davidc@xxxxxxxxx>:
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.


Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.