xsl-list
[Top] [All Lists]

Re: [xsl] Removing duplicates after list is sorted

2006-05-11 09:43:39
<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>
--~--

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