动态构建 XPath 查询字符串
我有一个链接的 XSLT 2.0 转换场景(使用 saxon),如下所示:
- I1.xml 是 T1.xslt 的输入,样式表将构建 T2.xslt
- I2.xml 是 T2.xslt 的输入,样式表将输出 O1.xml
我想要一个 xsl:function (以便它在 XPath 表达式中可用),让我们称之为 my:f( dataNode 、 queryString ),它将使用提供的查询来查询 dataNode,类似于以下内容:
<xsl:function name="my:f">
<xsl:param name="dataNode" as="item()*"/>
<xsl:param name="query" as="xsd:string"/>
<xsl:sequence select="$dataNode/$query"/>
</xsl:function>
my:f() 存储在单独的文件中,并且仅由 T2 包含。
my:f() 被隔离在文件中,因为根据配置,它可能会调用扩展函数来执行查询。
当然,my:f() 调用是在 T1 中“构建”的(其中 XPath 查询字符串是动态连接的),但实际上仅在 T2 中调用。
我似乎遇到的唯一问题是如何将动态构建的查询字符串从 T1 实际传递到 T2,然后作为简单字符串传递到 my:f() (因为实际查询将由 my:f() 执行) 。
有人对如何解决这个问题有任何想法(最好是一些代码)吗?
问候
I have a chained XSLT 2.0 transformation scenario (using saxon), like this:
- I1.xml is input for T1.xslt, stylesheet which will build T2.xslt
- I2.xml is input for T2.xslt, stylesheet which will output O1.xml
I would like to have an xsl:function (so that it will be available in XPath expressions), let's call it my:f( dataNode, queryString ), which will query dataNode using the supplied query, similar with below:
<xsl:function name="my:f">
<xsl:param name="dataNode" as="item()*"/>
<xsl:param name="query" as="xsd:string"/>
<xsl:sequence select="$dataNode/$query"/>
</xsl:function>
my:f() is stored in a separate file and included only by T2.
my:f() is isolated in a file because depending on configuration, it might call an extension function for performing the query.
my:f() call is, of course, "build" in T1 ( where the XPath queryString is dynamically concatenated ), but it is actually called only in T2.
The only problem that I seem to have .. is how to actually pass the dynamically build queryString from T1 to T2 and then to my:f() as a simple string (as the actual query will be performed by my:f()).
Does anyone have any ideas (and ideally some code) about how to approach this?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想在运行时构建和评估 XPath 表达式,那么您需要使用扩展函数,例如 http://www.saxonica.com/documentation/extensions/functions/evaluate.xml:
Well if you want to construct and evaluate XPath expressions at run-time then you need to use an extension function like http://www.saxonica.com/documentation/extensions/functions/evaluate.xml:
<xsl:sequence select="saxon:evaluate(concat('$p1/', $query), $dataNode)"/>