I've recently being trying out the xalan-j 2.2 developer releases, because I
would very much like to try out the DTM stuff to see what kind of speed
increase it gives us.
I'm using JDK 1.3.1, Xalan-j 2.2.D13, xerces-j 1.4.3 on windows 2000.
Anyway, I've run into a problem. Our application uses DOMSources to feed
data into our XSLT... and this no longer seems to work with 2.2.
I have supplied a sample test case, appended to this mail.
This looks like a bug to me, but I thought I should check with this list
first, in case I have done something stupid.
(This isn't my normal coding style BTW, but I thought it would be easier to
just have one file to deal with, if people want to try running it
themselves)
------- START SAMPLE CODE -------
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import java.io.*;
public class testit {
private static String xslt =
"<xsl:stylesheet "+
" version=\"1.0\" "+
" xmlns:TEST=\"TESTURI\""+
" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\""+
" xmlns:xalan=\"http://xml.apache.org/xalan\">"+
" <xsl:output method=\"xml\" version=\"1.0\" encoding=\"UTF-8\"
indent=\"no\"/>"+
" <!-- main template -->"+
" <xsl:template match=\"/TEST:actions\">"+
" <MATCHED/>"+
" </xsl:template>"+
"</xsl:stylesheet>";
private static String xmlText =
"<TEST:actions xmlns:TEST=\"TESTURI\"/>";
public static void main(String[] args)
throws Throwable {
// create a new DocumentBuilder
DocumentBuilderFactory docFactory =
DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// Create a new TransformerFactory
TransformerFactory tFactory = TransformerFactory.newInstance();
// Create a new transformer
Templates templates = tFactory.newTemplates(new StreamSource(new
StringReader(xslt)));
Transformer transformer = templates.newTransformer();
// Create a new DOM document
Document srcDoc = docBuilder.newDocument();
Element el = srcDoc.createElementNS("TESTURI", "TEST:actions");
srcDoc.appendChild(el);
el.setAttribute("xmlns:TEST", "TESTURI");
// create sources
DOMSource domSource = new DOMSource(srcDoc.getDocumentElement());
StreamSource textSource = new StreamSource(new
StringReader(xmlText));
// Transform it!
System.out.println("DOM SOURCE: ");
transformer.transform(domSource, new StreamResult(System.out));
System.out.println();
System.out.println("STREAM SOURCE: ");
transformer.transform(textSource, new StreamResult(System.out));
}
}
------- END SAMPLE CODE -------
------- START SAMPLE OUTPUT -------
DOM SOURCE:
<?xml version="1.0" encoding="UTF-8"?>
STREAM SOURCE:
<?xml version="1.0" encoding="UTF-8"?>
<MATCHED xmlns:xalan="http://xml.apache.org/xalan" xmlns:TEST="TESTURI"/>
------- END SAMPLE OUTPUT -------
As you can see, the stream source version matched, but the dom source
version did not.
However, both of them are using the same document.
(I know the "TEST:" prefix and the xmlns:TEST attributes on the DOM data are
superfluous, but I wanted to ensure it was using EXACTLY the same document
as the stream version)
Is this a bug? If so, I shall submit it to the bugtracking system.