有什么方法可以内联调用 XSLT 模板 [英] Is there any way to call XSLT templates inline
本文介绍了有什么方法可以内联调用 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屋!
查看全文