将绝对文件路径从java代码传递给xslt document() [英] Pass absolute file path from java code to xslt document()

查看:165
本文介绍了将绝对文件路径从java代码传递给xslt document()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的xslt中,我想查找一个xml文件。我需要从java代码传递这个文件的路径。我有以下内容:

In my xslt I'd like to look up an xml file. I need to pass the path to this file from java code.I have the followings:

...
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帖子传递参数的变体,但没有成功。

The problem is that I want to pass an absolute "base" path to the xsl, which I want to combine with the actual xml file name (myfile.xml). It seems to me that document considers file parameters relative to the location of the xsl. Furthermore I remarked that the parameter is not picked up from the java code. I use JABX with the default Xalan XSLT processor (1.0) I tried many variations of passing the parameters based on the other SO posts, but no success.

推荐答案

您需要使用完整的文件URL构造一个字符串: document(concat('file://',$ mypath,'/ myfile.xml') )

You need to construct a string then with the complete file URL: document(concat('file://', $mypath, '/myfile.xml')).

这篇关于将绝对文件路径从java代码传递给xslt document()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆