Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5064280

XSLT output type XML does not honor {http://xml.apache.org/xslt}indent-amount in



    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 5.0
    • Component/s: xml



        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&#39; " +
                    "xmlns:xalan='http://xml.apache.org/xslt&#39; " +
                    "exclude-result-prefixes='xalan'>" +
                "<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" +
                "<xsl:template match='/'>" +
                "<outer><inner/></outer>" +
                "</xsl:template>" +
            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"?>

        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"?>

        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


        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



        "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


            Issue Links



                ayadavsunw Arun Yadav (Inactive)
                jglick Jesse Glick (Inactive)
                0 Vote for this issue
                0 Start watching this issue