Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2007, 12:01 PM
Registered User
 
Join Date: Jul 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Don't Know

here's some sample data to try and explain my problem

Input
Code:
<company>
   <unit>
      <unitno>1111</unitno>
      <category>Housewares</categroy>
      <employees>2</employees>
      <sales>
           <periodone>1000</periodone>
           <periodtwo>2000</periodtwo>
           <periodthree>0</periodthree>
           <periodfour>1</periodfour>      
      </sales>
   </unit>
   <unit>
      <unitno>1111</unitno>
      <category>Garden</categroy>
      <employees>1</employees>
      <sales>
           <periodone>400</periodone>
           <periodtwo>200</periodtwo>
           <periodthree>90</periodthree>
           <periodfour>50</periodfour>      
      </sales>
   </unit>
    <unit>
      <unitno>1111</unitno>
      <category>Automotive</categroy>
      <employees>3</employees>
      <sales>
           <periodone>2500</periodone>
           <periodtwo>3000</periodtwo>
           <periodthree>1680</periodthree>
           <periodfour>0</periodfour>      
      </sales>
   </unit>
</company>

Output
periodname sales employees
periodone 3900 6
periodtwo 5200 6
periodthree 1770 4
periodfour 51 3

I have no problem getting the output for the first two columns(periodname,sales). However, if the sales for that period are zero then the employees should be excluded (periodthree, periodfour). I can't figure the way to sum because the predicate that needs to be applied [period1!=0] is a level below the number i want sum(employees). Any help would greatly appreciated!

FYI this is just a sample. In reality the number and name of the children for sales varies. However, I've handled all those issues but this one has me stumped.




 
Old July 20th, 2007, 12:09 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It would be useful to see your existing code to see what approach you are using to the overall structure, this may affect the answer.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 20th, 2007, 12:54 PM
Registered User
 
Join Date: Jul 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i had to replace several things for confidentiality reasons so hopefully i got all the names changes right.

Code:
   <table>
       <xsl:for-each select="msxsl:node-set($unitnodes)/unit[generate-id(.) = generate-id(key('KeyUnit',unit)[1])]" > 
          <xsl:variable name="coid" select="./unitno" />              

              <xsl:for-each select="./sales/*" >
               <xsl:variable name="periodname" select="name(.)" />
               <xsl:variable name="salesamount" select="sum(msxsl:node-set($unitnodes)/unit[unitno=$coid]/sales/*[name()=$periodname])" />                
               <tr> 
                   <td><xsl:value-of select="$coid" /></td>                                                      
                   <td><xsl:value-of select="$periodname" /></td>
                   <td><xsl:value-of select="format-number($salesamount,'###,##0.')"/></td>
                       <xsl:choose>
                          <xsl:when test=". &gt; 0">                             
                             <td><xsl:value-of select="" /></td>                                                      
                          </xsl:when>
                          <xsl:otherwise>
                             <td>0</td>
                          </xsl:otherwise> 
                       </xsl:choose>
            </tr>    
             </xsl:for-each>

       </xsl:for-each>
</table>











Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.