【问题标题】:calling XQuery from XSLT, building XSLT dynamically in XQuery?从 XSLT 调用 XQuery,在 XQuery 中动态构建 XSLT?
【发布时间】:2018-10-23 11:06:32
【问题描述】:

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

我需要使用 XQuery 在 eXist-DB 中执行 XSLT 转换。在某一时刻,XSLT 需要在数百个文档中搜索节点属性值的匹配项。在 eXist-DB seems to not work 中从 XSLT 调用 collection()

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

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

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

感谢任何意见和参考。

【问题讨论】:

    标签: xslt xquery saxon exist-db


    【解决方案1】:

    由于 XSLT 是 XML,而使用 XQuery,您可以构建 XML,您当然可以即时构建 XSLT 并将您在 XQuery 中其他地方收集的数据注入,以下显然是一个愚蠢的示例,但它在 XQuery 中构建了一些数据,创建了一个 XSLT动态样式表直接内联注入一些数据作为参数值,然后运行 ​​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, ())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多