【发布时间】:2015-05-10 15:55:07
【问题描述】:
在我的 xslt 中,我想查找一个 xml 文件。我需要从java代码传递这个文件的路径。我有以下内容:
...
Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
transformer.setParameter("mypath", "/home/user/repository");
xslt:
<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="mypath"/>
...
<xsl:template match="connection[@id]">
<xsl:variable name="lookupStore" select="document('$mypath/myfile.xml')/connections"/>
<xsl:copy>
<xsl:apply-templates select="$lookupStore">
<xsl:with-param name="current" select="."/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
...
<xsl:transform>
问题是我想将绝对“基本”路径传递给 xsl,我想将它与实际的 xml 文件名 (myfile.xml) 结合起来。在我看来,document 考虑了相对于 xsl 位置的文件参数。
此外,我注意到该参数不是从 java 代码中提取的。我将 JABX 与默认的 Xalan XSLT 处理器 (1.0) 一起使用
我尝试了许多基于其他 SO 帖子传递参数的变体,但没有成功。
【问题讨论】:
-
您是否尝试过实现
resolver?应该可以以编程方式提供myfile.xml的内容。 -
我试过了。但问题是我想要特定于 xsl 的名称“myfile.xml”,并且我不想创建 myfile.xml 的文档对象并将其传递给 xslt。
标签: java xml xslt jaxb xslt-1.0