-4

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>

4

1 回答 1

2

这种转变

<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 文档时(在更正提供的严重格式错误的文本后获得):

<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>
于 2012-09-08T20:35:41.293 回答