0

我正在使用 XSLT 参数在运行时使用 Xalan-C 在属性中设置绝对路径。基本上,我的输入 XML 是这样的:-

<root xmlns="initial">
  <!-- document goes here -->
</root>

我的样式表是:-

<xsl:stylesheet version="1.0" xmlns:s="initial" xmlns="final" />

  <xsl:param name="default_data_location">/path/to/some/location</xsl:param>

  <xsl:template match="//s:*">
    <xsl:element name="{local-name()}" namespace="final">
      <xsl:attribute name="dataLocation">
        <xsl:value-of select="concat($default_data_location, '/datafile')"/>
      </xsl:attribute>
    </xsl:element>
  </xsl:template>

  <!-- rest of the stylesheet -->

</xsl:stylesheet>

因此,当我运行它时,我想要的输出 XML 为:-

Xalan foo.xml foo.xsl 

应该是(这是有效的部分):-

<root xmlns="final" dataLocation="/path/to/some/location/datafile">
  <!-- document goes here -->
</root>

当我运行它时: -

Xalan -p default_data_location /some/other/path foo.xml foo.xsl

它应该是(这是不起作用的部分):-

<root xmlns="final" dataLocation="/some/other/path/datafile">
  <!-- document goes here -->
</root>

但是,如果我尝试在命令行中设置此参数,它会给我以下 XML:-

<root xmlns="final" dataLocation="/datafile">
  <!-- document goes here -->
</root>

我应该做什么?

4

1 回答 1

1

参数值似乎是一个 XPath 表达式,因此您需要确保传入一个 XPath 字符串,并且您可能需要双引号以确保命令行 shell 不会进入您的方式,因此这样做Xalan -p default_data_location "'/some/other/path'" foo.xml foo.xsl应该可以工作。至少这是我在http://xml.apache.org/xalan-c/commandline.html上阅读的文档,我没有要测试的 Xalan-C。

于 2012-10-01T17:50:04.623 回答