0

XSLT paramsを使用して、実行時に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文字列を渡す必要があります。また、コマンドラインシェルが邪魔にならないように二重引用符を付ける必要がある場合もあります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 に答える