XSL grouping from flat XML and putting in table

From the XML structure in the code section I want to create the folllowing table:
Account number      1017132
Start date            End date
29/01/2001            29/01/2003
29/01/2003            29/01/2005
29/01/2005            -

Account number      3845870
Start date            End date
18/08/2004            18/08/2005
18/08/2005            18/08/2006
18/08/2006            -

using XSL.

I used the sort field via a template call and attempted to group using x-path preceding but I cannot get either the grouping or the table structures to work.

HELP and thanks
<?xml version="1.0" encoding="utf-8"?>
<__Message2 xmlns:Namespace="http://viceroy/">
	<SubscriptionList>
		<tblHODR_Subscription>
			<txtAccountNumber>3845870</txtAccountNumber>
			<dtFromDate>18/08/2004</dtFromDate>
			<dtToDate>18/08/2005</dtToDate>
			<dtAccountCreationDateSort>38458702004-08-18T00:00:002004-08-18T00:00:00</dtAccountCreationDateSort>
		</tblHODR_Subscription>
		<tblHODR_Subscription>
			<txtAccountNumber>1017132</txtAccountNumber>
			<dtFromDate>29/01/2001</dtFromDate>
			<dtToDate>29/01/2003</dtToDate>
			<dtAccountCreationDateSort>10171322001-01-29T00:00:002001-01-29T00:00:00</dtAccountCreationDateSort>
		</tblHODR_Subscription>
		<tblHODR_Subscription>
			<txtAccountNumber>3845870</txtAccountNumber>
			<dtFromDate>18/08/2005</dtFromDate>
			<dtToDate>18/08/2006</dtToDate>
			<dtAccountCreationDateSort>38458702004-08-18T00:00:002005-08-18T00:00:00</dtAccountCreationDateSort>
		</tblHODR_Subscription>
		<tblHODR_Subscription>
			<txtAccountNumber>1017132</txtAccountNumber>
			<dtFromDate>29/01/2003</dtFromDate>
			<dtToDate>29/01/2005</dtToDate>
			<dtAccountCreationDateSort>10171322001-01-29T00:00:002003-01-29T00:00:00</dtAccountCreationDateSort>
		</tblHODR_Subscription>
		<tblHODR_Subscription>
			<txtAccountNumber>1017132</txtAccountNumber>
			<dtFromDate>29/01/2005</dtFromDate>
			<dtToDate/>
			<dtAccountCreationDateSort>10171322001-01-29T00:00:002005-01-29T00:00:00</dtAccountCreationDateSort>
		</tblHODR_Subscription>
		<tblHODR_Subscription>
			<txtAccountNumber>3845870</txtAccountNumber>
			<dtFromDate>18/08/2006</dtFromDate>
			<dtToDate/>
			<dtAccountCreationDateSort>38458702004-08-18T00:00:002006-08-18T00:00:00</dtAccountCreationDateSort>
		</tblHODR_Subscription>
	</SubscriptionList>
</__Message2>

Open in new window

PugwashXPAsked:
Who is Participating?
 
Geert BormansInformation ArchitectCommented:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output indent="yes"/>
    <xsl:key name="hodr" match="tblHODR_Subscription" use="txtAccountNumber"/>
    <xsl:template match="SubscriptionList">
        <xsl:for-each select="tblHODR_Subscription[generate-id() = generate-id(key('hodr',txtAccountNumber)[1])]">
            <xsl:sort select="txtAccountNumber" data-type="number"/>
            <h3><xsl:value-of select="txtAccountNumber"/></h3>
            <table>
                <tr>
                    <th>Start Date</th>
                    <th>End Date</th>
                </tr>
                <xsl:for-each select="key('hodr',txtAccountNumber)">
                    <tr>
                        <td><xsl:value-of select="dtFromDate"/></td>
                        <td><xsl:value-of select="dtToDate"/></td>
                    </tr>
                </xsl:for-each>
            </table>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
There is a pattern for dealing with grouping in XSLT
http://www.jenitennison.com/xslt/grouping/muenchian.xml
I will work this out in a minute, but it gives you some reading
0
 
PugwashXPAuthor Commented:
Best possible type of solution - elegant, clear and brief - many thanks
0
 
Geert BormansInformation ArchitectCommented:
welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.