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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:41:36+00:00 2026-06-17T17:41:36+00:00

I have the following xml whose structure is same but the nodes and there

  • 0

I have the following xml whose structure is same but the nodes and there values can be diffrent :

    <?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<main>
    <_All>
        <_001372>
            <_2012-Oct-10>
                <Employee_Amount>1.0</Employee_Amount>
                <Combo_Savings_Amount>2.0</Combo_Savings_Amount>
                <Total_Sales>3.0</Total_Sales>
                <Dine_in_Amount>4.0</Dine_in_Amount>
                <Promos_Actual>5.0</Promos_Actual>
                <Cash_Count>6.0</Cash_Count>
                </_2012-Oct-10>
            <_2012-Oct-11>
                <Employee_Amount>7.0</Employee_Amount>
                <Combo_Savings_Amount>0.0</Combo_Savings_Amount>
                <Total_Sales>0.0</Total_Sales>
                <Dine_in_Amount>0.0</Dine_in_Amount>
                <Promos_Actual>0.0</Promos_Actual>
                <Cash_Count>0.0</Cash_Count>
                </_2012-Oct-11>
            </_001372>
        <_024139>
            <_2012-Oct-10>
                <Employee_Amount>0.0</Employee_Amount>
                <Combo_Savings_Amount>313.148999999997</Combo_Savings_Amount>
                <Total_Sales>3515.5</Total_Sales>
                <Dine_in_Amount>543.86</Dine_in_Amount>
                <Promos_Actual>0.0</Promos_Actual>
                <Cash_Count>330.0</Cash_Count>
                </_2012-Oct-10>
            <_2012-Oct-11>
                <Employee_Amount>10.0</Employee_Amount>
                <Combo_Savings_Amount>17.0</Combo_Savings_Amount>
                <Total_Sales>5.0</Total_Sales>
                <Dine_in_Amount>7.0</Dine_in_Amount>
                <Promos_Actual>0.0</Promos_Actual>
                <Cash_Count>20.0</Cash_Count>
                </_2012-Oct-11>
            </_024139>
        <_101010>
            <_2012-Oct-10>
                <Employee_Amount>5.0</Employee_Amount>
                <Combo_Savings_Amount>0.0</Combo_Savings_Amount>
                <Total_Sales>0.0</Total_Sales>
                <Dine_in_Amount>0.0</Dine_in_Amount>
                <Promos_Actual>0.0</Promos_Actual>
                <Cash_Count>0.0</Cash_Count>
                </_2012-Oct-10>
            <_2012-Oct-11>
                <Employee_Amount>0.0</Employee_Amount>
                <Combo_Savings_Amount>0.0</Combo_Savings_Amount>
                <Total_Sales>0.0</Total_Sales>
                <Dine_in_Amount>0.0</Dine_in_Amount>
                <Promos_Actual>0.0</Promos_Actual>
                <Cash_Count>0.0</Cash_Count>
                </_2012-Oct-11>
            </_101010>
    </_All>
</main>

I need to sum all the elements of a store. for example i need to sum Employee_Amount of dates date01 and date02. same as all the nodes. What I have try is as below :

<?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"
            align="center">
            <tr bgcolor="#8181F7">
                <xsl:apply-templates select="/*/*/*/*" mode="ColHeader" />
            </tr>
            <tr bgcolor="#00FFFF">
                <td>
                    <xsl:value-of
                        select="translate(name(child::*),'_',' ')" />
                </td>
                <td>&#160;</td>
                <xsl:for-each select="/*[1]/*[1]/*[1]/*[1]/*">
                    <xsl:variable name="pos" select="position()" />
                    <td>
                        <xsl:value-of
                            select='format-number(sum(/*/*/*/*/*[$pos]),"#.##")' />
                    </td>
                </xsl:for-each>
            </tr>
            <xsl:apply-templates select="/*/*/*" mode="values" />
        </table>
    </xsl:template>

    <xsl:template match="/*/*/*/*" mode="ColHeader">
        <xsl:if test="position() = 1">
            <th>Region</th>
            <th>Store</th>
            <xsl:for-each select="./*">
                <th>
                    <xsl:value-of select="translate(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="translate(name(),'_',' ')" />
                </td>
                <xsl:apply-templates select="./*/*" mode="rollupVal"/>
            </tr>
        </xsl:for-each>
    </xsl:template>
    <xsl:template match="/*/*/*/*/*" mode="rollupVal">
        <xsl:variable name="pos1" select="current()"/>
                    <td>
                        <xsl:value-of select='format-number(sum(./node()[$pos1]), "#.##")'/>
                    </td>
    </xsl:template>
</xsl:stylesheet>

But I am unable to sum those rows. Please help me. Thanks

Edited: The output HTML is:

<table align="center" cellpadding="1" cellspacing="1" border="1">
    <tr bgcolor="#8181F7">
    <th>Region</th><th>Store</th><th>Employee Amount</th><th>Combo Savings Amount</th><th>Total Sales</th><th>Dine in Amount</th><th>Promos Actual</th><th>Cash Count</th>
    </tr>
    <tr bgcolor="#00FFFF">
        <td> All</td>
        <td>&nbsp;</td>
        <td>18</td>
        <td>332.15</td>
        <td>3523.5</td>
        <td>554.86</td>
        <td>5</td>
        <td>356</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td> 001372 44CLOSED</td>
        <td>8</td>
        <td>2</td>
        <td>3</td>
        <td>4</td>
        <td>5</td>
        <td>6</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td> 024139</td>
        <td>10</td>
        <td>330.15</td>
        <td>3520.5</td>
        <td>550.86</td>
        <td>0</td>
        <td>350</td>
    </tr>
</table>
  • 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-17T17:41:37+00:00Added an answer on June 17, 2026 at 5:41 pm

    This XSL is still a bit of a mess, but it seems to produce the expected output:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
      <xsl:output method="html" indent="yes" />
      <xsl:key name="field" match="/*/*/*/*/*" use="local-name()" />
      <xsl:variable name="fieldGroups" select="/*/*/*/*/*[generate-id() = generate-id(key('field', local-name())[1])]" />
    
      <xsl:template match="/*">
        <table border="1" cellspacing="1" cellpadding="1"
            align="center">
          <tr bgcolor="#8181F7">
            <!-- First date node -->
            <xsl:call-template name="ColHeaders" />
          </tr>
          <!-- All node -->
          <xsl:apply-templates select="*" mode="GrandTotal" />
          <!-- Each store -->
          <xsl:apply-templates select="*/*" mode="values" />
        </table>
      </xsl:template>
    
      <xsl:template name="EmptyCell">
        <td>&#160;</td>
      </xsl:template>
    
      <xsl:template match="/*/*" mode="GrandTotal">
        <tr bgcolor="#00FFFF">
          <td>
            <xsl:value-of select="translate(name(.),'_',' ')" />
          </td>
          <xsl:call-template name="EmptyCell" />
          <!-- Each field of first date -->
          <xsl:apply-templates select="$fieldGroups" mode="FieldTotal" />
        </tr>
      </xsl:template>
    
      <xsl:template match='/*/*/*/*/*' mode='FieldTotal'>
        <xsl:variable name="pos" select="position()" />
        <td>
          <xsl:value-of select='format-number(sum(key("field", local-name())),"0.##")' />
        </td>
      </xsl:template>
    
      <xsl:template name="ColHeaders">
        <th>Region</th>
        <th>Store</th>
        <xsl:apply-templates select="$fieldGroups" mode="ColHeader" />
      </xsl:template>
    
      <xsl:template match="*" mode="ColHeader">
        <th>
          <xsl:value-of select="translate(name(),'_',' ')" />
        </th>
      </xsl:template>
    
      <!-- Matches stores -->
      <xsl:template match="/*/*/*" mode="values">
        <tr>
          <xsl:call-template name="EmptyCell" />
          <td>
            <!-- Store code -->
            <xsl:value-of select="translate(name(),'_',' ')" />
          </td>
          <!-- All fields in first date -->
          <xsl:apply-templates select="*[1]/*" mode="rollupVal"/>
        </tr>
      </xsl:template>
    
      <xsl:template match="/*/*/*/*/*" mode="rollupVal">
        <xsl:variable name="pos1" select="position()"/>
        <td>
          <xsl:value-of select='format-number(sum(../../*/*[$pos1]), "0.##")'/>
        </td>
      </xsl:template>
    </xsl:stylesheet>
    

    output:

    <table border="1" cellspacing="1" cellpadding="1" align="center">
      <tr bgcolor="#8181F7">
        <th>Region</th>
        <th>Store</th>
        <th>Employee Amount</th>
        <th>Combo Savings Amount</th>
        <th>Total Sales</th>
        <th>Dine in Amount</th>
        <th>Promos Actual</th>
        <th>Cash Count</th>
      </tr>
      <tr bgcolor="#00FFFF">
        <td> All</td>
        <td> </td>
        <td>18</td>
        <td>332.14</td>
        <td>3523.5</td>
        <td>554.86</td>
        <td>5</td>
        <td>356</td>
      </tr>
      <tr>
        <td> </td>
        <td> store01</td>
        <td>8</td>
        <td>2</td>
        <td>3</td>
        <td>4</td>
        <td>5</td>
        <td>6</td>
      </tr>
      <tr>
        <td> </td>
        <td> store02</td>
        <td>10</td>
        <td>330.14</td>
        <td>3520.5</td>
        <td>550.86</td>
        <td>0</td>
        <td>350</td>
      </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have xml file whose structure is defined with following xsd: <?xml version=1.0 encoding=utf-8?>
I have the following xml structure : <?xml version=1.0 encoding=utf-8 ?> <nws> <url>http://cpa.hypotheses.org/feed</url> <url>http://news.ycombinator.com/rss</url>
I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
I have following XML. I was able to remove all namespaces but not able
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
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
I have a need to serialize a Clojure data structure to XML, but I'm
I have to following XML document structure: <option_set id=1> <option>Yes</option> <option>No</option> <option>Maybe</option> </option_set> <question
I have an XML file of the following structure <Root> <Child Name=First> <Data Name=a

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.