如何使用 maven-xml-plugin 传递 XSLT 参数?

How to pass XSLT parameter with maven-xml-plugin?

这是我的 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>

但是没有用。谁能说说怎么做?

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