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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:09:28+00:00 2026-06-13T20:09:28+00:00

I have an XML that generates a transaction file, it records entries from a

  • 0

I have an XML that generates a transaction file, it records entries from a Clubcard of how much was spent to earn points and the date it was done. There is no order that I can use as the same card number may appear further in the XML. What I would like is to get the XSL to find a card number (which I do not have a record of to use as an ID), put it in a <td></td> and show how much in total was spent, how much points were earned and what date it was done.

This is the XML…

<Root>
  <Events>
    <TicketEnd Date="2012-10-21" />
  </Events>
  <Ticket>
    <TicketStart Date="2012-10-22" />
    <TicketEnd Date="2012-10-22" />
  </Ticket>
  <Events>
  </Events>
  <Ticket>
    <TicketStart Date="2012-10-22" />
    <Clubcard Opcode="96" Function="27" CardAcc="1" QualSpendInfo="0" SchemeNo="40" CardNo="1042540000026" PointsToDate="0" RedemptionValue="0" CustomerUpdateDate="000000" QualSpent="0" Date="2012-10-22" />
    <ClubcardPoints Opcode="96" Function="28" SchemeNo="40" PromNo="0" CardNo="1042540000026" QualSpend="30005" PointSpend="0" Points="6" BonusPoints="0" PromCount="0" Date="2012-10-22" />
    <Clubcard Opcode="96" Function="27" CardAcc="1" QualSpendInfo="1" SchemeNo="40" CardNo="1042540000026" PointsToDate="0" RedemptionValue="0" CustomerUpdateDate="000000" QualSpent="30005" Date="2012-10-22" />
    <TicketEnd Date="2012-10-22" />
  </Ticket>
  <Ticket>
    <TicketStart Date="2012-10-22" />
    <Clubcard Opcode="96" Function="27" CardAcc="1" QualSpendInfo="0" SchemeNo="40" CardNo="1042540000019" PointsToDate="0" RedemptionValue="0" CustomerUpdateDate="000000" QualSpent="0" Date="2012-10-22" />
    <ClubcardPoints Opcode="96" Function="28" SchemeNo="40" PromNo="0" CardNo="1042540000019" QualSpend="24330" PointSpend="0" Points="4" BonusPoints="0" PromCount="0" Date="2012-10-22" />
    <Clubcard Opcode="96" Function="27" CardAcc="1" QualSpendInfo="1" SchemeNo="40" CardNo="1042540000019" PointsToDate="0" RedemptionValue="0" CustomerUpdateDate="000000" QualSpent="24330" Date="2012-10-22" />
    <TicketEnd Date="2012-10-22" />
  </Ticket>
  <Ticket>
    <TicketStart Date="2012-10-22" />
    <Clubcard Opcode="96" Function="27" CardAcc="1" QualSpendInfo="0" SchemeNo="40" CardNo="1042540000026" PointsToDate="0" RedemptionValue="0" CustomerUpdateDate="000000" QualSpent="0" Date="2012-10-22" />
    <ClubcardPoints Opcode="96" Function="28" SchemeNo="40" PromNo="0" CardNo="1042540000026" QualSpend="30005" PointSpend="0" Points="6" BonusPoints="0" PromCount="0" Date="2012-10-22" />
    <Clubcard Opcode="96" Function="27" CardAcc="1" QualSpendInfo="1" SchemeNo="40" CardNo="1042540000026" PointsToDate="0" RedemptionValue="0" CustomerUpdateDate="000000" QualSpent="30005" Date="2012-10-22" />
    <TicketEnd Date="2012-10-22" />
  </Ticket>
</Root>

My XSL can only list the entries…

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>
  <xsl:template match="/">
    <html>
      <head>
    <title>Loyalty Sales</title>
      </head>
    <body>
      <br/>
      <br/>
      <br/>
       <h1 style="color:blue;
                  margin-left:20px;
                  font-family:verdana;
                  text-align:center;">
        Customers Report</h1>
      <br/>
      <p style="color:red;
                margin-left:20px;
                font-family:arial;
                text-align:right;
                font-size:15px;">
        Store Report</p>
      <p style="color:green;
                margin-left:20px;
                font-family:arial;
                text-align:right;
                font-size:15px;">
        for Customer ABC</p>
      <br/>
    <table width="100%" border="3">
      <THEAD>
      <TR bgcolor="RGB(0, 204, 51)">
      <TD width="25%">
        <font color="white"><B>Account Number</B></font>
      </TD>
      <TD width="25%">
        <font color="white"><B>Points</B></font>
      </TD>
      <TD width="25%">
        <font color="white"><B>Date</B></font>
      </TD>
      <TD width="25%">
        <font color="white"><B>Qualified Spent</B></font>
      </TD>
      </TR>
      </THEAD>
    <TBODY>
    <xsl:for-each select="Root/Ticket/ClubcardPoints">
      <TR>
      <TD width="25%"><xsl:value-of select="@CardNo" /></TD>
      <TD width="25%"><xsl:value-of select="@Points" /></TD>
      <TD width="25%"><xsl:value-of select="@Date" /></TD>
      <TD width="25%"><xsl:value-of select="format-number(@QualSpend div 100,'&#x52;#.##')" /></TD>
    </TR>
    </xsl:for-each>
    </TBODY>
    </table>
  </body>
</html>
</xsl:template>
</xsl:stylesheet>

I have searched for examples but cannot find a scenario that has all these conditions and when put to a single XSL it fails.
Please help.

Here is the output file I would like to have…

<THEAD>
                <TR bgcolor="RGB(0, 204, 51)">
                    <TD width="25%"><font color="white"><B>Account Number</B></font></TD>
                    <TD width="25%"><font color="white"><B>Total Points</B></font></TD>
                    <TD width="25%"><font color="white"><B>Date</B></font></TD>
                    <TD width="25%"><font color="white"><B>Total Qualified Spent</B></font></TD>
                </TR>
            </THEAD>
            <TBODY>
                <TR>
                    <TD width="25%">1042540000002</TD>
                    <TD width="25%">100</TD>
                    <TD width="25%">2012-10-22</TD>
                    <TD width="25%">R750.32</TD>
                </TR>
  • 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-13T20:09:29+00:00Added an answer on June 13, 2026 at 8:09 pm

    If you want to total each card’s points and spend, then you will need to group the cards by their card number. In XSLT1.0, you use Munechian Grouping for this. This means defining a key for your group

    <xsl:key name="cards" match="ClubcardPoints" use="@CardNo" />
    

    Then, to select each distinct card number, you look for ClubcardPoints which occur first in the group for their card number. This is done as follows

    <xsl:apply-templates 
       select="Root/Ticket/ClubcardPoints[generate-id() = generate-id(key('cards', @CardNo)[1])]" />
    

    Getting the total points is then straight-forward

    <xsl:value-of select="sum(key('cards', @CardNo)/@Points)" />
    

    Here is the full XSLT (Note that I’ve simplified it to remove all the styling)

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="html"/>
       <xsl:key name="cards" match="ClubcardPoints" use="@CardNo"/>
    
       <xsl:template match="/">
          <table>
             <THEAD>
                <TR>
                   <TD>Account Number</TD>
                   <TD>Points</TD>
                   <TD>Date</TD>
                   <TD>Qualified Spent</TD>
                </TR>
             </THEAD>
             <TBODY>
                <xsl:apply-templates select="Root/Ticket/ClubcardPoints[generate-id() = generate-id(key('cards', @CardNo)[1])]"/>
             </TBODY>
          </table>
       </xsl:template>
    
       <xsl:template match="ClubcardPoints">
          <TR>
             <TD>
                <xsl:value-of select="@CardNo"/>
             </TD>
             <TD>
                <xsl:value-of select="sum(key('cards', @CardNo)/@Points)"/>
             </TD>
             <TD>
                <xsl:value-of select="@Date"/>
             </TD>
             <TD>
                <xsl:value-of select="format-number(sum(key('cards', @CardNo)/@QualSpend) div 100,'R#.##')"/>
             </TD>
          </TR>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    <table>
       <THEAD>
          <TR>
             <TD>Account Number</TD>
             <TD>Points</TD>
             <TD>Date</TD>
             <TD>Qualified Spent</TD>
          </TR>
       </THEAD>
       <TBODY>
          <TR>
             <TD>1042540000026</TD>
             <TD>12</TD>
             <TD>2012-10-22</TD>
             <TD>R600.1</TD>
          </TR>
          <TR>
             <TD>1042540000019</TD>
             <TD>4</TD>
             <TD>2012-10-22</TD>
             <TD>R243.3</TD>
          </TR>
       </TBODY>
    </table>
    

    Note that, in XSLT2.0, grouping would be done by using the xsl:for-each-group element.

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

Sidebar

Related Questions

I have a T4 template that generates classes from an xml file. How can
Right now I have an application that generates an XML file. We'll call it
I have an application that generates a lengthy Xml output file which contains many
So I have a sql database that generates an xml file. This xml file
I have written an IronPython script that generates a xml file that contains the
I have built an application that generates a large XML file using Linq-to-Entities and
I have an application that generates xml files, and they might contain special characters.
I have a 3rd Party tool that generates an xml spreadsheet (*.xls). I have
I have an XML document that I generate from an Entity Framework object. The
I have generated an XML file that and one of the nodes contains data

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.