A
aleksander.hansen
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">
<xslutput method="html" version="1.0" encoding="utf-16"
indent="yes"/>
<xsl:key name="kChannel" match="article/field[@name='KANAL']/category"
use="@path" />
<xslutput 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
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">
<xslutput method="html" version="1.0" encoding="utf-16"
indent="yes"/>
<xsl:key name="kChannel" match="article/field[@name='KANAL']/category"
use="@path" />
<xslutput 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