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 9257463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:10:08+00:00 2026-06-18T12:10:08+00:00

I tried for following code but its not working. I have taken one string

  • 0

I tried for following code but its not working. I have taken one string and write XSLT in it and load it XslCompiledTransform object.

 <xsl:sequence select=
        "sum(//Item/(cost * related_id/Item/quantity))"/>

Source XML:

<AML>
  <Item>
    <cost>
      40
    </cost>
    <related_id>
      <Item>
        <quantity>2</quantity>
      </Item>
    </related_id>
  </Item>
  <Item>
    <cost>
      50
    </cost>
    <related_id>
      <Item>
        <quantity>10</quantity>
      </Item>
    </related_id>
  </Item>
</AML>
  • 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-06-18T12:10:09+00:00Added an answer on June 18, 2026 at 12:10 pm

    As I said in the comments, xsl:sequence and that XPath syntax you’re trying to use aren’t available in XSLT 1.0 (which XslCompiledTransform uses), but you can achieve a sum of formulas by using a recursive template:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="text" indent="yes"/>
    
      <xsl:template match="/">
        <xsl:call-template name="SumSet">
          <xsl:with-param name="items" select="/*/Item" />
        </xsl:call-template>
      </xsl:template>
    
      <xsl:template name="SumSet">
        <xsl:param name="items" />
    
        <xsl:if test="$items">
          <xsl:variable name="currentValue">
            <xsl:apply-templates select="$items[1]" />
          </xsl:variable>
          <xsl:variable name="remainderSum">
            <xsl:call-template name="SumSet">
              <xsl:with-param name="items" select="$items[position() > 1]" />
            </xsl:call-template>
          </xsl:variable>
    
          <xsl:value-of select="$currentValue + $remainderSum"/>
        </xsl:if>
        <xsl:if test="not($items)">0</xsl:if>
      </xsl:template>
    
      <xsl:template match="Item">
        <xsl:value-of select="cost * related_id/Item/quantity"/>
      </xsl:template>
    </xsl:stylesheet>
    

    When this is run on your input XML, the result is:

    580
    

    That would be the generic approach, but since you’ve mentioned that you’re using XslCompiledTransform, you can use msxsl:node-set() to simplify this task a bit:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:msxsl="urn:schemas-microsoft-com:xslt">
      <xsl:output method="text" indent="yes"/>
    
      <xsl:template match="/">
        <xsl:variable name="values">
          <xsl:apply-templates select="/*/Item" />
        </xsl:variable>
    
        <xsl:value-of select="sum(msxsl:node-set($values)/*)"/>
      </xsl:template>
    
      <xsl:template match="Item">
        <itemValue>
          <xsl:value-of select="cost * related_id/Item/quantity"/>
        </itemValue>
      </xsl:template>
    </xsl:stylesheet>
    

    This also produces the value 580 when run on your input XML.

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

Sidebar

Related Questions

I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,
I have tried for unload and beforeunload binding in following code, but none of
I want to use regex in ng-repeat. I have tried the following code but
I have following code for the UIAlertView Loading indicator which is not working and
I tried to control email address and reviewer's name with the following code but
I just tried the following code, but the result seems a little strange. It
I tried using the following code for a HTML page, but it doesn't work.
How can I iterate ResultSet ? I've tried with the following code, but i
I tried running the following python code in Eclipse on Windows but it is
I tried following some of the code from here and here , but I

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.