Reputation: 20270
I am using Saxon-B 9.1.0.8 and XSL 2.0.
I have a XSL stylesheet, in which there is an xsl:param
element:
<xsl:param name="lang"/>
And I am using the following code to do the transformation of my document:
try {
Source xmlSource = new StreamSource(new File(xmlFilename));
Source xsltSource = new StreamSource(new File(xslFilename));
// create the transformer
Processor processor = new Processor(false);
XsltCompiler xsltCompiler = processor.newXsltCompiler();
XsltExecutable xslt = xsltCompiler.compile(xsltSource);
XsltTransformer xsltTransformer = xslt.load();
xsltTransformer.setSource(xmlSource);
// configure output
StringWriter sw = new StringWriter();
Serializer serializer = new Serializer();
serializer.setOutputWriter(sw);
serializer.setOutputProperty(Serializer.Property.INDENT, "yes");
xsltTransformer.setDestination(serializer);
// do it!
xsltTransformer.transform();
} catch (SaxonApiException e) {
logger.error(e.getMessage(), e);
}
How should a value for this parameter be passed to the transformer?
Upvotes: 2
Views: 411
Reputation: 20270
Saxon uses the QName
and XdmAtomicValue
classes to pass in parameters:
QName langParam = new QName("lang");
xsltTransformer.setParameter(langParam, new XdmAtomicValue("default"));
Upvotes: 1