[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Spotting "cousin marriages" in a tree


Subject: Re: [xsl] Spotting "cousin marriages" in a tree
From: Phil Endecott <spam_from_xslt_list@xxxxxxxxxxxx>
Date: Thu, 29 Jul 2004 13:13:36 +0100

David Carlisle wrote:
All that is stopping me is that XSLT doesn't - as far as I know - allow for keys to be used on exsl:node-set()s,

keys, once set up, automatically apply, separately, to any document that is used and so if your exsl:node-set() returns a node set consisting of a root node / which it will if it is given a result tree fragment coming from xsl:variable, then your keys will apply to that.

Thanks for the suggestion David. But I can't get it to work. Here's my test code:


<xsl:transform
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exsl="http://exslt.org/common"
  extension-element-prefixes="exsl">

<xsl:key name="k" match="a" use="@x"/>

  <xsl:template match="/">
    <xsl:variable name="v">
      <n>
        <a x="1" y="A"/>
        <a x="2" y="B"/>
      </n>
    </xsl:variable>
    <xsl:apply-templates select="exsl:node-set($v)/*"/>
  </xsl:template>

  <xsl:template match="n">
<!--    <xsl:apply-templates select="a[@x='1']"/> -->
    <xsl:apply-templates select="key('k','1')"/>
  </xsl:template>

  <xsl:template match="a">
    <xsl:value-of select="@y"/>
  </xsl:template>

</xsl:transform>


I get no output. But when I use the non-key lookup (commented out) I get "A", as expected. This is with libxslt's xsltproc:


$ xsltproc --version
Using libxml 20610, libxslt 10105 and libexslt 804

Does it work correctly on other processors?

--Phil.


Current Thread
Keywords