是否有任何方式内联调用XSLT模板 [英] Is there any way to call XSLT templates inline

查看:155
本文介绍了是否有任何方式内联调用XSLT模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何内联调用XSLT模板?例如,而不是:

How to call XSLT templates inline? For instance, instead of :

<xsl:call-template name="myTemplate" >
<xsl:with-param name="param1" select="'val'" />
</xsl:call-template>

我可以使用XSLT内置的函数调用样式,如下所示:

Can I use XSLT built-in function-call style, like this:

<xls:value-of select="myTeplate(param1)" />


推荐答案

在XSLT 2.0中,您可以使用 xsl:function

In XSLT 2.0 you can define your own custom functions using xsl:function

一篇关于XML.com的文章,介绍如何在XSLT 2.0中编写自己的功能: http: //www.xml.com/pub/a/2003/09/03/trxml.html

An article on XML.com describing how to write your own functions in XSLT 2.0: http://www.xml.com/pub/a/2003/09/03/trxml.html

<xsl:stylesheet version="2.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:foo="http://whatever">

  <!-- Compare two strings ignoring case, returning same
       values as compare(). -->
  <xsl:function name="foo:compareCI">
    <xsl:param name="string1"/>
    <xsl:param name="string2"/>
    <xsl:value-of select="compare(upper-case($string1),upper-case($string2))"/>
  </xsl:function>

  <xsl:template match="/">
compareCI red,blue: <xsl:value-of select="foo:compareCI('red','blue')"/>
compareCI red,red: <xsl:value-of select="foo:compareCI('red','red')"/>
compareCI red,Red: <xsl:value-of select="foo:compareCI('red','Red')"/>
compareCI red,Yellow: <xsl:value-of select="foo:compareCI('red','Yellow')"/>
  </xsl:template>

</xsl:stylesheet>

这篇关于是否有任何方式内联调用XSLT模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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