This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Select distinct elements


Hi Jakub,

> I need to select events for text output, but only once each.
> So the output should look like this:
> 
> 11:00-14:00: Event 1
> 12:00-12:15: Event 2
> 15:00-15:30: Event 3
> 
> I don't know, how to select each event original, when the same event is in
> input more times.
This is a grouping problem. Really classic question. Who could explain
it better than Jeni Tennison, I wonder why she didn't do already...

Solution:
<?xml version="1.0"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

<xsl:key name="event"
         match="/day/hour/event"
         use="name"/>

<xsl:template match="/">
    <output>
        <xsl:apply-templates />
    </output>
</xsl:template>

<xsl:template match="day">
   <xsl:for-each select="hour/event[generate-id() =
generate-id(key('event',name)[1])]">
       <xsl:sort select="name"/>
<xsl:text>
</xsl:text>
       <xsl:value-of select="concat(timeFrom,'-',timeTo,': ',name)"/>
   </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
Explanation:
see http://www.jenitennison.com/xslt/grouping/muenchian.html

Gruß, Philip

P.S. some other solution with saxon:distinct?

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]