After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 148773 - keys don't work inside an exsl:node-set
keys don't work inside an exsl:node-set
Status: VERIFIED FIXED
Product: libxslt
Classification: Platform
Component: general
1.1.7
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2004-07-29 14:22 UTC by Phil Endecott
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Phil Endecott 2004-07-29 14:22:40 UTC
Keys should work inside documents created using exsl:node-set, but they don't
seem to.  It is easiest to explain with an extract from a thread I started on
the xslt mailing list; this is / will be archived at
http://www.biglist.com/lists/xsl-list/archives/200407/msg00844.html

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

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

Phil> Thanks for the suggestion David.  But I can't get it to work.
Phil> 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>


Phil> I get no output.  But when I use the non-key lookup
Phil> (commented out) I get "A", as expected.  This is with
Phil> libxslt's xsltproc.  Does it work correctly on other
Phil> processors?

David Carlisle> It works in saxon:
David Carlisle> $ saxon keys.xsl keys.xsl
David Carlisle> <?xml version="1.0" encoding="utf-8"?>A


This is with libxslt 1.1.7, which seems to be the newest version is Debian Testing.

Regards, --Phil.
Comment 1 Daniel Veillard 2004-07-29 14:27:20 UTC
paphio:~ -> xsltproc --version tst.xsl tst.xsl
Using libxml 20611, libxslt 10108 and libexslt 806
xsltproc was compiled against libxml 20611, libxslt 10108 and libexslt 806
libxslt 10108 was compiled against libxml 20611
libexslt 806 was compiled against libxml 20611
<?xml version="1.0"?>
A
paphio:~ ->


  This Work fine in the latest released version apparently,

Daniel
Comment 2 Phil Endecott 2004-07-29 16:22:12 UTC
Hi Daniel, thanks for looking at this so quickly.  There's a problem with the
example; if you supply the stylesheet as the XML input to the processor, i.e.
"xsltproc tst.xsl tst.xsl" it will find the <a> elements within the variable
declaration.  Please try again but with a different file as the XML input file,
e.g. foo.xml = "<foo/>".  This seems to fail for me with libxslt 1.1.8, but I
have confirmed with David Carlisle that it works in Saxon.

Regards, --Phil.
Comment 3 William M. Brack 2004-08-02 15:57:31 UTC
I added some code to libxslt to assure keys are generated (when needed) for node-sets, and it certainly 
fixes your example:
bill@bbrack bug148773 $ ./xsltproc bug.xsl bug.xml
<?xml version="1.0"?>
A

Changed source is in cvs (several different source files involved).  Please check that your original file is 
now handled correctly, and re-open the bug if there is any problem.  Thanks for the report and the 
details.

Bill
Comment 4 Phil Endecott 2004-08-02 21:00:59 UTC
Bill,

Thanks.  I probably won't be able to try this for a couple of weeks (I'm going
on holiday) but I will check and confirm then.

--Phil.
Comment 5 Phil Endecott 2004-08-21 16:49:10 UTC
Hello again,

I can confirm that this seems to solve my original problem, as well as some
other key-related oddities that I was seeing.  (Or at least they have been fixed
by some change since 1.1.8).  Thanks!  However I'm not yet seeing the expected
speedup that keys should give me.  I'll file another bug if I can track down
what is going on.

--Phil.
Comment 6 William M. Brack 2004-08-21 19:58:05 UTC
Note the recent (16 Aug 04) enhancement to transform.c to fix bug133289 - this 
may be related to your performance concerns.

Bill
Comment 7 Daniel Veillard 2004-08-22 20:52:22 UTC
 This should be fixed in release libxslt-1.1.9.
                                                                                
   thanks,
                                                                                
Daniel