在我的 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 帖子传递参数的变体,但没有成功。
最佳答案
您需要使用完整的文件 URL 构造一个字符串:document(concat('file://', $mypath, '/myfile.xml'))
。
关于java - 将绝对文件路径从 java 代码传递到 xslt document(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30153433/