Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Sorting with Muenchian Method

From: aleksander.hansen@-----.---
To: NULL
Date: 11/3/2006 5:08:00 AM

Hello, I have xml data that I need to group and sort. I have tried
grouping it using the Muenchian Method. Probably not solved the best
way, but it works. But I can't get the sorting right.

Here's my XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="channel.xslt"?>
<SearchResults>
	<SearchHit>
		<article>
			<field name="KANAL">
				<category path="//TV//Channels//Channel1" id="1"/>
			</field>
			<field name="TITTEL">Program 1</field>
			<field name="SCHEDULE">
			<schedule startTime="2400"/></field>
		</article>
		<article>
			<field name="KANAL">
				<category path="//TV//Channels//Channel2" id="2"/>
			</field>
			<field name="TITTEL">Program 2</field>
			<field name="SCHEDULE">
			<schedule startTime="0900"/></field>
		</article>
		<article>
			<field name="KANAL">
				<category path="//TV//Channels//Channel2" id="2"/>
			</field>
			<field name="TITTEL">Program 3</field>
			<field name="SCHEDULE">
			<schedule startTime="1100"/></field>
		</article>
		<article>
			<field name="KANAL">
				<category path="//TV//Channels//Channel2" id="2"/>
			</field>
			<field name="TITTEL">Program 4</field>
			<field name="SCHEDULE">
			<schedule startTime="1000"/></field>
		</article>
		<article>
			<field name="KANAL">
				<category path="//TV//Channels//Channel1" id="1"/>
			</field>
			<field name="TITTEL">Program 5</field>
			<field name="SCHEDULE">
			<schedule startTime="2100"></schedule></field>
		</article>
	</SearchHit>
</SearchResults>

Here's my XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" version="1.0" encoding="utf-16"
indent="yes"/>
	<xsl:key name="kChannel" match="article/field[@name='KANAL']/category"
use="@path" />
	<xsl:output method="html"/>
	<xsl:template match="SearchResults/SearchHit">
	<xsl:for-each
select="article/field[@name='KANAL']/category[generate-id()=generate-id(key('kChannel',
@path))]">
		<xsl:variable name="theArticle"
select="current()/parent::node()/parent::node()" />
		<xsl:variable name="ChannelName" select="@path" />
		<xsl:value-of select="$ChannelName" /><br/>
		<xsl:apply-templates
select="/SearchResults/SearchHit/article/field/category[@path =
current()/@path]" />
	</xsl:for-each>
	</xsl:template>

	<xsl:template match="category">
		<xsl:variable name="theArticle"
select="current()/parent::node()/parent::node()" />
		<xsl:value-of select="$theArticle/field[@name='TITTEL']"/> -
		<xsl:value-of
select="$theArticle/field[@name='SCHEDULE']/schedule/@startTime"/><br/>
                </xsl:template>
</xsl:stylesheet>

Here's my current output:

//TV//Channels//Channel1
Program 1- 2400
Program 5- 2100
//TV//Channels//Channel2
Program 2- 0900
Program 3- 1100
Program 4- 1000

I would like to sort the channels by its ID and the programs by its
startTime. Does anybody have an idea?

Any help would be appreciated!

Regards, 
A Hansen, XSLT newbie



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent