从 XSLT 调用 XQuery,在 XQuery 中动态构建 XSLT? [英] calling XQuery from XSLT, building XSLT dynamically in XQuery?

查看:66
本文介绍了从 XSLT 调用 XQuery,在 XQuery 中动态构建 XSLT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:eXist-db 4.2.1、XQuery 3.1、XSLT 2.0

Environment: eXist-db 4.2.1 , XQuery 3.1, XSLT 2.0

我需要使用 XQuery 在 eXist-DB 中执行 XSLT 转换.有一次,XSLT 需要在数百个文档中搜索节点属性值的匹配项.从 eXist-DB 中的 XSLT 调用 collection() 似乎不起作用 .

I am required to perform an XSLT transformation within eXist-DB using XQuery. At one point the XSLT needs to search across hundreds of documents for matches on a node attribute value. Calling collection() from XSLT in eXist-DB seems to not work .

我已经搜索了一些其他方法来解决这个问题,但没有找到任何东西,我在这里发布了两个问题:

I've done some searching on other ways to solve this problem, and having failed to find anything, I'm posting two questions here:

  1. 是否可以从 XQuery 动态编写和转换 XSLT,从而允许我从 XQuery 本身动态注入值(xquery transform:transform() 上的参数在这里不够用)

  1. Is is possible to dynamically write and transform XSLT from XQuery, thus allowing me to dynamically inject values from XQuery itself (parameters on xquery transform:transform() don't suffice here)

是否可以通过 XSLT 以任何方式调用/检索(eXist)XQuery 文档/函数的结果?

Is it possible to call/retrieve results from an (eXist) XQuery document/function from XSLT in any way?

感谢您的任何意见和参考.

Thanks for any opinions and references.

推荐答案

由于 XSLT 是 XML 并且使用 XQuery 您可以构建 XML,您当然可以动态构建 XSLT 并注入您在 XQuery 其他地方收集的数据,以下是显然很愚蠢的例子,但它在 XQuery 中构造了一些数据,动态创建了一个 XSLT 样式表,将其中的一些数据直接作为参数值内联注入,然后运行 ​​XSLT:

As XSLT is XML and with XQuery you can construct XML you can of course construct XSLT on the fly and inject data you gathered elsewhere in XQuery, the following is a silly example obviously but it constructs some data in XQuery, creates an XSLT stylesheet on the fly injecting some of that data directly inline as a parameter value and then runs the XSLT:

declare namespace xsl = "http://www.w3.org/1999/XSL/Transform";

let $elements := (1 to 3)!<root><data>{.}</data></root>,
    $stylesheet := 
      <xsl:stylesheet version="2.0">
        <xsl:param name="data-elements" as="element()*">{$elements!data}</xsl:param>
        <xsl:template match="@* | node()">
          <xsl:copy>
             <xsl:apply-templates select="@* | node()"/>
          </xsl:copy>
        </xsl:template>
        <xsl:template match="foo[. = $data-elements]"/>
      </xsl:stylesheet>,
    $input := <root><list><foo>a</foo><foo>2</foo><foo>10</foo><foo>1</foo></list></root>
return transform:transform($input, $stylesheet, ())

这篇关于从 XSLT 调用 XQuery,在 XQuery 中动态构建 XSLT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆