Subject: Re: Removing duplicates after list is sorted
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 11 May 2006 17:40:50 +0100
|
<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 > $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
________________________________________________________________________
|