in src/main/java/org/apache/log4j/xml/XSLTLayout.java [403:457]
public void setTransform(final Document xsltdoc)
throws TransformerConfigurationException {
//
// scan transform source for xsl:output elements
// and extract encoding, media (mime) type and output method
//
String encodingName = null;
mediaType = null;
String method = null;
NodeList nodes = xsltdoc.getElementsByTagNameNS(
XSLT_NS,
"output");
for(int i = 0; i < nodes.getLength(); i++) {
Element outputElement = (Element) nodes.item(i);
if (method == null || method.length() == 0) {
method = outputElement.getAttributeNS(null, "method");
}
if (encodingName == null || encodingName.length() == 0) {
encodingName = outputElement.getAttributeNS(null, "encoding");
}
if (mediaType == null || mediaType.length() == 0) {
mediaType = outputElement.getAttributeNS(null, "media-type");
}
}
if (mediaType == null || mediaType.length() == 0) {
if ("html".equals(method)) {
mediaType = "text/html";
} else if ("xml".equals(method)) {
mediaType = "text/xml";
} else {
mediaType = "text/plain";
}
}
//
// if encoding was not specified,
// add xsl:output encoding=US-ASCII to XSLT source
//
if (encodingName == null || encodingName.length() == 0) {
Element transformElement = xsltdoc.getDocumentElement();
Element outputElement = xsltdoc.
createElementNS(XSLT_NS, "output");
outputElement.setAttributeNS(null, "encoding", "US-ASCII");
transformElement.insertBefore(outputElement, transformElement.getFirstChild());
encoding = Charset.forName("US-ASCII");
} else {
encoding = Charset.forName(encodingName);
}
DOMSource transformSource = new DOMSource(xsltdoc);
templates = transformerFactory.newTemplates(transformSource);
}