Hi,


I'm trying to 'collect' nodes in a org.apache.xpath.NodeSet using Xalan
Extensions and found out a strange behaviour, which looks like a bug to
me.


I'm using this XML file:

items.xml:
==========
<?xml version="1.0" encoding="ISO-8859-1"?>
  <items>
    <item name="a">xa</item>
    <item name="b">xb</item>
    <item name="c">xc</item>
    <item name="d">xd</item>
  </items>


and this stylesheet:

collectortest.xsl:
==================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
  xmlns:coll="xalan://NodeCollector" exclude-result-prefixes="xalan coll">

  <xsl:template match="/">
    <out>
      <xsl:value-of select="coll:add(//item[@name='b'])"/>
      <xsl:value-of select="coll:add(//item[@name='a'])"/>
      <xsl:value-of select="coll:add(//item[@name='c'])"/>
      <xsl:value-of select="coll:add(//item[@name='a'])"/>
      <xsl:value-of select="coll:add(//item[@name='b'])"/>
      <xsl:for-each select="coll:getNodes()">
        :<xsl:value-of select="@name"/>
      </xsl:for-each>
    </out>
  </xsl:template>
</xsl:stylesheet>


and this Extension:

NodeCollector.java:
===================
import java.io.*;
import org.apache.xpath.NodeSet;
import org.w3c.dom.*;

public class NodeCollector
{
  private NodeSet nodeset = new NodeSet();

  public NodeCollector() {
    System.err.println("-----> NodeCollector instantiated");
  }

  public void add(NodeList nodes) {
    System.err.println("-----> called add, "+nodes.getLength()+" nodes");
    nodeset.addNodes(nodes);
  }

  public NodeSet getNodes() {
    System.err.println("-----> called getNodes, size: " + nodeset.size());
    return nodeset;
  }
}


The interesting part follows now:
Using xalan-j_2_1_0, I get this output:
  -----> NodeCollector instantiated
  -----> called add, 1 nodes
  -----> called add, 1 nodes
  -----> called add, 1 nodes
  -----> called add, 1 nodes
  -----> called add, 1 nodes
  -----> called getNodes, size: 5
  <?xml version="1.0" encoding="UTF-8"?>
  <out>
        :b
        :a
        :c
        :a
        :b</out>

This is what I expect (and want) to get...
but, using xalan-j_2_2_D10 or nightly builds, I get:

  <?xml version="1.0" encoding="UTF-8"?>
  -----> NodeCollector instantiated
  -----> called add, 1 nodes
  -----> called add, 1 nodes
  -----> called add, 1 nodes
  -----> called add, 1 nodes
  -----> called add, 1 nodes
  -----> called getNodes, size: 5
  <out>
        :a
        :b
        :c</out>

i.e. sorted and duplicates eliminated...
Since the getNodes()-size is 5, the NodeSet seems to be ok, and this
'error' is originating elsewhere (in the DTM ??)
I even tried a NodeList (which doesn't seem to work in 2_1_0, but it
didn't change anything.

So, is this a bug or a feature ? ;)
If it is intended, how do I manage to get my 'wanted' output ?


Thanks and regards,
Patrick
--
* Dipl.-Inform. Patrick Lay
* Institut f�r Informatik III     Phone +49 (228) 73-4537
* Universit�t Bonn                Fax   +49 (228) 73-4382
* R�merstra�e 164                 [EMAIL PROTECTED]
* D-53117 Bonn (Germany)          http://www.informatik.uni-bonn.de/~lay/


Reply via email to