You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Stoaks, Max" <St...@gsb.stanford.edu> on 2004/06/06 17:24:09 UTC

More detail on dups question...XPATH question

I'm trying to remove duplicate elements from an xml document that looks like this:
<CompanyResults>
	<CompanyResult>
		<CompanyTitle>IBM</CompanyTitle>
		<CompanyContact>Joe</CompanyContact>
	</CompanyResult>
	<CompanyResult>
		<CompanyTitle>IBM</CompanyTitle>
		<CompanyContact>Joe</CompanyContact>
	</CompanyResult>
	<CompanyResult>
		<CompanyTitle>Intuit</CompanyTitle>
		<CompanyContact>Claudia</CompanyContact>
	</CompanyResult>
</CompanyResults>

I basically want to ignore duplicate <CompanyResult> elements, where duplicate means they have the same <CompanyTitle>.


So, I wrote a stylesheet that looks like this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/">
	<xsl:for-each select="CompanyResults/CompanyResult[not(CompanyTItle=preceding-sibling::CompanyResults/CompanyResult/CompanyTItle)]">	
	<xsl:value-of select="CompanyTitle"/>	
	</xsl:for-each>	
	</xsl:template>
</xsl:stylesheet>



This is still not de-duping the list. Can anybody help?

Thanks!!!
Max