call-template和apply-templates
对xml模板 来说,name属性是很关键的 call-template /apply-template 的name必须要和模板的name相对应。模板相当于一个函数,可以暂时这么看。而name相当于函数名称.
简单说apply是应用,call是调用。
用apply时,引擎自动搜索与当前select指定xpath的匹配节点相匹配的template(该template必须有属性match)并使用该template进行处理,此时需要指定的是select的path。
用call时就跟其它语言调用函数一样,必须指定name属性,相应的,该template必须有name属性,当然,也可以在这时with-param(当然相应的模板中有对应的param才行,不过这个不强制要求)。
1)从名字区分:call-template,一次只对一个node名字有效;而apply-templates,注意是是复数,所以这个是对所有符合条件的node有效。
2)从手法上:call-template,手段是通过name;apply-templates手段是通过match。
3)使用apply调用的模板, 其中的上下文节点是与之匹配的节点。使用call调用的模板, 它没有上下文节点,参数通过param进行传递
call-template的用法
比如用到枚举型
定义
<xsl:call-template name="pollutionSource">
<xsl:with-param name="source" select="ns1:PollutionSource"></xsl:with-param>
</xsl:call-template>
实现
<xsl:template name="pollutionSource">
<xsl:param name="source" />
<xsl:if test="$source=0">
<xsl:text>水</xsl:text>
</xsl:if>
<xsl:if test="$source=1">
<xsl:text>气</xsl:text>
</xsl:if>
<xsl:if test="$source=2">
<xsl:text>生物</xsl:text>
</xsl:if>
<xsl:if test="$source=3">
<xsl:text>声</xsl:text>
</xsl:if>
</xsl:template>
call-template和apply-templates的更多相关文章
- springbooot2 thymeleaf 配置以及加载资源文件。Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
最近在学习springbooot2 和 thymeleaf 程序文件 application.properties文件配置: #thymeleaf spring.thymeleaf.prefix=cl ...
- Package template (html/template) ... Types HTML, JS, URL, and others from content.go can carry safe content that is exempted from escaping. ... (*Template) Funcs ..
https://godoc.org/text/template GoDoc Home About Go: text/templateIndex | Examples | Files | Directo ...
- Umbraco(2) - Creating Your First Template and Content Node(翻译文档)
创建(编辑)你的第一个模板(Template) 展开 Settings > Templates文件夹 - 然后你应该看到子节点名为"Homepage" - 这是我们在创建Do ...
- C++11 : variadic templates(可变参数模板)
Introduction: Before the possibilities of the new C++ language standard, C++11, the use of templat ...
- 3、Ansible playbooks(Hosts、Users、tasks、handlers、变量、条件测试(when、迭代)、templates)
Ansible playbooks playbook是由一个或多个“play”组成的列表.play的主要功能在于将事先归并为一组的主机装扮成事先通过ansible中的task定义好的角色.从根本上来讲 ...
- IntelliJ IDEA 2017版 使用笔记(五) 模板 live template自定义设置(二) ;postfix使用;IDE快捷键使用
一.live template 活模板 就像这个单词的含义一样,live template就是一个高效的提高代码,书写速度的方式,(live template位置File-----settin ...
- Rsyslog的模板template详解
一. Template功能 根据用户需求指定任意格式 动态生成文件名 每个输出都使用了一些模板,包括针对文件的,针对用户消息等 备注: 旧版本:$template 新版本:template() V6之 ...
- angular—— Dynamic Templates
原文:http://davidcai.github.io/blog/posts/router-dynamic-templates/ ui-router : templateProvider vs te ...
- 深入jvm虚拟机--第一篇 void TemplateInterpreterGenerator::generate_and_dispatch(Template* t, TosState tos_out) 函数
今天第一次使用虚拟姐打断点,断点设置在了void TemplateInterpreterGenerator::generate_and_dispatch(Template* t, TosState t ...
- Deformable Templates For Eye Detection
1 Abstract This approach was published On "Deformable Templates for Face Recognition" by A ...
随机推荐
- 图片标签的alt与title区别
一.img标签alt属性 1.alt属性是考虑到不支持图像显示或者图像显示被关闭的浏览器的用户,以及视觉障碍的用户和使用屏幕阅读器的用户.当图片不显示的时候,图片的替换文字. 2.alt属性值得长度必 ...
- iOS开发 UITableView之cell
1.cell简介 UITableView的每一行都是一个UITableViewCell,通过dataSource的tableView:cellForRowAtIndexPath:方法来初始化每一行 U ...
- 认识<hr>标签,添加水平横线
在信息展示时,有时会需要加一些用于分隔的横线,这样会使文章看起来整齐些.如下图所示: 语法: html4.01版本 <hr> xhtml1.0版本 <hr /> 注意: 1. ...
- 七、C# 接口
并非只能通过继承使用多态性,还能通过接口使用它. 和抽象类不同,接口不包含任何实现(方法). 然后和抽象类相似,接口也定义了一系列成员,调用者可以依赖这些成员来支持一个特定的功能. 实现接口的类会 ...
- hibernate_validator_04
对象图--个人觉得就是关联验证 ean Validation API不仅能够用来校验单个的实例对象,还能够用来校验完整的对象图.要使用这个功能,只需要在一个有关联关系的字段或者属性上标注 @Valid ...
- 二十分钟弄懂C++11 的 rvalue reference (C++ 性能剖析 (5))
C++ 11加了许多新的功能.其中对C++性能和我们设计class的constructor或assignment可能产生重大影响的非rvalue reference莫属!我看了不少资料,能说清它的不多 ...
- 巧用C#做中间语言 实现Java调用.net DLL
本文将详细为大家介绍一个java调用.net DLL的方法,以实现特殊的客户的特殊要求:“在Java项目中必须使用其提供的用.net写的DLL加密机制!” 环境与工具: ◆.net framework ...
- CMake----if与option使用小记
在CMake中if语法比较简单,if后面括号中的参数随着CMake版本的推进,在else和endif中也可以不用写了. if(address) else() endif() 对于if语法,比较常用的就 ...
- .net别样外观控件包DotNetBar
内容介绍:http://www.componentcn.com/?thread-6423-1.html BubbleBar应用: BubbleBar, DevComponents. Namesp ...
- thinkphp框架之模型(数据库查询)
1. 模型定义 文件名称必须是 表名+Model.class.php 例如:UserModel.class.php namespace Home\Model; //该模型类的命名空间 use Thin ...