I want to allow the transformer to set a param in my stylesheet to specify how many spaces of indentation are desired. I have tried all of the suggestions by @Dimitre Novatchev
As @Mads Hansen already said it does not appear that Xalan supports attribute value templates for the value of the xalan:indent-amount
attribute.
I found that setting the property on the transformer itself does work though. The nice thing about this is that I don't have to create/modify any files.
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
Credit goes to @Flynn1179
It does not appear that Xalan supports attribute value templates for the value of the xalan:indent-amount
attribute.
I get a warning message that attribute value templates are not supported in xsl:output in XSLT 1.0. Apparently, they are supported in 1.1 (which should not be used, as it was abandoned by the W3C), but Xalan does not appear to resolve the parameter value in the AVT in that particular attribute.
When I attempt to use the parameter value in an AVT, it returns the error:
E For input string "{$indent}"
One possible workaround would be to use entities and generate a DTD. Rather than pass in the indent value as a param, have your XSLT reference a DTD. Generate the DTD file with the indent value that you need and then invoke the XSLT.
For example, create a DTD file like this (assume named "indent.dtd"):
<!ENTITY indent "10" >
And then reference the DTD in your XSLT like this (assume that indent.dtd is located in the same folder, or you could adjust the path):
<!DOCTYPE xsl:stylesheet SYSTEM "indent.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"
xalan:indent-amount="&indent;"/>
</xsl:stylesheet>
Another workaround would be to generate an XSLT with the desired value for the xalan:indent-amount
first, and then transform your XML with the newly generated XSLT.