将绝对文件路径从 java 代码传递到 xslt document()

2023-12-14

在我的 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')).

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将绝对文件路径从 java 代码传递到 xslt document() 的相关文章

随机推荐