Saxon 9.2 / Java / XSLT: setting transformer parameters using setParameters()

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 15:33:59

问题


I have the following XSLT 2.0 template:

<xsl:template name="t1">
<xsl:variable name="totalpos" as="xsd:double" select="$currentTotal"/>
..  

I am struggling to programmatticaly provide currentTotal as a parameter to the transformer, like this:

transformer.setParameter("currentTotal", new Double("100"))

.. but without any positive results:

Error at /xsl:transform/xsl:template[3]/xsl:variable[1] XPST0008: XPath syntax error at char 13 on line -1 in {$currentTotal}: Variable $currentTotal has not been declared

When calling setParameter(), the currentTotal variable will also get defined, right? How should I invoke the setParameter() call so that the currentTotal defined in my application will be seen inside the style-sheet?

For clarification, I am instantiating the transformer like this:

System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
transformerFactory = new TransformerFactoryImpl();
transformer = transformerFactory.newTransformer(inputNodes);

回答1:


Parameters have to be declared in your stylesheet using

<xsl:param name="currentTotal"/>

inside the xsl:stylesheet element. You can also define a default value with the select attribute or inside the element body.



来源:https://stackoverflow.com/questions/3434644/saxon-9-2-java-xslt-setting-transformer-parameters-using-setparameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!