How does Java Transformer use multiple xslt files

2019-07-25 02:34发布

I have one XSLT file including other two xml files to generate html page, like below

<xsl:include href="xsltcache://UtilityTemplates.xml" />
<xsl:include href="xsltcache://eCertSpecificTemplates.xml" />

I do not know how to add multiple xsl sources (three files in this case) to transformer,

Source xslSource = new StreamSource(xslFile);
Transformer trasformToXml=tFactory.newTransformer(xslSource);

标签: java xml xslt
1条回答
smile是对你的礼貌
2楼-- · 2019-07-25 03:06

You are using a very specialized form of URI in the xsl:include directives, these look as if they were designed to be handled by custom URI dereferencing logic, perhaps an OASIS catalog.

The bog-standard way to do this would be to use relative URIs in the xsl:include (for example <xsl:include href="UtilityTemplates.xsl"/>, to put all three files in the same directory, and then to make sure that the base URI of the main file is known (which it will be if xslFile is a File object).

If there's some special magic to the "xsltcache" URIs then you need to find out what it is. But if you don't want to change the source, you can set a URIResolver on the TransformerFactory. The URIResolver will be called when an xsl:include declaration is encountered, and it can do anything it likes to convert the supplied URI to a Source object containing the included module.

查看更多
登录 后发表回答