-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b58
-
x86
-
linux_redhat_9.0
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2118730 | 5.0 | Arun Yadav | P3 | Resolved | Fixed | rc |
It seems that Tiger builds do not honor the {http://xml.apache.org/xslt}indent-amount attribute on <{http://www.w3.org/1999/XSL/Transform}output> when using method="xml" indent="yes".
Consider the following program:
---%<---
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class Main {
private static final String XSL =
"<xsl:stylesheet version='1.0' " +
"xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " +
"xmlns:xalan='http://xml.apache.org/xslt' " +
"exclude-result-prefixes='xalan'>" +
"<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" +
"<xsl:template match='/'>" +
"<outer><inner/></outer>" +
"</xsl:template>" +
"</xsl:stylesheet>";
private static final String XML = "<irrelevant/>";
public static void main(String[] args) throws Exception {
TransformerFactory fact = TransformerFactory.newInstance();
Transformer t = fact.newTransformer(new StreamSource(new StringReader(XSL)));
t.transform(new StreamSource(new StringReader(XML)), new StreamResult(System.out));
}
}
---%<---
and its output under JDK 1.4.2_04 and JDK 1.5.0 b55:
---%<---
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b02)
Java HotSpot(TM) Client VM (build 1.4.2_04-b02, mixed mode)
<?xml version="1.0" encoding="UTF-8"?>
<outer>
<inner/>
</outer>
---%<---
---%<---
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b55)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b55, mixed mode, sharing)
<?xml version="1.0" encoding="UTF-8"?>
<outer>
<inner/>
</outer>
---%<---
The element <inner/> is no longer indented four spaces as was requested.
The attribute in question is of course not guaranteed by the JAXP or XSLT specifications, but it is permitted for the implementation to recognize it; and it is extremely useful when attempting to produce readable, structured XML output from XSLT, especially for long documents.
The attribute is supposed to be supported by the Xalan processor, according to
http://xml.apache.org/xalan-j/usagepatterns.html#outputprops
and as far as I am aware it is, when using Xalan as downloaded from xml.apache.org.
Perhaps just the XSLTC engine fails to support it and this is the reason for the functional regression in Tiger.
Whatever the cause, it seems that this should be very easy to fix; XML indentation is hardly a complex algorithm. I might even suggest turning on some nonzero indentation by default (only if the XSLT standard indent="yes" attribute is given, of course), since if you want line breaking you probably also want some indentation to make the output file more readable to a human.
For reference, the XSLT spec
http://www.w3.org/TR/xslt#section-XML-Output-Method
says
"If the indent attribute has the value yes, then the xml output method may output whitespace in addition to the whitespace in the result tree (possibly based on whitespace stripped from either the source document or the stylesheet) in order to indent the result nicely [...]"
The term "indent" is not defined, since the exact behavior is up to the implementation, but it is reasonable to assume that insertion of both line breaks and tab-like indentation within a line are desirable, since this is the style most often used for presentable XML.
If the user has switched to a different XSLT engine than is the default in JAXP, and it is not based on Xalan, of course this attribute should be quietly ignored as it is a hint.
###@###.### 2004-06-16
###@###.### 2004-06-22
Consider the following program:
---%<---
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class Main {
private static final String XSL =
"<xsl:stylesheet version='1.0' " +
"xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " +
"xmlns:xalan='http://xml.apache.org/xslt' " +
"exclude-result-prefixes='xalan'>" +
"<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" +
"<xsl:template match='/'>" +
"<outer><inner/></outer>" +
"</xsl:template>" +
"</xsl:stylesheet>";
private static final String XML = "<irrelevant/>";
public static void main(String[] args) throws Exception {
TransformerFactory fact = TransformerFactory.newInstance();
Transformer t = fact.newTransformer(new StreamSource(new StringReader(XSL)));
t.transform(new StreamSource(new StringReader(XML)), new StreamResult(System.out));
}
}
---%<---
and its output under JDK 1.4.2_04 and JDK 1.5.0 b55:
---%<---
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b02)
Java HotSpot(TM) Client VM (build 1.4.2_04-b02, mixed mode)
<?xml version="1.0" encoding="UTF-8"?>
<outer>
<inner/>
</outer>
---%<---
---%<---
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b55)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b55, mixed mode, sharing)
<?xml version="1.0" encoding="UTF-8"?>
<outer>
<inner/>
</outer>
---%<---
The element <inner/> is no longer indented four spaces as was requested.
The attribute in question is of course not guaranteed by the JAXP or XSLT specifications, but it is permitted for the implementation to recognize it; and it is extremely useful when attempting to produce readable, structured XML output from XSLT, especially for long documents.
The attribute is supposed to be supported by the Xalan processor, according to
http://xml.apache.org/xalan-j/usagepatterns.html#outputprops
and as far as I am aware it is, when using Xalan as downloaded from xml.apache.org.
Perhaps just the XSLTC engine fails to support it and this is the reason for the functional regression in Tiger.
Whatever the cause, it seems that this should be very easy to fix; XML indentation is hardly a complex algorithm. I might even suggest turning on some nonzero indentation by default (only if the XSLT standard indent="yes" attribute is given, of course), since if you want line breaking you probably also want some indentation to make the output file more readable to a human.
For reference, the XSLT spec
http://www.w3.org/TR/xslt#section-XML-Output-Method
says
"If the indent attribute has the value yes, then the xml output method may output whitespace in addition to the whitespace in the result tree (possibly based on whitespace stripped from either the source document or the stylesheet) in order to indent the result nicely [...]"
The term "indent" is not defined, since the exact behavior is up to the implementation, but it is reasonable to assume that insertion of both line breaks and tab-like indentation within a line are desirable, since this is the style most often used for presentable XML.
If the user has switched to a different XSLT engine than is the default in JAXP, and it is not based on Xalan, of course this attribute should be quietly ignored as it is a hint.
###@###.### 2004-06-16
###@###.### 2004-06-22
- backported by
-
JDK-2118730 XSLT output type XML does not honor {http://xml.apache.org/xslt}indent-amount in
-
- Resolved
-
- relates to
-
JDK-7150637 No newline emitted after XML decl in XSLT output
-
- Closed
-