Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 345315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:04:21+00:00 2026-05-12T11:04:21+00:00

I have the following XML source structure: <turnovers> <turnover repid=1 amount=500 rate=0.1/> <turnover repid=5

  • 0

I have the following XML source structure:

<turnovers>
    <turnover repid="1" amount="500" rate="0.1"/>
    <turnover repid="5" amount="600" rate="0.5"/>
    <turnover repid="4" amount="400" rate="0.2"/>
    <turnover repid="1" amount="700" rate="0.05"/>
    <turnover repid="2" amount="100" rate="0.15"/>
    <turnover repid="1" amount="900" rate="0.25"/>
    <turnover repid="2" amount="1000" rate="0.18"/>
    <turnover repid="5" amount="200" rate="0.55"/>
    <turnover repid="9" amount="700" rate="0.40"/>
</turnovers>

I need an XSL:value-of select statement that will return the sum of the product of the rate attribute and the amount attribute for a given rep ID. So for rep 5 I need ((600 x 0.5) + (200 x 0.55)).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:04:21+00:00Added an answer on May 12, 2026 at 11:04 am
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
      <xsl:template match="/turnovers">
        <val>
          <!-- call the sum function (with the relevant nodes) -->
          <xsl:call-template name="sum">
            <xsl:with-param name="nodes" select="turnover[@repid='5']" />
          </xsl:call-template>
        </val>
      </xsl:template>
    
      <xsl:template name="sum">  
        <xsl:param name="nodes" />
        <xsl:param name="sum" select="0" />
    
        <xsl:variable name="curr" select="$nodes[1]" />
    
        <!-- if we have a node, calculate & recurse -->
        <xsl:if test="$curr">
          <xsl:variable name="runningsum" select="
            $sum + $curr/@amount * $curr/@rate
          " />
          <xsl:call-template name="sum">
            <xsl:with-param name="nodes" select="$nodes[position() &gt; 1]" />
            <xsl:with-param name="sum"   select="$runningsum" />
          </xsl:call-template>
        </xsl:if>
    
        <!-- if we don't have a node (last recursive step), return sum -->
        <xsl:if test="not($curr)">
          <xsl:value-of select="$sum" />
        </xsl:if>
    
      </xsl:template>
    </xsl:stylesheet>
    

    Gives:

    <val>410</val>
    

    The two <xsl:if>s can be replaced by a single <xsl:choose>. This would mean one less check during the recursion, but it also means two additional lines of code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML :- <inventory> <item> <name_element> <!--some structure--> </name_element> <some_element1>val1</some_element1> <some_element2>val2</some_element2>
I have an XML file with the following structure: <Products> <Product name=MyProduct1> <Components> <Component
Say i have the following XML: <app-deployment> <name>gr1</name> <target>AdminServer</target> <module-type>ear</module-type> <source-path>/u01/app/wls1035_homes/wls1035_9999/grc864</source-path> <security-dd-model>DDOnly</security-dd-model> <staging-mode>stage</staging-mode> </app-deployment>
I have the following: <xs:attribute name=CarTitleID type=xs:long use=optional /> In my source XML I
I have following source xml <forms> <x> <y> <x-component select=foobar /> </y> </x> <component
I have an XML file of the following structure: <?xml version=1.0 encoding=utf-8?> <root> <ArrayOfLocationDTO
I have the following XML code that I grab from an external site: <source>
i have the following xml structure and want to add it to a treeview.
I have the following source layout: . ├── pom.xml ├── modules (has pom) │
I have following xml and I want to fetch the value of node which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.