新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论XSL,XSLT,XSL-FO,CSS等技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XSL/XSLT/XSL-FO/CSS 』 → [求助]<xsl:call-template>与<xsl:apply-templates>的区别是什么? 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 5717 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [求助]<xsl:call-template>与<xsl:apply-templates>的区别是什么? 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     sam 帅哥哟,离线,有人找我吗?
      
      
      头衔:日夜灌水W3C
      等级:大三暑假(ITELS考了7分!)
      文章:198
      积分:969
      门派:XML.ORG.CN
      注册:2004/3/24

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给sam发送一个短消息 把sam加入好友 查看sam的个人资料 搜索sam在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问sam的主页 引用回复这个贴子 回复这个贴子 查看sam的博客楼主
    发贴心情 [求助]<xsl:call-template>与<xsl:apply-templates>的区别是什么?

    <xsl:call-template>一般用在什么地方?

       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    http://www.xml.org.cn/uploadFace/3819_20044191991837196.gif^_^

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/4/12 23:22:00
     
     wedge 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:35
      积分:153
      门派:XML.ORG.CN
      注册:2004/3/31

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wedge发送一个短消息 把wedge加入好友 查看wedge的个人资料 搜索wedge在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看wedge的博客2
    发贴心情 
    <xsl:call-template>能够建立模板函数,重复使用相同的模板元素,只需引入不同的参数就可以产生不同的结果!
    simplebook.xml
    ********************
    <?xml version="1.0" encoding="GB2312"?>
    <?xml-stylesheet type="text/xsl" href="function.xslt"?>
    <!-- edited with XMLSPY v2004 rel. 3 U (http://www.xmlspy.com) by wedge (WWW) -->
    <!--网页制作彻底研究系列-->
    <booklist>
     <book sales="Y">
      <code>F8915</code>
      <title>ASP网页制作彻底研究</title>
      <authorlist>
       <author>陈会安</author>
       <author>sun</author>
      </authorlist>
      <price>580</price>
     </book>
     <book sales="Y">
      <code>F8916</code>
      <title>ASP与IIS 4/5网站架设彻底研究</title>
      <authorlist>
       <author>wedge</author>
       <author>sun</author>
      </authorlist>
      <price>550</price>
     </book>
     <book sales="N">
      <code>F8917</code>
      <title>ASP精讲案例教程</title>
      <authorlist>
       <author>wedge</author>
       <author>sun</author>
      </authorlist>
      <price>590</price>
     </book>
     <book sales="N">
      <code>F8918</code>
      <title> 家常小菜</title>
      <authorlist>
       <author>sally</author>
       <author>sun</author>
      </authorlist>
      <price>120</price>
     </book>
     </booklist>

    ********************
    function.xslt
    *******************
    <?xml version="1.0" encoding="gb2312"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
     <head>
      <title>使用函数显示XML</title>
     </head>
     <body>
     <center>
     <h2>使用函数显示XML</h2>
     </center>
     <p>价格超过550的书</p>
     <table width="100%" border="1">
     <thead>
      <tr>
       <th>代码</th>
       <th>书名</th>
       <th>作者</th>
       <th>单价</th>
      </tr>
     </thead>
     
      <tbody>
      <xsl:call-template name="showbook">
      <xsl:with-param name="position" select="/booklist/book[price>='550' ] ">
    </xsl:with-param>
      </xsl:call-template>
      </tbody>
     </table>
     <p>价格低于500的书</p>
     <table width="100%" border="1">
     <xsl:call-template name="showbook">
      <xsl:with-param name="position" select="/booklist/book[price &lt;'500'] ">
    </xsl:with-param>
      </xsl:call-template>
    </table>
     <table width="100%" border="1">
     <p>已经售出的书</p>
     <xsl:call-template name="showbook">
      <xsl:with-param name="position" select="/booklist/book[@sales='Y'] ">
    </xsl:with-param>
      </xsl:call-template>

     </table>
     </body>
    </html>
    </xsl:template>
    <xsl:template name="showbook"><!-- 定义函数showbook-->
    <xsl:param name="position" select="/booklist/book"></xsl:param>
    <xsl:for-each select="$position">
    <tr>
     <th><xsl:value-of select="code"></xsl:value-of></th>
     <th><xsl:value-of select="title"></xsl:value-of></th>
    <th><xsl:value-of select="authorlist/author"></xsl:value-of></th>
    <th><xsl:value-of select="price"></xsl:value-of></th>
    </tr>


    </xsl:for-each>

    </xsl:template>


    </xsl:stylesheet>
    ********************
    希望多多交流!

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/4/13 16:02:00
     
     diegor 帅哥哟,离线,有人找我吗?白羊座1979-4-10
      
      
      威望:4
      等级:大二(研究C++)|大二(研究汇编)
      文章:266
      积分:806
      门派:XML.ORG.CN
      注册:2004/3/3

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给diegor发送一个短消息 把diegor加入好友 查看diegor的个人资料 搜索diegor在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看diegor的博客3
    发贴心情 
    msxml 4.0 sdk say:

    The <xsl:call-template> enables you to invoke a named template—that is, an <xsl:template> element—that has an assigned name attribute. If an <xsl:template> element has a name attribute, it might, but need not, also have a match attribute. An <xsl:call-template> element invokes a template by name; it has a required name attribute that identifies the template to be invoked. Unlike <xsl:apply-templates>, <xsl:call-template> does not change the current node or the current node-list.

    An error occurs if a style sheet contains more than one template with the same name and with the same import precedence.
    An <xsl:call-template> element can contain any number of <xsl:with-param> elements. However, it cannot contain other XSLT elements.

    <xsl:call-template
      name = QName>
    </xsl:call-template>

    The <xsl:apply-templates> element first selects a set of nodes using the expression specified in the select attribute. If this attribute is left unspecified, all children of the current node are selected. For each of the selected nodes, <xsl:apply-templates> directs the XSLT processor to find an appropriate <xsl:template> to apply. Templates are tested for applicability by comparing the node to the XPath expression specified in the template's match attribute. If more than one template satisfies the match pattern, the one appearing with the highest priority is chosen. If several templates have the same priority, the last in the style sheet is chosen.

    <xsl:apply-templates
      select = Expression
      mode = QName>
    </xsl:apply-templates>


    我看了半天也不是很明白,两者区别好像是:是否有参数,一种使用比较灵活,一种比较固定,呵呵,愚见!


    [此贴子已经被作者于2004-4-13 17:11:31编辑过]

    ----------------------------------------------
    坚决支持XML!

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/4/13 16:39:00
     
     sam 帅哥哟,离线,有人找我吗?
      
      
      头衔:日夜灌水W3C
      等级:大三暑假(ITELS考了7分!)
      文章:198
      积分:969
      门派:XML.ORG.CN
      注册:2004/3/24

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给sam发送一个短消息 把sam加入好友 查看sam的个人资料 搜索sam在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问sam的主页 引用回复这个贴子 回复这个贴子 查看sam的博客4
    发贴心情 
    谢谢wedge和diegor
    找了很久的资料,看到了下面的东西,可惜还是搞不太明白
    <xsl:apply-templates> Instructs the XSLT processor to apply the appropriate templates to a node-set.
    <xsl:call-template> Lets you invoke a particular template by name. This invocation is a convenient way to create commonly used output. For example, if you create an HTML page and all your HTML pages have the same masthead and footer, you could define templates named masthead and footer, then use <xsl:call-template> to invoke those templates as needed.

    ----------------------------------------------
    http://www.xml.org.cn/uploadFace/3819_20044191991837196.gif^_^

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/4/14 9:49:00
     
     wedge 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:35
      积分:153
      门派:XML.ORG.CN
      注册:2004/3/31

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wedge发送一个短消息 把wedge加入好友 查看wedge的个人资料 搜索wedge在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看wedge的博客5
    发贴心情 
    当在xml中出现<xsl:apply-templates select="//book"/>时,应该跳出当前的模板,递归地去找符合
    <xsl:templates select="book"/>的模板,把所有的book元素都显示出来,好象和递归计算n!的方法类似!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/4/15 14:37:00
     
     KAI 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:40
      积分:215
      门派:XML.ORG.CN
      注册:2004/4/16

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给KAI发送一个短消息 把KAI加入好友 查看KAI的个人资料 搜索KAI在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看KAI的博客6
    发贴心情 
    call 你有name的template
    apply 你没有name 的template

    ----------------------------------------------
    [url]http://www.kingbbs.net[/url]

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/4/16 18:18:00
     
     hyandlsz 帅哥哟,离线,有人找我吗?
      
      
      头衔:侠
      等级:大二期末(Java考了96分!)
      文章:117
      积分:503
      门派:W3CHINA.ORG
      注册:2004/3/30

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给hyandlsz发送一个短消息 把hyandlsz加入好友 查看hyandlsz的个人资料 搜索hyandlsz在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看hyandlsz的博客7
    发贴心情 
    有道理!

    ----------------------------------------------
    人最大的烦恼就是记性太好,如果什么都可以忘了,以后的每一天将会是一个新的开始,那你说多开心!

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/4/19 10:55:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/27 5:57:26

    本主题贴数7,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    5,503.906ms