xml - 如何使用 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>
但它没有用。有人能说怎么做吗?
解决方案
对于 XSLT,要使用外部参数,您需要在顶层声明它们,即作为xsl:stylesheet
or的子级xsl:transform
: <xsl:param name="path"/>
。
推荐阅读
- java - 如何通过 Spring Boot 访问需要 OAuth2 的外部 URL?
- python - 如何使用 python 的 elasticsearch 库自动生成索引名称?
- jsf - JSF 复合组件递归中的 StackOverflowError
- node.js - React 部署/运行选项
- javascript - Reactjs - 在组件中导入 CSS/JS
- php - 用于函数驱动应用程序的 PHP DI 模式
- swift - 如何在 NSPredicate 的帮助下使用自定义对象数组实现搜索?
- react-native - 在原生基地的甲板刷卡器中是否可以缩放图像
- java - 如何从 Firebase 数据库中检索附加值
- tfs - TFS 2017 Web 访问 - 如何将保存的查询添加到工作菜单?