You can also control these output properties from inside your
Java programs using these four methods in the
Transformer
class.:
public abstract void setOutputProperties(Properties
outputFormat)
throws IllegalArgumentException;
public abstract Properties getOutputProperties();
public abstract void setOutputProperty(String name, String value)
throws IllegalArgumentException;public abstract String getOutputProperty(String name);
The keys and values for these properties are simply the string names established by the XSLT 1.0 specification.
The
javax.xml.transform.OutputKeys
class
provides
named constants for all the property names:
package javax.xml.transform; public class OutputKeys { private OutputKeys() {} public static final String METHOD = "method"; public static final String VERSION = "version"; public static final String ENCODING = "encoding"; public static final String OMIT_XML_DECLARATION = "omit-xml-declaration"; public static final String STANDALONE = "standalone"; public static final String DOCTYPE_PUBLIC = "doctype-public"; public static final String DOCTYPE_SYSTEM = "doctype-system"; public static final String CDATA_SECTION_ELEMENTS = "cdata-section-elements"; public static final String INDENT = "indent"; public static final String MEDIA_TYPE = "media-type"; }
For example:
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-16"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml"); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
In the event of a conflict between what the Java code
requests with output properties
requests and what the stylesheet requests with an
xsl:output
element, the ones specified
in the Java code take precedence.