`
Intrepid2012
  • 浏览: 70762 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

<xsl:apply-templates> vs <xsl:call-template/>

    博客分类:
  • xsl
 
阅读更多

On a very basic level, you use <xsl:apply-templates> when you want to let the processor handle nodes automatically, and you use <xsl:call-template/> when you want finer control over the processing. So if you have:

<foo>
    <boo>World</boo>
    <bar>Hello</bar>
</foo>

And you have the following XSLT:

<xsl:template match="foo">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="bar">
    <xsl:value-of select="."/>
</xsl:template>

<xsl:template match="boo">
    <xsl:value-of select="."/>
</xsl:template>

You will get the result WorldHello. Essentially, you've said "handle bar and boo this way" and then you've let the XSLT processor handle these nodes as it comes across them. In most cases, this is how you should do things in XSLT.

Sometimes, though, you want to do something fancier. In that case, you can create a special template that doesn't match any particular node. For example:

<xsl:template name="print-hello-world">
    <xsl:value-of select="concat( bar, ' ' , boo )" />
</xsl:template>

And you can then call this template while you're processing <foo> rather than automatically processing foo's child nodes:

<xsl:template match="foo">
    <xsl:call-template name="print-hello-world"/>
</xsl:template>

In this particular artificial example, you now get "Hello World" because you've overriden the default processing to do your own thing.

分享到:
评论

相关推荐

    eclipse-testng 离线包下载

    &lt;xsl:template name="writeCssFile"&gt; &lt;xsl:result- document href="{testng:absolutePath('style.css')}" format="text"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="testng:isFilterSelected('CONF') = 'true'"&gt; ....

    个人简历xml+xsl.zip

    针对于xml个人简历,附有xsl文档代码:&lt;?xml version="1.0" encoding="gb2312"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;...

    xml常用命令

    比较有用的关于xml的命令, xsl:import元素 xsl:import元素用于导入外部的样式单,也是一个顶级元素。...&lt;xsl:template match=”node”&gt; &lt;xsl:apply-impotres/&gt; &lt;/xsl:template&gt; ……… &lt;/xsl:stylesheet&gt;

    动易网站标签说明(电子书)

    &lt;UL&gt;{PE.DataSource id="InfoList&lt;XSL:VALUE-OF select="NodeID" /&gt;" datasource="图片栏目循环列表信息" nodeArray="&lt;XSL:VALUE-OF select="arrChildID" /&gt;" parentId="&lt;XSL:VALUE-OF select="$parentId" /&gt;" ...

    xml程序大集绵(有各种文件,包括很多)

    &lt;sno&gt;1067001516&lt;/sno&gt; &lt;name&gt;汤柳清&lt;/name&gt; &lt;sex&gt;男&lt;/sex&gt; &lt;age&gt;22&lt;/age&gt; &lt;address&gt;江西师范大学&lt;/address&gt; &lt;tel&gt;15270861237&lt;/tel&gt; &lt;/student&gt; &lt;student&gt; &lt;sno&gt;1067001517&lt;/sno&gt; &lt;name&gt;张三&lt;/...

    动易SF通用信息列表解释版

    -- 定义了输出文档的格式、&lt;xsl:output&gt; 是顶层元素(top-level element),必须是 &lt;xsl:stylesheet&gt; 或 &lt;xsl:transform&gt; 的子节点。定义输出的格式html、设置输出格式的 W3C 版本号(仅在 method=...

    N级导航标签

    xsl:value-of select="$currentId"/&gt;" depth="1"/}" num="1" /} &lt;/div&gt; &lt;div id="nav"&gt; &lt;a class="home" href="{PE.SiteConfig.SitePath /}"&gt;返回首页&lt;/a&gt; {PE.Label id="多级导航菜单" nodeid="{PE.Label id=...

    XSL转换XML的技术

    编写文件名为student2.xsl的XSL文件,其中,用&lt;xsl:sort&gt;对学生信息数据按照专业进行排序,并用&lt;xsl:if&gt;筛选出专业为“计算机”的学生信息。要求显示出的计算机专业的学生信息记录单元格背景色为黄色,字符为加粗的...

    XML 指南XML 实例XML 测验XML 基础

    &lt;TITLE&gt;Empire Burlesque&lt;/TITLE&gt; &lt;ARTIST&gt;Bob Dylan&lt;/ARTIST&gt; &lt;COUNTRY&gt;USA&lt;/COUNTRY&gt; &lt;COMPANY&gt;Columbia&lt;/COMPANY&gt; &lt;PRICE&gt;10.90&lt;/PRICE&gt; &lt;YEAR&gt;1985&lt;/YEAR&gt; &lt;/CD&gt; &lt;CD&gt; &lt;TITLE&gt;Hide your heart&lt;/TITLE&gt; &lt;ARTIST&gt;...

    XBRL符合性测试用例

    &lt;!-- XBRL 2.1 Tests --&gt; &lt;!... All Rights Reserved.... ...xml-stylesheet type="text/xsl" href="testcases.xsl"?...&lt;testcases name="XBRL 2.1 Tests" date="12/14/2009"&gt; &lt;testcase uri="Common/300-...&lt;/testcases&gt;

    hadoop,spark,hbase,zookeeper,kafka配置文件

    hadoop,spark,hbase,zookeeper,kafka配置文件。 例如: &lt;?xml version="1.0" encoding="UTF-8"?&gt;... &lt;value&gt;file:/home/bigData/bigdata/hadoop/tmp&lt;/value&gt; &lt;/property&gt; &lt;/configuration&gt;

    hadoop-lzo-0.4.20.jar

    &lt;name&gt;io.compression.codecs&lt;/name&gt; &lt;value&gt; org.apache.hadoop.io.compress.GzipCodec, org.apache.hadoop.io.compress.DefaultCodec, org.apache.hadoop.io.compress.BZip2Codec, org.apache.hadoop.io....

    html标签及属性大全

    基本结构标签: &lt;HTML&gt;,表示该文件为HTML文件 ...&lt;/HEAD&gt;,&lt;HEAD&gt;的结束标志 &lt;BODY&gt;,放置浏览器中显示信息的所有标志和属性,其中内容在浏览器中显示. &lt;/BODY&gt;,&lt;BODY&gt;的结束标志 &lt;/HTML&gt;,&lt;HTML&gt;的结束标志

    testNG-xslt

    &lt;project name="myproject" basedir="."&gt; &lt;property name="lib.dir" value="lib"/&gt; &lt;path id="test.classpath"&gt; &lt;!-- adding the saxon jar to your classpath --&gt; &lt;fileset dir="${lib.dir}" includes="*.jar...

    无限菜单之 xml+popup 版(IE5.5+)

    &lt;xsl:if test="count(MenuItem) &gt; 0"&gt; &lt;!-- 这里用来存储子菜单的xml数据 --&gt; &lt;xml&gt; &lt;xsl:copy-of select="."/&gt; &lt;/xml&gt; &lt;/xsl:if&gt; &lt;/td&gt; &lt;td width="20" align="right" valign...

    docx-xslt:Microsoft Word .docx 模板文件的 XSL 转换

    docx-xslt docx-xslt是一个 Python 库,用于为没有 XML 或 XSLT 编码的 ... ::= &lt;command&gt; &lt;command&gt; ::= &lt;command&gt; | &lt;command&gt; &lt;command&gt; ::= 'xsl' ':' &lt;context&gt; &lt;xsl&gt; &lt;xsl&gt; &lt;context&gt; ::= ':' &lt;context&gt; | &lt;

    Struts2 国际化字符串 拦截器

    &lt;result type="velocity"&gt;/HelloWorld.vm&lt;/result&gt; &lt;/action&gt; 例3 classes/struts.xml中VMHelloWorld Action的配置 新建HelloWorld.vm,内容如下所示: &lt;html&gt; &lt;head&gt; &lt;title&gt;Velocity&lt;/title&gt; &lt;meta ...

    如何在class内写xsl标记注意事项

    复制代码代码如下: &lt;xsl select=”trtim”&gt; &lt;tr&gt; &lt;td class=””&gt; &lt;xsl select=”titel/@color”/&gt;&lt;xsl select=”titel”&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl select=”border”&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/xsl&gt; 我想给class中写一个值,如下面的...

    JSP中使用XSLT所需要的jar

    xerces xalan taglibs-xsl是JSP中调用&lt;xsl:apply xml="result.xml" xsl="result.xsl"&gt;&lt;/xsl:apply&gt;的xslt标签所必须的包。 还需要另外一个文件到http://download.csdn.net/source/655756下载。

Global site tag (gtag.js) - Google Analytics