Reduced source XML:
<?xml version="1.0" encoding="UTF-8"?>
<POL>
<POLFORMS>
<FORMS>
<ID>12455</ID>
<BUS_TYPE>HAT</BUS_TYPE>
<DATE>07-2008</DATE>
</FORMS>
<FORMS>
<ID>12455</ID>
<BUS_TYPE>INS</BUS_TYPE>
<DATE>07-2008</DATE>
</FORMS>
<FORMS>
<ID>12455</ID>
<BUS_TYPE>INS</BUS_TYPE>
<DATE>07-2008</DATE>
</FORMS>
<FORMS>
<ID>12455</ID>
<BUS_TYPE>HAT</BUS_TYPE>
<DATE>07-2008</DATE>
</FORMS>
<FORMS>
<ID>12456</ID>
<BUS_TYPE>INS</BUS_TYPE>
<DATE>07-2010</DATE>
</FORMS>
<FORMS>
<ID>12456</ID>
<BUS_TYPE>INS</BUS_TYPE>
<DATE>07-2010</DATE>
</FORMS>
<FORMS>
<ID>12456</ID>
<BUS_TYPE>POM</BUS_TYPE>
<DATE>07-2008</DATE>
</FORMS>
<FORMS>
<ID>12456</ID>
<BUS_TYPE>POM</BUS_TYPE>
<DATE>07-2008</DATE>
</FORMS>
</POLFORMS>
</POL>
This is what I want to end up with, unique ID - DATE combo list. I
will be bringing along other nodes also, but this is the essence.
<POL>
<POLFORMS>
<FORMS>
<ID>12455</ID>
<DATE>07-2008</DATE>
</FORMS>
<FORMS>
<ID>12456</ID>
<DATE>07-2010</DATE>
</FORMS>
<FORMS>
<ID>12456</ID>
<DATE>07-2008</DATE>
</FORMS>
</POLFORMS>
</POL>
In case your XSLT processor supports key()s in key
expressions, this can be done cleanly with a couple of
simple keys. If not, just filter explicitly on match.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="idDate" match="FORMS"
use="concat(ID, '|', DATE)"/>
<xsl:key name="uniqIdDate" match="FORMS"
use="
count(.|key('idDate', concat(ID, '|', DATE))[1])
"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="POLFORMS">
<method-1>
<xsl:apply-templates select="key('uniqIdDate', 1)"/>
</method-1>
<method-2>
<xsl:apply-templates select="FORMS"
mode="unique-id-date"/>
</method-2>
</xsl:template>
<xsl:template match="FORMS" mode="unique-id-date">
<xsl:variable name="id" select="ID"/>
<xsl:variable name="date" select="DATE"/>
<xsl:if test="
count(
preceding-sibling::FORMS[ID = $id and DATE = $date]
) = 0
">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
--
P. Lepin
Excellent, thank you. I was making it out to be harder than it
actually was.