Public bug reported:

I'm using libxslt and xsltproc 1.1.26-6 in Ubuntu maverick.

When I use xsltproc with the following XML document:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <a>
    <b reference="1"/>
  </a>
  <c id="1" />
</root>

and the following XSLT transformation:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
  <xsl:key name="key-test" match="*" use="@id" />
  <xsl:key name="key-test" match="*" use="@reference" />
  <xsl:template match="/">
    <xsl:copy-of select="key('key-test', '1')[1]" />
    <xsl:copy-of select="key('key-test', '1')" />
  </xsl:template>
</xsl:transform>

the output is:
<?xml version="1.0"?>
<c id="1"/><b reference="1"/><c id="1"/>

So in this case, key('key-test', '1')[1] returns a node (c in this case)
that is not the first node that is returned when using key('key-test',
'1') (this returns b followed by c).

I've tried Saxon 9.3.0.4 and the SAP XSLT Processor, and both returned what I 
would have expected:
<?xml version="1.0"?>
<b reference="1"/><b reference="1"/><c id="1"/>

I have also noticed that changing the order of the two xsl:key elements
in my transformation changes the result of key('key-test', '1')[1] in
xsltproc, while key('key-test', '1') stays the same. In both Saxon and
the SAP XSLT Processor, the order of the elements does not have any
influence on the output.

As both Saxon and the SAP XSLT Processor behave the way I would have
expected, and xsltproc does not, I assume there is something wrong with
xsltproc.

Edit: XSLT transformation was not indented properly.

** Affects: libxslt (Ubuntu)
     Importance: Undecided
         Status: New

** Description changed:

  I'm using libxslt and xsltproc 1.1.26-6 in Ubuntu maverick.
  
  When I use xsltproc with the following XML document:
  
  <?xml version="1.0" encoding="utf-8"?>
  <root>
-   <a>
-     <b reference="1"/>
-   </a>
-   <c id="1" />
+   <a>
+     <b reference="1"/>
+   </a>
+   <c id="1" />
  </root>
  
  and the following XSLT transformation:
  
  <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
-   <xsl:key name="key-test" match="*" use="@id" />
-   <xsl:key name="key-test" match="*" use="@reference" />
-     <xsl:template match="/">
-     <xsl:copy-of select="key('key-test', '1')[1]" />
-     <xsl:copy-of select="key('key-test', '1')" />
-   </xsl:template>
-   </xsl:transform>
+   <xsl:key name="key-test" match="*" use="@id" />
+   <xsl:key name="key-test" match="*" use="@reference" />
+   <xsl:template match="/">
+     <xsl:copy-of select="key('key-test', '1')[1]" />
+     <xsl:copy-of select="key('key-test', '1')" />
+   </xsl:template>
+ </xsl:transform>
  
  the output is:
  <?xml version="1.0"?>
  <c id="1"/><b reference="1"/><c id="1"/>
  
  So in this case, key('key-test', '1')[1] returns a node (c in this case)
  that is not the first node that is returned when using key('key-test',
  '1') (this returns b followed by c).
  
  I've tried Saxon 9.3.0.4 and the SAP XSLT Processor, and both returned what I 
would have expected:
  <?xml version="1.0"?>
  <b reference="1"/><b reference="1"/><c id="1"/>
  
  I have also noticed that changing the order of the two xsl:key elements
  in my transformation changes the result of key('key-test', '1')[1] in
  xsltproc, while key('key-test', '1') stays the same. In both Saxon and
  the SAP XSLT Processor, the order of the elements does not have any
  influence on the output.
  
  As both Saxon and the SAP XSLT Processor behave the way I would have
  expected, and xsltproc does not, I assume there is something wrong with
  xsltproc.
+ 
+ Edit: XSLT transformation was not indented properly.

** Description changed:

  I'm using libxslt and xsltproc 1.1.26-6 in Ubuntu maverick.
  
  When I use xsltproc with the following XML document:
  
  <?xml version="1.0" encoding="utf-8"?>
  <root>
    <a>
      <b reference="1"/>
    </a>
    <c id="1" />
  </root>
  
  and the following XSLT transformation:
  
  <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
    <xsl:key name="key-test" match="*" use="@id" />
-   <xsl:key name="key-test" match="*" use="@reference" />
+   <xsl:key name="key-test" match="*" use="@reference" />
    <xsl:template match="/">
-     <xsl:copy-of select="key('key-test', '1')[1]" />
-     <xsl:copy-of select="key('key-test', '1')" />
+     <xsl:copy-of select="key('key-test', '1')[1]" />
+     <xsl:copy-of select="key('key-test', '1')" />
    </xsl:template>
  </xsl:transform>
  
  the output is:
  <?xml version="1.0"?>
  <c id="1"/><b reference="1"/><c id="1"/>
  
  So in this case, key('key-test', '1')[1] returns a node (c in this case)
  that is not the first node that is returned when using key('key-test',
  '1') (this returns b followed by c).
  
  I've tried Saxon 9.3.0.4 and the SAP XSLT Processor, and both returned what I 
would have expected:
  <?xml version="1.0"?>
  <b reference="1"/><b reference="1"/><c id="1"/>
  
  I have also noticed that changing the order of the two xsl:key elements
  in my transformation changes the result of key('key-test', '1')[1] in
  xsltproc, while key('key-test', '1') stays the same. In both Saxon and
  the SAP XSLT Processor, the order of the elements does not have any
  influence on the output.
  
  As both Saxon and the SAP XSLT Processor behave the way I would have
  expected, and xsltproc does not, I assume there is something wrong with
  xsltproc.
  
  Edit: XSLT transformation was not indented properly.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/722343

Title:
  xsltproc returns nodes in wrong order when using xsl:key

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to