In thread http://www.daniweb.com/forums/thread157149.html I was asking for different alternatives for passing a node as a parameter to an XSL stylesheet called from Java using saxon.

I set up on using the XdmNode object as a parameter for passing the parameter and here is a code extract:

//  create a XSLT transformer
XsltTransformer trans = comp.compile(new StreamSource(MyClass.getResourceAsStream(XSLT_FILE))).load();

// [...]

// sample XML to pass as parameter
String str = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" +
                    "<opsys:operatingSystems xmlns:opsys=\"http://osnews.pl/operating-systems\">\n" +
                    "    <opsys:operatingSystem id=\"1\">\n" +
                    "        <opsys:name>GNU/Linux</opsys:name>\n" +
                    "        <opsys:code>GNU</opsys:code>\n" +
                    "    </opsys:operatingSystem>\n" +
                    "    <opsys:operatingSystem id=\"2\">\n" +
                    "        <opsys:name>Microsoft</opsys:name>\n" +
                    "        <opsys:code>MSFT</opsys:code>\n" +
                    "    </opsys:operatingSystem>\n" +

            ByteArrayInputStream byteStream = new ByteArrayInputStream(str.getBytes());
            StringReader reader = new StringReader(str);

            SAXSource source = new SAXSource(new XMLFilterImpl(), new InputSource(reader));

            // this throws a null pointer exception in build method
            XdmNode node = db.build(source);

            // this works as intended
//            XdmNode node = db.build(
//                    new File("test.xml"));
          trans.setParameter(new QName("operatingSystems"), node);

Now as you can see in the above example, when I use a file as an input, the node is created fine and I can access the node with custom XML from the operatingSystems parameter in my XSLT (cool).
For some reason, when using a Source as an input for DocumentBuilder's build method, a NullPointerException is called.
The docs for DocumentBuilder: http://www.saxonica.com/documentation/javadoc/net/sf/saxon/s9api/DocumentBuilder.html#build(javax.xml.transform.Source) claim that I should be using either SAXSource or JAXP source or DOMSource or PullSource. I tried a few but they all cause this exception to be thrown.

Any ideas before I start debugging saxon libraries?

8 Years
Discussion Span
Last Post by michux

OK, it was indeed a bug in saxon, I guess, solved in the latest release of Saxon:
Sorry for bugging anyone.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.