XSLT编写技巧

1、<xsl:apply-templates select="xsd:schema" mode="schema"/>

如果select的结果为空,则实际上什么也不做

2、xpath中的通配符

通配符

描述

*

匹配任何元素节点

@*

匹配任何属性节点。

node()

匹配任何类型的节点

 

3、<span class="xforms-hint-value" id="{$hid}">

如上代码演示了如何在输出文档流中插入变量、参数值,方法为{$名称}

 

4、call-template和apply-templates的性能差别上:

In terms of raw performance xsl:call-template is likely to be faster, as you are calling a specific named template, rather than telling the XSLT processor to pick the template which best matches.

There are certainly things you can do with xsl:call-template that you can’t do with xsl:apply-templates, such as recursive templates which are very powerful.

xsl:apply-templates is however the more flexible and extensible, due to its combined use of the match patterns, modes and priorities.

 

5、关于apply-template的优先级

A template with a high priority is chosen over a template with a lower priority.

6、call-template传递参数

1)

<xsl:with-param name="class">

xforms-control xforms-

<xsl:value-of select="local-name()" />

se>

</xsl:choose>

</xsl:with-param>

传递的参数类型为:Text

2)、

 

7、为空的情况

concat(@class, ' xforms-disabled ', $class)

如果@class为空(不存在),则当作空处理,不会影响函数的正常运行。

posted @ 2014-07-10 09:08  ghpaas  阅读(323)  评论(0编辑  收藏  举报