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 ...
随机推荐
- python增删改查
###增删改查 names = ["zhangding","wangxu","wudong","cheng"] #增na ...
- Day7 - Python基础7 面向对象编程进阶
Python之路,Day7 - 面向对象编程进阶 本节内容: 面向对象高级语法部分 经典类vs新式类 静态方法.类方法.属性方法 类的特殊方法 反射 异常处理 Socket开发基础 作业:开发一个 ...
- HTML 详细介绍
什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Text Markup Language) HTML 不是一种编程语言,而是一种标记语言 (ma ...
- querystring,parse和stringify相互转换
var querystring = require('querystring');var str = 'name==zfpx@age==8';//手工指定字段分隔符和 keyvalue分隔符var q ...
- C语言零移位操作
给定一个整形数组要求把其中的零元素移动到数组的末尾 非零元顺序保持不变 以下采用两种方法实现 #include <stdlib.h> #include <stdio.h> #i ...
- JavaScript-学习一全局变量
因为局部变量只作用于函数内,所以不同的函数可以使用相同名称的变量. 局部变量在函数开始执行时创建,函数执行完后局部变量会自动销 不限制位置的 JavaScript 变量生命周期在它声明时初始化. 局部 ...
- 我牵头,你做事——C#委托实践
我牵头,你做事——C#委托实践一 2007-09-05 23:54:54 标签:委托 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http ...
- 随机数是骗人的,.Net、Java、C为我作证(转载)
几乎所有编程语言中都提供了"生成一个随机数"的方法,也就是调用这个方法会生成一个数,我们事先也不知道它生成什么数.比如在.Net中编写下面的代码: Random rand = ...
- c# 接口代码实例
类和接口的实现 接口定义:为一组方法签名指定一个名称的方式. 类实现接口,就一定要提供接口所有方法的实现. 即使抽象类,也要全部实现,但是,它可以把接口方法声明为abstract的,从而把这个接口方法 ...
- Unity脚本获取内存和FPS
using System; using System.Collections.Generic; using UnityEngine; public class Debugger : MonoBehav ...