以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 XSL/XSLT/XSL-FO/CSS 』 (http://bbs.xml.org.cn/list.asp?boardid=8) ---- [求助]如何统计元素值一样的元素总数, 请帮帮新手,谢先!!! (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=50949) |
-- 作者:handspeaker -- 发布时间:8/4/2007 10:13:00 AM -- [求助]如何统计元素值一样的元素总数, 请帮帮新手,谢先!!! —————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 自己新手,实在没有思路。 |
-- 作者:txnnh -- 发布时间:8/4/2007 2:08:00 PM -- <?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> |
-- 作者:handspeaker -- 发布时间:8/4/2007 10:36:00 PM -- 多谢了! 又学了两招,呵呵 |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
62.500ms |