Hello Michael!

My Method is:

    public static NodeList getElementList(String rootName, String elementName, double counter) {
        DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
        dbfactory.setNamespaceAware(true);
        try {
            DocumentBuilder domparser = dbfactory.newDocumentBuilder();
            Document document = domparser.newDocument();
            Element element = document.createElement(rootName);
            document.appendChild(element);
            for (int i = 0; i < counter; i++)
                element.appendChild(document.createElement(elementName));
            return element.getChildNodes();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

The call for example is in the select of a for-each

b:Bestellung/b:Waren/b:Buch | i:getElementList('r','e',1-count(b:Bestellung/b:Waren/b:Buch))/*

so this means e.g. i:getElementList('r','e',1) give a NodeList with one element back.

In Xalan and Saxon 9.0 I use i:getElementList('r','e',1)/* and the for-each iterates 1 times. In Saxon 9.1 it only works if I call i:getElementList('r','e',1).



To explain this - maybe you have a better solution for me: I generate this XSLT. I want to be able to generate at least a given number of b:Buch elements in the result, also if they are not in the input dokument. For this e.g.

b:Bestellung/b:Waren/b:Buch | i:getElementList('r','e',3-count(b:Bestellung/b:Waren/b:Buch))/*

generates min. 3 b:Buch elements in the result. If there are Elements in the input, than this elements are used. If there are 2 elements, then they will be used and one more will be generated.

best regards, marc pellmann

The nodes in a NodeList are not children of the NodeList, so I don't see how they would ever be found by following the child axis.
 
The only explanation I can think of is that I've come across DOM implementations where the same object implements Node in respect of a parent node, and NodeList in respect of its children. (This kind of thing makes programming using dynamic types extremely error-prone!)
 
Please supply sufficient information that I can reproduce and investigate the problem. However, I would expect that when you return a DOM NodeList, it is mapped to an XPath sequence of nodes, so the behaviour you describe as the 9.1 behaviour looks correct to me.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Marc Pellmann [mailto:marc.pellmann@inubit.com]
Sent: 24 June 2009 16:18
To: saxon-help@lists.sourceforge.net >> Mailing list for SAXON XSLT queries
Subject: [saxon] Change from 9.0 to 9.1 in org.w3c.NodeList?

Hello!

In an java function, that I call from an XSLT script I give back a org.w3c.NodeList. In Version 9.0 (like in Xalan, too) I could access this in a for-each by method()/* and get all nodes in the list. In 9.1 I need to use method() (without slash and star).

Now I have the problem of different access by Xalan/Saxon.

best regards, marc pellmann