[xsl] Unique entries from substrings

Subject: [xsl] Unique entries from substrings
From: "Andreas Guther" <aguther@xxxxxxxxxxxxxx>
Date: Sun, 26 Jun 2005 18:56:28 -0700
I am trying to get all unique month-date entries based on a list of
mm/dd/yyyy entries.

I am able to get the unique mm/dd/yyyy entries but I would like to only
get the unique months per year.

I have included a stripped down XML I am reading data from and my test
XSL that should give me the unique values.  From the given data set the
transformation returns now:

"07-2005";"05-2005";"05-2005";

...but what I would like to achieve is:

"07-2005";"05-2005";


I guess the formatting of the date does not work as I expect it.  Is
there another way to find unique entries on a different format than
found in the XML?

Strange to me is that if the formatting would not work, I should see
four entries instead of three.  So something is not working as I think
it should, but I am not able to figure it out.

What do I do wrong????

The XML:

<REPORT_ACCESS>
  <REPORTS>
    <REPORT>
      <!-- not unique in list -->
      <DATE>07/08/2005</DATE>
    </REPORT>
    <REPORT>
      <!-- unique -->
      <DATE>05/08/2005</DATE>
    </REPORT>
    <REPORT>
      <!-- not unique in list -->
      <DATE>07/08/2005</DATE>
    </REPORT>
    <REPORT>
      <!-- unique 05-2005-->
      <DATE>05/09/2005</DATE>
    </REPORT>
    <REPORT>
      <!-- unique 07-2005-->
      <DATE>07/09/2005</DATE>
    </REPORT>
  </REPORTS>
</REPORT_ACCESS>

and the XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="text" encoding="UTF-8" indent="no"/>
  <!--
    date unformatted
  -->
  <xsl:variable name="unique-dates"
select="REPORT_ACCESS/REPORTS/REPORT/
    DATE[not(../preceding-sibling::REPORT/DATE = .)]"/>
  <!--
    date formatted
    -->
  <xsl:variable name="unique-dates-formatted"
select="REPORT_ACCESS/REPORTS/REPORT/

DATE[not(concat(substring(../preceding-sibling::REPORT/DATE,1,2),'-',sub
string(../preceding-sibling::REPORT/DATE,7,4)) =
concat(substring(.,1,2),'-',substring(.,7,4)))]"/>
  <!--

-->
  <xsl:template match="/REPORT_ACCESS">
    <!-- for testing
    <xsl:copy-of select="$unique-dates-month"/>
    -->
    <xsl:call-template name="build-list-month-year">
      <!-- if used with unformatted list, it works fine as expected -->
      <xsl:with-param name="list" select="$unique-dates-formatted"/>
    </xsl:call-template>
  </xsl:template>
  <!--

  -->
  <xsl:template name="build-list-month-year">
    <xsl:param name="list"/>
    <xsl:for-each select="$list">
      <xsl:text>"</xsl:text>
      <xsl:value-of
select="concat(substring(.,1,2),'-',substring(.,7,4))"/>
      <xsl:text>";</xsl:text>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

--------------------------------------------------------

This electronic mail message contains information belonging to PaymentOne,
which may be confidential and/or legal privileged. The information is intended
only for the use of the individual or entity named above. If you are not the
intended recipient, you are hereby notified that any disclosure, printing,
copying, distribution, or the taking of any action in reliance on the contents
of this electronically mailed information is strictly prohibited. If you
receive this message in error, please immediately notify us by electronic mail
and delete this message.
--------------------------------------------------------

Current Thread