We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

XSL grouping from flat XML and putting in table

Medium Priority
193 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

Comment
Watch Question

Gertone (Geert Bormans)Information Architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
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
Information Architect
CERTIFIED EXPERT
Top Expert 2006
Commented:

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Best possible type of solution - elegant, clear and brief - many thanks
Gertone (Geert Bormans)Information Architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
welcome
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.