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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:08:12+00:00 2026-06-17T14:08:12+00:00

suppose that the structure of my xml file is: <?xml version=1.0 encoding=ISO-8859-1?> <main> <_All>

  • 0

suppose that the structure of my xml file is:

 <?xml version="1.0" encoding="ISO-8859-1"?>
<main>
    <_All>
        <_999999>
            <Employee_Amount>10.0</Employee_Amount>
            <Cash_Count>10.0</Cash_Count>
            <Dine_in_Amount>10.0</Dine_in_Amount>
            <Promos_Actual>10.0</Promos_Actual>
            <Combo_Savings_Amount>10.0</Combo_Savings_Amount>
            <total_sales>10.0</total_sales>
            </_999999>
        <_test>
            <Employee_Amount>20.0</Employee_Amount>
            <Cash_Count>20.0</Cash_Count>
            <Dine_in_Amount>20.0</Dine_in_Amount>
            <Promos_Actual>20.0</Promos_Actual>
            <Combo_Savings_Amount>20.0</Combo_Savings_Amount>
            <total_sales>20.0</total_sales>
            </_test>
    </_All>
</main>

I have to sum all the nodes (for example – Cash_Count of both the nodes,total_sales of both the nodes), the node name can be change so I cannot use its name to navigate. I have tried for-each but i stuck with the xpath expressions. since I am new to xslt 1.0, Please help me for the same.

I have tried with the below xslt with the help of what proskor suggested me in the answers:

<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="html" indent="yes"/>
  <xsl:template match="/*">
    <table border="1" cellspacing="1" cellpadding="1">
        <tr>
            <xsl:apply-templates select="/*/*/*" mode="wrap"/>
        </tr>
        <tr>
        <td><xsl:value-of select="name(child::*)"/></td>
        <td>&#160;</td>
        <xsl:for-each select="/*/*/*/*[current()]">
                          <xsl:variable name="pos" select="position()" />
                         <td> <xsl:value-of select="sum(/*/*/*/*[$pos])" /></td>
                  </xsl:for-each>
        </tr>
        <xsl:apply-templates select="/*/*/*" mode="values"/>
    </table>
  </xsl:template>

 <xsl:template match="/*/*/*" mode="wrap">
    <xsl:if test="position() = 1">
    <th>Region</th>
    <th>Store</th>
    <xsl:for-each select="./*">
    <th><xsl:value-of select="name()"/></th>
    </xsl:for-each>
    </xsl:if>
</xsl:template>
<xsl:template match="/*/*/*" mode="values">
    <xsl:for-each select=".">
        <tr>
            <td>&#160;</td>
            <td><xsl:value-of select="name()"/></td>
            <xsl:for-each select="./*">
            <td><xsl:value-of select="."/></td>
            </xsl:for-each>
        </tr>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

it worked fine but produses output with extra td with values 0 to it. since there are 6 nodes hence there are 6 extra td with the value 0 to it.
after sum this tr looks like this..

<tr>
<td>30</td>
<td>30</td>
<td>30</td>
<td>30</td>
<td>30</td>
<td>30</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>

Please anyone help to figure it out. Thanks

  • 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-17T14:08:13+00:00Added an answer on June 17, 2026 at 2:08 pm

    Change the select-attribute of the xsl:for-each element on line 14 to "/*[1]/*[1]/*[1]/*":

    <?xml version="1.0" encoding="US-ASCII"?>
    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">
      <xsl:output method="html" indent="yes"/>
      <xsl:template match="/*">
        <table border="1" cellspacing="1" cellpadding="1">
            <tr>
                <xsl:apply-templates select="/*/*/*" mode="wrap"/>
            </tr>
            <tr>
            <td><xsl:value-of select="name(child::*)"/></td>
            <td>&#160;</td>
            <xsl:for-each select="/*[1]/*[1]/*[1]/*">
                              <xsl:variable name="pos" select="position()" />
                             <td> <xsl:value-of select="sum(/*/*/*/*[$pos])" /></td>
                      </xsl:for-each>
            </tr>
            <xsl:apply-templates select="/*/*/*" mode="values"/>
        </table>
      </xsl:template>
    
     <xsl:template match="/*/*/*" mode="wrap">
        <xsl:if test="position() = 1">
        <th>Region</th>
        <th>Store</th>
        <xsl:for-each select="./*">
        <th><xsl:value-of select="name()"/></th>
        </xsl:for-each>
        </xsl:if>
    </xsl:template>
    <xsl:template match="/*/*/*" mode="values">
        <xsl:for-each select=".">
            <tr>
                <td>&#160;</td>
                <td><xsl:value-of select="name()"/></td>
                <xsl:for-each select="./*">
                <td><xsl:value-of select="."/></td>
                </xsl:for-each>
            </tr>
        </xsl:for-each>
    </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's suppose we have the XML file with the structure as follows. <?xml version=1.0
My XML file consists of a structure that resembles something like the following: <root>
Suppose I have code that maintains a parent/children structure. In such a structure I
Suppose that we have file like this: sometext11 sometext12 sometext13 sometext21 sometext22 sometext23 Texts
Suppose that I have a trie data structure holding a number of strings. To
Suppose I have a directory structure like the following /a/b/testB.xml /a/c/testC.xml /a/testD.xml and I
Suppose there is a simple XML file as below: <a> <b>hello</b> <c>world</c> </a> I
Suppose I get the following XML structure: <root> <item> <item1>text1</item1> <item2>text2</item2> more text here
I have the following json and suppose that I can't modify it: { structure:
I have XML data in a tree structure that has an variable depth. Sometimes

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.