-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.2.3
-
sparc
-
solaris_8
The Xalan processor, when used with schema and namespaces (see examples below),
is emitting the xml namespace information 'xmlns:foo="http://foo"' in the
top level <html> tag of the result of a transformation even though the stylesheet is explicitly setting <xsl:output method="html"/>. Interestingly,
the Xsltc processor does not do this, however when we pull in Xalan 2.5 which
integrates the serializers for both xalan and xsltc, then this bug may be seen
in xsltc processor as well.
I have supplied a standalone jaxp program, xml doc, xml schema, and xsl stylesheet to allow developers to reproduce the problem themselves. Here is my
output :
Using xalan as the xslt processor:
% java -cp "." BUG BUG.xml BUG.xsl
<html xmlns:foo="http://foo">My Book Title</html>
Using xsltc as the xslt processor:
java -Djavax.xml.transform.TransformerFactory=org.apache.xalan.xsltc.trax.TransformerFactoryImpl -cp "." BUG BUG.xml BUG.xsl
<html>My Book Title</html>
-------------------------------------------------------
Here is the xml doc: BUG.xml
<?xml version="1.0"?>
<book xmlns="http://foo"
xsi:schemaLocation="http://foo test.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<title>My Book Title</title>
<chapter>One</chapter>
<chapter>Two</chapter>
</book>
Here is the schema 'test.xsd'
<?xml version="1.0" ?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://foo"
xmlns:foo="http://foo"
elementFormDefault="qualified"
attributeFormDefault="qualified"
>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"
minOccurs="0" maxOccurs="1"/>
<xs:element name="chapter" type="xs:string"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Here is the xsl stylesheet, 'BUG.xsl'
<xsl:transform
xmlns:foo="http://foo"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="foo:book">
<html>
<xsl:value-of select="foo:title"/>
</html>
</xsl:template>
</xsl:transform>
Here is the jaxp program to reproduce the problem: BUG.java
import java.io.FileReader;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class BUG {
public static void main(String[] args) throws Exception {
String xmldoc = null;
String xsl = null;
if (args.length == 2) {
xmldoc = args[0];
xsl = args[1];
}
else {
System.err.println("Usage: MySAXApp2 <xml> <xsl>");
System.exit(1);
}
SAXParserFactory fact = SAXParserFactory.newInstance();
fact.setNamespaceAware(true);
fact.setValidating(true);
fact.setFeature("http://xml.org/sax/features/validation", true);
fact.setFeature(
"http://apache.org/xml/features/validation/schema", true);
SAXParser parser = fact.newSAXParser();
XMLReader reader = parser.getXMLReader();
TransformerFactory tfactory = TransformerFactory.newInstance();
TransformerHandler thandler =
((SAXTransformerFactory)tfactory).newTransformerHandler(
new StreamSource(xsl));
thandler.setResult(new StreamResult(System.out));
FileReader r = new FileReader(xmldoc);
reader.setContentHandler(thandler);
reader.parse(new InputSource(r));
System.exit(0);
}
}
is emitting the xml namespace information 'xmlns:foo="http://foo"' in the
top level <html> tag of the result of a transformation even though the stylesheet is explicitly setting <xsl:output method="html"/>. Interestingly,
the Xsltc processor does not do this, however when we pull in Xalan 2.5 which
integrates the serializers for both xalan and xsltc, then this bug may be seen
in xsltc processor as well.
I have supplied a standalone jaxp program, xml doc, xml schema, and xsl stylesheet to allow developers to reproduce the problem themselves. Here is my
output :
Using xalan as the xslt processor:
% java -cp "." BUG BUG.xml BUG.xsl
<html xmlns:foo="http://foo">My Book Title</html>
Using xsltc as the xslt processor:
java -Djavax.xml.transform.TransformerFactory=org.apache.xalan.xsltc.trax.TransformerFactoryImpl -cp "." BUG BUG.xml BUG.xsl
<html>My Book Title</html>
-------------------------------------------------------
Here is the xml doc: BUG.xml
<?xml version="1.0"?>
<book xmlns="http://foo"
xsi:schemaLocation="http://foo test.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<title>My Book Title</title>
<chapter>One</chapter>
<chapter>Two</chapter>
</book>
Here is the schema 'test.xsd'
<?xml version="1.0" ?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://foo"
xmlns:foo="http://foo"
elementFormDefault="qualified"
attributeFormDefault="qualified"
>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"
minOccurs="0" maxOccurs="1"/>
<xs:element name="chapter" type="xs:string"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Here is the xsl stylesheet, 'BUG.xsl'
<xsl:transform
xmlns:foo="http://foo"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="foo:book">
<html>
<xsl:value-of select="foo:title"/>
</html>
</xsl:template>
</xsl:transform>
Here is the jaxp program to reproduce the problem: BUG.java
import java.io.FileReader;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class BUG {
public static void main(String[] args) throws Exception {
String xmldoc = null;
String xsl = null;
if (args.length == 2) {
xmldoc = args[0];
xsl = args[1];
}
else {
System.err.println("Usage: MySAXApp2 <xml> <xsl>");
System.exit(1);
}
SAXParserFactory fact = SAXParserFactory.newInstance();
fact.setNamespaceAware(true);
fact.setValidating(true);
fact.setFeature("http://xml.org/sax/features/validation", true);
fact.setFeature(
"http://apache.org/xml/features/validation/schema", true);
SAXParser parser = fact.newSAXParser();
XMLReader reader = parser.getXMLReader();
TransformerFactory tfactory = TransformerFactory.newInstance();
TransformerHandler thandler =
((SAXTransformerFactory)tfactory).newTransformerHandler(
new StreamSource(xsl));
thandler.setResult(new StreamResult(System.out));
FileReader r = new FileReader(xmldoc);
reader.setContentHandler(thandler);
reader.parse(new InputSource(r));
System.exit(0);
}
}