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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:28:53+00:00 2026-05-13T14:28:53+00:00

I need a loop up to a specific node position() and sum of these

  • 0

I need a loop up to a specific node position() and sum of these nodes. For example:

  • if my position is 2 then node[1] + node[2]
  • if my position is 5 then node[1] + node[2] + node[3] + node[4] + node[5]

How can that be done in XSLT?

do have following xml

<?xml-stylesheet type="text/xsl" href="sum.xsl"?><root><FIDetail Node1="5" Node2="2" Node3="9" Node4="5" Node5="1" Node6="6" Node7="5" Node8="5" Node9="12" Node10="6" Node11="4" Node12="8" Node13="4" Node14="6" Node15="5" Node16="6" Node17="2" Node18="7" Node19="4" Node20="5" Node21="4" Node22="6" Node23="4" Node24="11" Node25="5" Node26="1" Node27="7" Node28="1" Node29="4" Node30="2" Node31="5" Node32="2" Node33="6" Node34="4" Node35="7" Node36="7" Node37="9" Node38="10" Node39="3" Node40="8" Node41="8" Node42="5" Node43="5" Node44="2" Node45="5" Node46="12" Node47="9" Node48="14" Node49="18" Node50="1"/></root>

i am trying to show output as below

5 sum of Node1

7 sum of Node1 + Node2

16 sum of Node1 + Node2 + Node3

…. sum of Node1 + … + Node50

any one please help me that what will be XSL

not working xsl is as below

<?xml version="1.0" encoding="UTF-8"?>

    <xsl:for-each select="//FIDetail/@*">
        <br/>
        <xsl:value-of select="sum(preceding-sibling::*) + ."/>
        =
        <xsl:for-each select="preceding-sibling::*">
            <xsl:value-of select="name()"/> +
        </xsl:for-each>
        <xsl:value-of select="name()"/>
    </xsl:for-each>

</xsl:template>

  • 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-13T14:28:54+00:00Added an answer on May 13, 2026 at 2:28 pm

    You may be able to cobble together a solution that appears to work, but there’s an inherent problem, and your solution is going to break.

    The problem is that attributes in XML don’t have significant order. You can’t rely on attributes being presented to any process, in or out of XSLT, in the same order they appear in the text. Frankly, I’m surprised that XSLT even allows you to use position() in an attribute predicate.

    (Incidentally, this is the reason that the identity transform uses that odd pattern select="node()|@*". The @* is required because node() doesn’t match attributes. node() doesn’t match attributes because attributes aren’t nodes. Nodes have position, and attributes don’t.)

    If your application depends on the ordering of attributes, it’s broken and you need to redesign it.

    There’s a way out, though, if you can rely on the attributes’ names to provide some kind of ordering, as shown in your example:

    <xsl:variable name="atts" select="@*"/>
    <xsl:for-each select="$atts">
      <xsl:sort select="substring-after(name(), 'Node')" data-type="number"/>
      <td>
        <xsl:variable name="this" select="number(substring-after(name(), 'Node'))"/>
        <xsl:value-of select="sum($atts[
                      number(substring-after(name(), 'Node')) &lt;= $this])"/>
      </td>
    </xsl:for-each>
    

    Is that ugly? You bet. And it breaks if you ever change your attribute naming scheme in the slightest. But it’ll work however the attributes are ordered.

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

Sidebar

Related Questions

I need to solve the following question which i can't get to work by
i have a input tag which is non editable, but some times i need
I need to develop a file indexing application in python and wanted to know
I am trying to load a html page through UIWebview.I need to disable all
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
This is beyond both making sense and my control. That being said here is
We manage a site for a medical charity. They have a number of links
I have a login.jsp page which contains a login form. Once logged in the
I have a snippet to create a 'Like' button for our news site: <iframe
Is there a way to test if a collection is already initialized? try-catch only?

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.