产品总数xslt

时间:2012-09-08 16:48:02

标签: xml xslt-2.0

我在处理这个xslt时遇到的困难让我头疼的是总结收据是库存* price.i需要指导我应该如何在xslt表中放入代码以便结果将是一个包含2个办公室的表和每个客户的2个产品的总价值。新的xml和xslt,。请帮助

<offices>
  <office>
    <customerproduct>
      <Price>10</Price>
       <Stock>20</Stock>
       <Ordered>25</Ordered>
    </customerproduct>
    <customerproduct>
      <Price>10</Price>
       <Stock>2</Stock>
       <Ordered>15</Ordered>
    </customerproduct>
   <receiptno.>1</receiptno.>
  </office>
  <office>
    <customerproduct>
      <Price>14</Price>
       <Stock>20</Stock>
       <Ordered>24</Ordered>
    </customerproduct>
    <customerproduct>
      <Price>100</Price>
       <Stock>2</Stock>
       <Ordered>100</Ordered>
    </customerproduct>
  <receiptno.>2</receiptno.>
 </office>
</offices>

1 个答案:

答案 0 :(得分:0)

此转化

<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">
     <xsl:apply-templates/>
    </table>
  </html>
 </xsl:template>

 <xsl:template match="office">
  <tr>
    <td><xsl:value-of select="concat('Office',position())"/></td>
    <td><xsl:value-of select="sum(*/(Price*Stock))"/></td>
  </tr>
 </xsl:template>
</xsl:stylesheet>

应用于以下XML文档(修正多个错误后提供的文字):

<offices>
    <office>
        <customerproduct>
            <Price>10</Price>
            <Stock>20</Stock>
            <Ordered>25</Ordered>
        </customerproduct>
        <customerproduct>
            <Price>10</Price>
            <Stock>2</Stock>
            <Ordered>15</Ordered>
        </customerproduct>
        <receiptno.>1</receiptno.>
    </office>
    <office>
        <customerproduct>
            <Price>14</Price>
            <Stock>20</Stock>
            <Ordered>24</Ordered>
        </customerproduct>
        <customerproduct>
            <Price>100</Price>
            <Stock>2</Stock>
            <Ordered>100</Ordered>
        </customerproduct>
        <receiptno.>2</receiptno.>
    </office>
</offices>

产生(我们可以猜测是什么)想要的结果:

<html>
   <table border="1">
      <tr>
         <td>Office1</td>
         <td>220</td>
      </tr>
      <tr>
         <td>Office2</td>
         <td>480</td>
      </tr>
   </table>
</html>