2 unique lists

Subject: 2 unique lists
From: Matthew Cordes <mcorde61@xxxxxxxxx>
Date: Mon, 7 Aug 2000 11:41:35 -0400
Hello all.  

This another question about deriving a unique list from xmldata, but I think 
mine is a little different.  I have the following xml:

<schedule>
	<person name="person1">
		<date>Feb2000</date>
		<date>Mar2000</date>
		<date>Apr2000</date>
		<date>Feb2000</date>
		<date>Mar2000</date>
		<date>Apr2000</date>
		<date>Feb2000</date>
		<date>Mar2000</date>
		<date>Apr2000</date>
		<date>Feb2000</date>
		<date>Mar2000</date>
		<date>Apr2000</date>
	</person>
	<person name="person2">
		<date>Feb2000</date>
		<date>Mar2000</date>
		<date>Apr2000</date>
		<date>Feb2000</date>
		<date>Mar2000</date>
		<date>Apr2000</date>
		<date>Feb2000</date>
		<date>Mar2000</date>
		<date>Apr2000</date>
		<date>Feb2000</date>
		<date>Mar2000</date>
		<date>Apr2000</date>
	</person>
</schedule>	

	 and from this I want two unique lists of dates, thus 

	 person1: Feb2000, Mar2000, Apr2000.
	 person2: Feb2000, Mar2000, Apr2000.

	 Here is the first stylesheet, using preceding:

<xsl:template match="person">
  <xsl:value-of select="@name"/><xsl:text>: </xsl:text>
  <xsl:for-each select="date[ not( . = preceding::date )]">
    <xsl:value-of select="."/>
    <xsl:if test="not(position()=last())">, </xsl:if>
  </xsl:for-each>
</xsl:template>

which produces: 
				person1: feb2000, mar2000, Apr2000
        person2: 


I also tried the key method:
<xsl:key name="thedate" match="date" use="."/>

<xsl:template match="person">
  <xsl:value-of select="@name"/><xsl:text>: </xsl:text>
  <xsl:for-each select="date[generate-id(.) = generate-id(key('thedate',.)[1])]">
    <xsl:value-of select="."/>
    <xsl:if test="not(position()=last())">, </xsl:if>
  </xsl:for-each>
</xsl:template>

which produced the same result.  Can anyone offer any suggestions?  Also I'm not sure
I understand what the key method is doing can someone provide a detailed explanation?

-matt


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


Current Thread