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 ...
随机推荐
- 码表 ASCII Unicode GBK UTF-8
2017-1-3 [ASCII]一个字节(7位,128个字符,2个16进制) 不包含中文 ASCII(American Standard Code for Information Interchang ...
- 创建cocos项目
创建cocos项目 进入终端输入命令: cocos new HelloCpp -p com.cocos.org -l cpp -d /Users/emerys/documents/cocos 参数说明 ...
- javaScript 手写图片轮播
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- qt实现类似QQ伸缩窗口--鼠标事件应用
原创文章,引用请保证原文完整性,尊重作者劳动,原文地址http://blog.csdn.net/hiwubihe/article/details/38678305,qq:1269122125. 上一章 ...
- 跟我学android-Activity介绍
Activity是android四大组件之一,activity 可以看成是一个屏幕,用户可以在这里做一些操作.activity通常都是满屏的,但也可以小于屏幕而浮于其它窗口之上,比如把activity ...
- 最短路径算法——Dijkstra,Bellman-Ford,Floyd-Warshall,Johnson
根据DSqiu的blog整理出来 :http://dsqiu.iteye.com/blog/1689163 PS:模板是自己写的,如有错误欢迎指出~ 本文内容框架: §1 Dijkstra算法 §2 ...
- 【USACO 2.4.3】牛的旅行
[描述] 农民 John的农场里有很多牧区.有的路径连接一些特定的牧区.一片所有连通的牧区称为一个牧场.但是就目前而言,你能看到至少有两个牧区通过任何路径都不连通.这样,Farmer John就有多个 ...
- Android学习----Android Studio 技巧汇总
关于快捷键 The File Structure Popup ctrl+f12此快捷键可以调出当前文件的大纲,并通过模糊匹配快速跳转至指定的方法.勾选上“show anonymous classes” ...
- 04_RHEL7.1忘记root密码
在开机进入启动项时,选择需要重设密码的那个启动项 按e进入编辑模式,找到rhgb和quiet参数(几乎在最下面),替换为 init=/bin/sh 按ctrl+X不需密码进入shell 以rw的方式重 ...
- 无法解析属性“mode”的值。错误为: 枚举值必须是以下各值中的一个: RemoteOnly, On, Off。
Off首字母要大写,注意大小写 <customErrors mode="Off"> <error statusCode="404" ...