xslt 汇总发票中的总数 [英] xslt summing the totals in an invoice

查看:20
本文介绍了xslt 汇总发票中的总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用 xslt 表来显示每个客户的发票总额.请帮助,.尽我所能使用递归,但似乎没有任何让步,.for-每个循环只给我所有的总数产品但不是每张发票.,任何想法

am wondering how i can up with an xslt sheet for to show the invoice total per customer.please help,.tried my best with recursive but nothing seems to give way,.for-each loop only gives me the total of all the products but not per invoice.,..any ideas

<customers>
  <customer>
    <clientname>troy madison</clientfname>
    <invoices>
    <invoiceDate>8/8/98</invoiceDate>
      <product>
         <PriceUnit>1000</PriceUnit>
         <Ordered>2</Ordered>
     </product>
     <product>
         <PriceUnit>5400</PriceUnit>
         <Ordered>3</Ordered>
     </product>
   </invoices>
   <invoices>
     <invoiceDate>1/4/98</invoiceDate>
       <product>
          <PriceUnit>300</PriceUnit>
          <Ordered>4</Ordered>
       </product>
      <product>
        <PriceUnit>6000</PriceUnit>
        <Ordered>1</Ordered>
     </product>
   </invoices>
  <invoices>
    <invoiceDate>03/5/99</invoiceDate>
      <product>
        <PriceUnit>549</PriceUnit>
        <Ordered>1</Ordered>
     </product>
     <product>
       <PriceUnit>320</PriceUnit>
       <Ordered>2</Ordered>
    </product>
   </invoices>
 </customer>
 <customer>
   <clientname>Morris</clientfname>
    <invoices>
      <invoiceDate>1/1/00</invoiceDate>
        <product>
           <PriceUnit>59</PriceUnit>
           <Ordered>3</Ordered>
        </product>
      <product>
          <PriceUnit>55</PriceUnit>
          <Ordered>1</Ordered>
      </product>
    </invoices>
    <invoices>
     <invoiceDate>11/1/01</invoiceDate>
       <product>
         <PriceUnit>10</PriceUnit>
         <Ordered>2</Ordered>
      </product>
      <product>
         <PriceUnit>54</PriceUnit>
         <Ordered>1</Ordered>
       </product>
    </invoices>
    <invoices>
      <invoiceDate>03/2/01</invoiceDate>
        <product>
          <PriceUnit>30</PriceUnit>
          <Ordered>1</Ordered>
        </product>
       <product>
         <PriceUnit>299</PriceUnit>
         <Ordered>1</Ordered>
       </product>
    </invoices>
</customer>

推荐答案

这种转变:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="/*">
  <html>
    <table border="1">
     <thead>
       <tr>
         <td>Name</td><td>Total</td>
       </tr>
     </thead>
     <xsl:apply-templates/>
    </table>
  </html>
 </xsl:template>

 <xsl:template match="customer">
  <tr>
    <td><xsl:value-of select="clientname"/></td>
    <td><xsl:value-of select=
     "sum(invoices/product/(PriceUnit*Ordered))"/></td>
  </tr>
 </xsl:template>
</xsl:stylesheet>

应用于以下 XML 文档时(在纠正严重格式错误的提供文本后获得):

when applied on the following XML document (obtained after correcting the severely malformed provided text):

<customers>
  <customer>
    <clientname>troy madison</clientname>
    <invoices>
    <invoiceDate>8/8/98</invoiceDate>
      <product>
         <PriceUnit>1000</PriceUnit>
         <Ordered>2</Ordered>
     </product>
     <product>
         <PriceUnit>5400</PriceUnit>
         <Ordered>3</Ordered>
     </product>
   </invoices>
   <invoices>
     <invoiceDate>1/4/98</invoiceDate>
       <product>
          <PriceUnit>300</PriceUnit>
          <Ordered>4</Ordered>
       </product>
      <product>
        <PriceUnit>6000</PriceUnit>
        <Ordered>1</Ordered>
     </product>
   </invoices>
  <invoices>
    <invoiceDate>03/5/99</invoiceDate>
      <product>
        <PriceUnit>549</PriceUnit>
        <Ordered>1</Ordered>
     </product>
     <product>
       <PriceUnit>320</PriceUnit>
       <Ordered>2</Ordered>
    </product>
   </invoices>
 </customer>
 <customer>
   <clientname>Morris</clientname>
    <invoices>
      <invoiceDate>1/1/00</invoiceDate>
        <product>
           <PriceUnit>59</PriceUnit>
           <Ordered>3</Ordered>
        </product>
      <product>
          <PriceUnit>55</PriceUnit>
          <Ordered>1</Ordered>
      </product>
    </invoices>
    <invoices>
     <invoiceDate>11/1/01</invoiceDate>
       <product>
         <PriceUnit>10</PriceUnit>
         <Ordered>2</Ordered>
      </product>
      <product>
         <PriceUnit>54</PriceUnit>
         <Ordered>1</Ordered>
       </product>
    </invoices>
    <invoices>
      <invoiceDate>03/2/01</invoiceDate>
        <product>
          <PriceUnit>30</PriceUnit>
          <Ordered>1</Ordered>
        </product>
       <product>
         <PriceUnit>299</PriceUnit>
         <Ordered>1</Ordered>
       </product>
    </invoices>
</customer>
</customers>

产生(只能猜测是什么!!!)想要的结果:

<html>
   <table border="1">
      <thead>
         <tr>
            <td>Name</td>
            <td>Total</td>
         </tr>
      </thead>
      <tr>
         <td>troy madison</td>
         <td>26589</td>
      </tr>
      <tr>
         <td>Morris</td>
         <td>635</td>
      </tr>
   </table>
</html>

这篇关于xslt 汇总发票中的总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆