You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在XPath中直接调用带模式的XSLT模板?XSLT3.0技术问询

关于XSLT 3.0实现动态模板调用的问题

为了精简代码,我更倾向于使用XPath而非XSLT,但目前只能通过编写适配器函数封装模板匹配来实现,示例代码如下:

<xsl:function name="mgx:iso" as="xs:string*">
    <xsl:param name="espTimeInstants" as="element(ESP_TIMEINSTANT)*"/>
    <xsl:param name="time" as="xs:string"/>
    <xsl:apply-templates mode="iso" select="$espTimeInstants">
       <xsl:with-param name="time" select="$time"/>
    </xsl:apply-templates>
</xsl:function>

<xsl:template mode="iso" match="ESP_TIMEINSTANT">
    <xsl:param name="time" as="xs:string"/>
    <xsl:sequence select="@date || 'T' || $time"/>
</xsl:template>

这样在调用代码中无需显式调用apply-templates,只需使用:

<xsl:sequence select="string-join(mgx:iso($elements,'00:00:12'))"/>

我期望能直接调用模板,比如自定义apply-templates函数的形式:

<xsl:sequence select="string-join(apply-templates('iso',$elements,('00:00:12')))"/>

无需编写上述适配器函数。尝试自行实现该函数时:

<xsl:function name="kooks:apply-templates">
   <xsl:param name="mode" as="xs:string"/>
   <xsl:param name="select" as="item()*"/>
   <xsl:param name="parameters" as="item()*"/>
   <xsl:apply-templates mode="$mode" select="$select">
      <xsl:with-param = ..eeeek.../>
   </xsl:apply-templates>
</xsl:function>

可通过约定使用map类型的params参数规避参数问题,但无法动态指定模板模式。我了解XSLT1.0的相关实现方法,但复杂度与当前方案相当且更晦涩,想确认XSLT3.0是否支持直接实现该需求?

内容的提问来源于stack exchange,提问作者MrD at KookerellaLtd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 07:19:56