[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

XSL grouping from flat XML and putting in table

Posted on 2009-02-15
4
Medium Priority
?
173 Views
Last Modified: 2013-11-18
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

0
Comment
Question by:PugwashXP
  • 3
4 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 23647602
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
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 23647629

<?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
 

Author Closing Comment

by:PugwashXP
ID: 31547218
Best possible type of solution - elegant, clear and brief - many thanks
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 23651627
welcome
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question