473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sorting with Muenchian Method

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

Nov 3 '06 #1
1 1503

al***************@gmail.com wrote:
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.
Funny, I don't see any <xsl:sort>s in your transformation.
Precisely how were you trying to get the sorting right?

[XML]

I wonder who designed that...

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:key name="k" match="article"
use="field[@name='KANAL']/category/@path"/>
<xsl:template match="/">
<result>
<xsl:apply-templates
select=
"
//article
[
generate-id()=
generate-id
(
key('k',field[@name='KANAL']/category/@path)
)
]
" mode="channel">
<xsl:sort
select="field[@name='KANAL']/category/@id"/>
</xsl:apply-templates>
</result>
</xsl:template>
<xsl:template match="article" mode="channel">
<channel>
<xsl:attribute name="path">
<xsl:value-of
select="field[@name='KANAL']/category/@path"/>
</xsl:attribute>
<xsl:apply-templates
select=
"
//article
[
field[@name='KANAL']/category/@id=
current()/field[@name='KANAL']/category/@id
]
" mode="program">
<xsl:sort
select=
"
field[@name='SCHEDULE']/schedule/@startTime
"/>
</xsl:apply-templates>
</channel>
</xsl:template>
<xsl:template match="article" mode="program">
<program>
<xsl:value-of select="field[@name='TITTEL']"/>
<xsl:text- </xsl:text>
<xsl:value-of
select=
"
field[@name='SCHEDULE']/schedule/@startTime
"/>
</program>
</xsl:template>
</xsl:stylesheet>

--
Pavel Lepin

Nov 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: rayt | last post by:
Im relatively new to XSLT and must admit Im finding it refreshing, but every now and again something comes along which floors me. Maybe its the old imperative language background that is hard to...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
6
by: Michiel Kamermans | last post by:
Hi, I need to generate a list based on a sorted nodeset, except duplicates need to be discarded. I initially though of doing a sort on a nodeset and then passing it to a template that iterates...
1
by: mike | last post by:
Hi, I'm trying to apply Muenchian grouping to the XML displayed below but having no success, I'm trying to group on the section element, any pointers would be much appreciated: Thanks, Mike
1
by: lennyw | last post by:
Hi I'm trying to use XSLT to do an xml to xml transformation where the output xml contains summary data on the information in the input xml. I've succesfully done a Muenchian grouping of the...
6
by: Christoph | last post by:
I'm trying to come up with a stylesheet where, when the rows are displayed, duplicate game names are not shown on subsequent rows. It works but doesn't work properly. If I sort the data using...
2
by: la.brunning | last post by:
Hello, I am trying to filter a Muenchian grouping I have created. I think I am fairly close, but I am not quite sure where to apply my filter; its been some time since I did any work with XSLT....
7
by: abracadabra | last post by:
I am reading an old book - Programming Pearls 2nd edition recently. It says, "Even though the general C++ program uses 50 times the memory and CPU time of the specialized C program, it requires...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.