XSLT 调用模板名称属性 [英] XSLT Call-Template name attribute

查看:25
本文介绍了XSLT 调用模板名称属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像我不能在 call-template 元素的 name 属性中使用 Xpath.我怎样才能解决这个问题?任何帮助/想法都会很棒!

It seems as if I can't use an Xpath in the name attribute of the call-template element. How can I get around this? Any help/thoughts would be awesome!

<xsl:for-each select="child::knomaddb/Content/Videos">
        <xsl:result-document method="xhtml" href="{local-name()}.html">
            <html>
                <body>
                    <h1>Knomad</h1>
                    <h2>{local-name()} Videos</h2>
                    <table border="1">
                        <tr bgcolor="#9acd32">
                            <th>Title</th>
                            <th>Video</th>
                            <th>Description</th>
                            <th>Comments</th>
                        </tr>
                        <xsl:for-each select="Video">
                            <xsl:call-template name="{ancestor::local-name()}"/>
                        </xsl:for-each>
                    </table>
                </body>
            </html>
        </xsl:result-document>
    </xsl:for-each>

推荐答案

好像我不能在名称属性中使用 Xpath调用模板元素.我该如何解决这个问题?

It seems as if I cant use an Xpath in the name attribute of the call-template element. How can I get around this?

好问题,+1.

你不能.但是你可以改用 .

这是一个快速演示:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:double="double" xmlns:incr="incr" xmlns:my="my:my"
exclude-result-prefixes="double incr my"
>
  <xsl:output method="text"/>

   <double:double/>
   <incr:incr/>

   <xsl:variable name="vFuncDouble"
        select="document('')/*/double:*[1]"/>

   <xsl:variable name="vFuncIncr"
        select="document('')/*/incr:*[1]"/>

   <xsl:function name="my:double">
     <xsl:param name="arg1" />

      <xsl:sequence select="2*$arg1"/>
   </xsl:function>

   <xsl:function name="my:incr">
     <xsl:param name="arg1" />

      <xsl:sequence select="1+$arg1"/>
   </xsl:function>

    <xsl:template name="double" match="double:*">
      <xsl:param name="arg1"/>

      <xsl:sequence select="my:double($arg1)"/>
    </xsl:template>

    <xsl:template name="incr" match="incr:*">
      <xsl:param name="arg1"/>

      <xsl:sequence select="my:incr($arg1)"/>
    </xsl:template>

    <xsl:function name="my:apply">
      <xsl:param name="pFun" as="element()"/>
      <xsl:param name="arg1"/>

      <xsl:apply-templates select="$pFun">
        <xsl:with-param name="arg1" select="$arg1"/>
      </xsl:apply-templates>
    </xsl:function>

    <xsl:template match="/">
     <xsl:sequence select="my:apply($vFuncIncr, my:apply($vFuncDouble,2))"/>
    </xsl:template>
</xsl:stylesheet>

当此转换应用于任何 XML 文档(未使用)时,会产生想要的结果:

5

请注意:

可以将参数(第一个参数)传递给 my:apply() 任何函数"和 my:apply()将其应用于第二个参数.

使用相同的原理FXSL 库 在XSLT 1.0 和 XSLT 2.0 -- 在此处阅读更多信息.

Using this same principle the FXSL library implemented Higher Order Functions (HOFs) in XSLT 1.0 and XSLT 2.0 -- read more here.

在即将发布的 XPath 3.0 函数首次成为 Xpath 数据模型 (XDM).

In the forthcoming XPath 3.0 functions are for the first time first class objects in the Xpath Data Model (XDM).

这篇关于XSLT 调用模板名称属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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