哪些工具链支持将节点集作为参数传递给 XSLT 转换?

发布于 2024-08-07 17:35:41 字数 640 浏览 2 评论 0原文

这是 上一个问题 我有关于 XSLT 的问题。

回顾一下,我没有意识到如果没有 EXSLT,XSLT 将无法让您动态创建具有字符串值的 xpath 表达式。建议的解决方法之一是

在执行转换之前查询输入文档的 DOM,并将节点集传递到转换中

我使用 Apache Ant 进行转换,并且按照 有关 xslt/style 任务参数的手册

要放入参数中的文本值。最初旨在成为 XSL 表达式。

听起来 Apache Ant 不支持这个。但这让我想知道,这种语义在支持此功能的系统中如何工作?

那么,哪些工具链或系统支持将节点集作为参数从源文档传递到转换中。示例代码的奖励积分。

This is a followup to an answer on a previous question I had about XSLT.

To recap, I didn't realize that without EXSLT, XSLT wouldn't let you dynamically create an xpath expression with string values. One of the suggested workarounds was

to query the input document's DOM before you execute the transform, and pass the node-set into the transform

I was using Apache Ant to do the transformation, and per the manual on the xslt/style task's parameters

Text value to be placed into the parameter. Was originally intended to be an XSL expression.

it sounds like Apache Ant doesn't support this. It got me wondering though, how would this semantics of this work in a system that did support this?

So, what Toolchains or systems support passing a nodeset from the source document into a transformation as a parameter. Bonus points for example code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新雨望断虹 2024-08-14 17:35:41

您无法在标准 xslt 1.0 中将节点集作为参数传递。
为此,您必须使用 xslt 2.0 解析器。

例如:
http://wiki.apache.org/ant/UsingAntWithXSLT20AndSaxon

You can't pass a nodeset as a parameter in standard xslt 1.0.
To do that you must use an xslt 2.0 parser.

For instance:
http://wiki.apache.org/ant/UsingAntWithXSLT20AndSaxon

枕梦 2024-08-14 17:35:41

我不完全确定我的答案,因为我似乎无法正确理解您的问题,但根据您引用的线程和您的引用,我可以提出以下建议:

build.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project name="Test XSLT" default="test-xslt" basedir=".">
    <target name="test-xslt">
        <xslt in="test.xml" style="ant-with-param.xsl" out="ant-with-param-out.xml">
            <param name="param-set-id" expression="2"/>
        </xslt>
    </target>
</project>

< strong>test.xml:

<?xml version="1.0" encoding="UTF-8"?>

<params>
    <set id="1">
        <param name="name" value="Name from the first set"/>
    </set>
    <set id="2">
        <param name="name" value="Name from the second set"/>
    </set>
</params>

ant-with-param.xsl:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:exsl="http://exslt.org/common"
                extension-element-prefixes="exsl">
    <xsl:param name="param-set-id"/>
    <xsl:variable name="param-set" select="//params/set[@id = $param-set-id]"/>

    <xsl:template match="/">
        <name>
            <xsl:value-of select="exsl:node-set($param-set)//param[@name = 'name']/@value"/>
        </name>
    </xsl:template>
</xsl:stylesheet>

输出

<?xml version="1.0" encoding="UTF-8"?>
<name>Name from the second set</name>

给定样式表根据传递的变量值从输入文档中获取参数来自构建文件。参数是借助 XPath 表达式从源文档中获取的,并在以后借助 exsl:node-set() 扩展函数使用。默认情况下,ant 使用 Xalan 作为 xslt 处理器。其扩展的完整列表可以在项目主页中找到。

I'm not completely sure about my answer because it seems that I cannot understand your question properly but basing on the thread you reference and your quotes I can come up with the following suggestion:

build.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project name="Test XSLT" default="test-xslt" basedir=".">
    <target name="test-xslt">
        <xslt in="test.xml" style="ant-with-param.xsl" out="ant-with-param-out.xml">
            <param name="param-set-id" expression="2"/>
        </xslt>
    </target>
</project>

test.xml:

<?xml version="1.0" encoding="UTF-8"?>

<params>
    <set id="1">
        <param name="name" value="Name from the first set"/>
    </set>
    <set id="2">
        <param name="name" value="Name from the second set"/>
    </set>
</params>

ant-with-param.xsl:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:exsl="http://exslt.org/common"
                extension-element-prefixes="exsl">
    <xsl:param name="param-set-id"/>
    <xsl:variable name="param-set" select="//params/set[@id = $param-set-id]"/>

    <xsl:template match="/">
        <name>
            <xsl:value-of select="exsl:node-set($param-set)//param[@name = 'name']/@value"/>
        </name>
    </xsl:template>
</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?>
<name>Name from the second set</name>

Given stylesheet fetches parameters from the input document basing on the value of the variable passed from the build-file. Parameters are fetched with the help of the XPath expression from the source document and used later with the help of the exsl:node-set() extension function. By default ant uses Xalan as an xslt processor. Full list of its extensions can be found at the project's home page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文