xsl-list
[Top] [All Lists]

Re: [xsl] Removing duplicates after list is sorted

2006-05-11 10:19:10
Hey thanks David!

Nicole, your problem gets near to where it's easier to use multiple passes. Fortunately you have the likes of David to help.

Cheers,
Wendell

At 12:40 PM 5/11/2006, he wrote:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

If your creation dates were in a form that could be compared as numbers
you could just do this:

<xsl:output indent="yes"/>

<xsl:key name="base" match="Document" use="Report/@base"/>
<xsl:template match="docs">
<docs>
<xsl:for-each select="Document[generate-id()=generate-id(key('base',Report/@base))]">
<xsl:variable name="thisgrp" select="key('base',Report/@base)"/>
<xsl:copy-of select="$thisgrp[not(@CREATIONTIME &gt; $thisgrp/@CREATIONTIME)][1] "/>
</xsl:for-each>
</docs>
</xsl:template>

</xsl:stylesheet>

but since they are not, I think something like this is what you want

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

<xsl:output indent="yes"/>

<xsl:key name="base" match="Document" use="Report/@base"/>
<xsl:template match="docs">
<docs>
<xsl:for-each select="Document[generate-id()=generate-id(key('base',Report/@base))]">

<xsl:for-each select="key('base',Report/@base)">
<xsl:sort select="@CREATIONTIME"/>
<xsl:if test="position()=last()">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</docs>
</xsl:template>

</xsl:stylesheet>

$ saxon dup.xml dup.xsl
<?xml version="1.0" encoding="utf-8"?>
<docs>
   <Document CREATIONTIME="200605051507">

      <Report ID="759d" base="ELS">

         <Authorized ASC="2"/>

      </Report>

   </Document>
   <Document CREATIONTIME="200605041506">

      <Report ID="759c" base="LAN">

         <Authorized ASC="0"/>

      </Report>

   </Document>
</docs>


David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>