JDK-5064280 : XSLT output type XML does not honor {http://xml.apache.org/xslt}indent-amount in
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.transform
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux_redhat_9.0
  • CPU: x86
  • Submitted: 2004-06-16
  • Updated: 2012-04-25
  • Resolved: 2004-07-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
5.0 b58Fixed
Related Reports
Relates :  
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>" +
    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

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-rc FIXED IN: tiger-rc INTEGRATED IN: tiger-b58 tiger-rc

EVALUATION Committed the patch on main-branch of internal code-base. XSLTC supports both the old namespace URI {http://xml.apache.org/xslt} and new namespace URI{http://xml.apache.org/xalan} for indent-amount. ###@###.### 2004-06-22

SUGGESTED FIX Restore behavior of JDK 1.4.2. ###@###.### 2004-06-16

WORK AROUND 1. Use a custom copy of Xalan, or some other XSLT processor that does indentation, registering it to JAXP. 2. Use indent="no" and explicitly include all desired whitespace in the stylesheet and/or input document. 3. Send to a SAX or DOM source and pipe that into a pretty-printer. ###@###.### 2004-06-16 ###@###.### 2004-06-22