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,'R#.##')" /></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>
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
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
Getting the total points is then straight-forward
Here is the full XSLT (Note that I’ve simplified it to remove all the styling)
When applied to your sample XML, the following is output
Note that, in XSLT2.0, grouping would be done by using the xsl:for-each-group element.