有没有办法在 XSLT 脚本文件中本地运行 XQuery 函数/或 XQuery 脚本?

问题描述 投票:0回答:1

我在堆栈溢出中提出的上一个问题是关于如何在 XSLT 中成功使用 load-query-module 来运行 XQuery,但是运行时必须能够知道如何使用位置提示来找到 XQuery 模块来加载它。

如果我假设我的 SAP Platform 运行时不支持此功能,那么我需要另一种方法在 XSLT 中运行 XQuery。是否可以将 XQuery 作为参数传递,然后在 XSLT 中运行它,或者 XSLT 是否可以引用 XSLT 的另一部分,该部分将 XQuery 嵌入到脚本文件中的其他位置?

xslt xquery
1个回答
0
投票

这是 Saxon 12 (PE/EE) 的示例,使用 https://www.saxonica.com/html/documentation12/functions/saxon/xquery.html:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:saxon="http://saxon.sf.net/"
  exclude-result-prefixes="#all">

  <xsl:param name="xquery-param1" as="xs:string" expand-text="no"><![CDATA[
  declare variable $x external; declare variable $y external; <z>{$x + $y + .}</z>
  ]]></xsl:param>

  <xsl:output indent="yes"/>

  <xsl:template match="/" name="xsl:initial-template">
    <result>
      <xsl:variable name="xquery1" select="saxon:xquery($xquery-param1)"/>
      <xsl:sequence select="$xquery1(4, map{xs:QName('x'): 3, xs:QName('y'): 2})"/>
    </result>
  </xsl:template>

</xsl:stylesheet>
© www.soinside.com 2019 - 2024. All rights reserved.