首页 > 解决方案 > 如何使用 maven-xml-plugin 传递 XSLT 参数?

问题描述

这是我的 xslt 2.0 文件的一部分:

<xsl:template match="test-one">
        <xsl:apply-templates select="document('../test.xml')//class"/>
</xsl:template>

正如所见,路径../test.xml是硬编码的。现在我想使用 xml-maven-plugin 将路径作为参数传递。所以我这样做:

<transformationSet>
    <dir>src/test/resources</dir>
    <includes>foo.xml</includes>
    <stylesheet>xslfile.xsl</stylesheet>
    <parameters>
        <parameter>
          <name>path</name>
          <value>../test.xml</value>
        </parameter>
    </parameters>
    <outputDir>${project.build.directory}/test-classes/META-INF</outputDir>
</transformationSet>

但是,我不明白如何将此路径添加到 xslt 文件。我试过:

<xsl:template match="test-one">
        <xsl:apply-templates select="document('$path')//class"/>
</xsl:template>

但它没有用。有人能说怎么做吗?

标签: xmlxsltxslt-2.0maven-plugin

解决方案


对于 XSLT,要使用外部参数,您需要在顶层声明它们,即作为xsl:stylesheetor的子级xsl:transform: <xsl:param name="path"/>


推荐阅读