[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

How can I recursively summarize grouped by nodes?

Asked by netformx in Extensible Stylesheet Language Transformation (XSLT)

Tags: xslt 2.0, firefox 2.0 , explorer

Hello,
 I have the following XML:
<nodeList >
<node group="chassis" instanceName="7604-RSP720C-P" unitPrice1="60" discount="0.0" quantity="1.0">
            <node instanceName="2700W-DC" unitPrice1="100" discount="0.00" quantity="2.0000" />
            <node instanceName="RSP720-3C-GE" unitPrice1="100" discount="0.00" quantity="3.0000" />
      </node>
<node group="chassis" instanceName="222222222" unitPrice1="100" discount="30.00" /uantity="4.000">
            <node instanceName="1C" unitPrice1="N/A" discount="0.00" quantity="5.0000" />
            <node instanceName="2E" unitPrice1="N/A" discount="0.00" quantity="5.0000" />
      </node>
<node group="chassis" instanceName="333333333" unitPrice1="N/A" discount="0.00" quantity="6.0000">
            <node instanceName="1C" unitPrice1="N/A" discount="0.00" quantity="7.0000" />
            <node instanceName="2E" unitPrice1="N/A" discount="0.00" quantity="8.0000" />
      </node>
</nodeList>

what i would like to do is to summerize the total price of each group and the total price of all the groups (all the nodes).

I managed to count the sum of each group by using the following code:

 <xsl:template match="NfxML/body/nodeList">
 <xsl:for-each select="node[count(.|key('contacts-by-chasi', @instanceName)[1]) = 1]">      
     
          <xsl:variable name="GroupName" select="@instanceName"/>
          <br /><xsl:value-of select="$GroupName" />:
                     <xsl:variable name="TotalSum">
                             <xsl:call-template name="calculator">
                            <xsl:with-param name="curSum">0</xsl:with-param>
                            <xsl:with-param name="counter"><xsl:value-of select="count(descendant-or-self::*)"/></xsl:with-param>
                    </xsl:call-template>
             </xsl:variable>

             <xsl:value-of select="$TotalSum"/>
      <br />
</xsl:for-each>
 </xsl:template>

  <xsl:template name="calculator">
    <xsl:param name="curSum"/>
    <xsl:param name="counter"/>

   
    <xsl:variable name="qty" select="number(descendant-or-self::*[number($counter)]/@quantity)"/>
    <xsl:variable name="cost" select="number(descendant-or-self::*[number($counter)]/@unitPrice1)"/>
    <xsl:variable name="discount" select="number(descendant-or-self::*[number($counter)]/@discount)"/>

    <xsl:variable name="sum" select="number($cost*(100-$discount) div 100 * $qty)"/>
   

    <xsl:variable name="CycleSum">
     <xsl:choose>
        <xsl:when test="string(number($sum)) = 'NaN'">
              <xsl:value-of select="number($curSum)"/>
        </xsl:when>
        <xsl:otherwise>
                <xsl:value-of select="number($curSum + $sum)"/>
        </xsl:otherwise>
      </xsl:choose>            
    </xsl:variable>    

    <xsl:choose>
      <xsl:when test="number($counter - 1) > 0 ">
           
        <xsl:call-template name="calculator">
          <xsl:with-param name="curSum"><xsl:value-of select="$CycleSum"/></xsl:with-param>
          <xsl:with-param name="counter">
            <xsl:value-of select="number($counter - 1)"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$CycleSum"/>
      </xsl:otherwise>
    </xsl:choose>  
  </xsl:template>


 Who can i get the total sum in the most efficient way?

the output I would like to get is:

7604-RSP720C-P: 560
222222222:          280
333333333:          0

Total:                   840

[+][-]09/23/08 06:30 AM, ID: 22549045Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Extensible Stylesheet Language Transformation (XSLT)
Tags: xslt 2.0, firefox 2.0 , explorer
Sign Up Now!
Solution Provided By: Gertone
Participating Experts: 1
Solution Grade: A
 
[+][-]09/23/08 06:45 AM, ID: 22549208Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/23/08 08:41 AM, ID: 22550630Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_2_20070628