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

    >> 本版讨论XSL,XSLT,XSL-FO,CSS等技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XSL/XSLT/XSL-FO/CSS 』 → [求助]如何统计元素值一样的元素总数, 请帮帮新手,谢先!!! 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3581 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [求助]如何统计元素值一样的元素总数, 请帮帮新手,谢先!!! 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     handspeaker 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:3
      积分:66
      门派:XML.ORG.CN
      注册:2007/5/2

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给handspeaker发送一个短消息 把handspeaker加入好友 查看handspeaker的个人资料 搜索handspeaker在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看handspeaker的博客楼主
    发贴心情 [求助]如何统计元素值一样的元素总数, 请帮帮新手,谢先!!!

    —————xml—————
    <customers>
     <customer cno="001" >
      <name>张</name>
      <orders>
       <order no="O112">
        <orderDate>2007-06-21</orderDate>
        <orderLine>
         <food>橙汁</food>
         <quantity>2</quantity>
         <unitPrice>2.50</unitPrice>
        </orderLine>
        <orderLine>
         <food>薯条</food>
         <quantity>2</quantity>
         <unitPrice>3</unitPrice>
        </orderLine>
       </order>
       <order no="O121">
        <orderDate>2006-01-20</orderDate>
        <orderLine>
         <food>橙汁</food>
         <quantity>5</quantity>
         <unitPrice>$2</unitPrice>
        </orderLine>
        <orderLine>
         <food>薯条</food>
         <quantity>1</quantity>
         <unitPrice>$3</unitPrice>
        </orderLine>
        <orderLine>
         <food>汉堡</food>
         <quantity>1</quantity>
         <unitPrice>$6</unitPrice>
        </orderLine>
       </order>
      </orders>
     </customer>
     <customer cno="002" >
      <name>李</name>
      <orders>
       <order no="O20">
        <orderDate>2007-06-3</orderDate>
        <orderLine>
         <food>橙汁</food>
         <quantity>2</quantity>
         <unitPrice>$2</unitPrice>
        </orderLine>
        <orderLine>
         <food>薯条</food>
         <quantity>1</quantity>
         <unitPrice>$3</unitPrice>
         
        </orderLine>
       </order>
       <order no="O21">
        <orderDate>2006-09-30</orderDate>
        <orderLine>
         <food>橙汁</food>
         <quantity>3</quantity>
         <unitPrice>$2</unitPrice>
        </orderLine>
        <orderLine>
         <food>汉堡</food>
         <quantity>1</quantity>
         <unitPrice>$6</unitPrice>
        </orderLine>
       </order>
      </orders>
     </customer>
    </customers>


    请问如何输出下面表格:

    food        total order number

    橙汁              12

    薯条              4

    自己新手,实在没有思路。
    请大侠指教, 多谢了!!!!


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/8/4 10:13:00
     
     txnnh 美女呀,离线,快来找我吧!
      
      
      等级:大二(研究汇编)
      文章:29
      积分:250
      门派:XML.ORG.CN
      注册:2006/11/17

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给txnnh发送一个短消息 把txnnh加入好友 查看txnnh的个人资料 搜索txnnh在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看txnnh的博客2
    发贴心情 
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
     <xsl:key name="foodName" match="orderLine" use="food"/>
     <xsl:template match="customers">
      <xsl:call-template name="foodAndQty"/>
     </xsl:template>
     <xsl:template name="foodAndQty">
      <table>
       <tbody>
        <xsl:for-each select="customer/orders/order/orderLine[generate-id() = generate-id(key('foodName',food))]">
         <tr>
          <xsl:variable name="courrentfoodName" select="food"/>
          <th>
           <xsl:value-of select="$courrentfoodName"/>
          </th>
          <th>
           <xsl:value-of select="sum(key('foodName',$courrentfoodName)/quantity)"/>
          </th>
         </tr>
        </xsl:for-each>
       </tbody>
      </table>
     </xsl:template>
    </xsl:stylesheet>
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/8/4 14:08:00
     
     handspeaker 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:3
      积分:66
      门派:XML.ORG.CN
      注册:2007/5/2

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给handspeaker发送一个短消息 把handspeaker加入好友 查看handspeaker的个人资料 搜索handspeaker在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看handspeaker的博客3
    发贴心情 
    多谢了! 又学了两招,呵呵
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/8/4 22:36:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2025/3/11 13:09:39

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

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