Eliminating duplicate entries

A

A.T.

I have an XML document that looks like the following, except that it
has about 30,000 entries.
<root>
<version id="A-0000">
<!many elements within- removed for ease of reading>
</version>
<version id="A-0000">
</version>
<version id="A-0001">
</version>
</root>


I want to create a stylesheet where a flag goes up when there are
duplicates like:
<version id="A-0256">
</version>
<version id="A-0256">
</version>

I'm trying to use

<xsl:template match="version">
<xsl:choose>
<xsl:when test="preceding::node()=node()">
<td bgcolor="blue"><xsl:value-of select="id"/></td>
</xsl:when>
<xsl:eek:therwise>
<td><xsl:value-of select="id"/></td>
</xsl:eek:therwise>
</xsl:choose>
<xsl:apply-templates select="version"/>
</xsl:template>

but I can't seem to get the test="" part of it to work. Please help.
 
D

David Carlisle

<xsl:template match="version">
<xsl:choose>
<xsl:when test="preceding::node()=node()">

your currnt node is version so the above test is testing if _any_
preceding node anywhere in the document (of any type, element, text,
comments, ..) is equal to any child node of the current node.

The current node apparently only has one child a text node consisting of
a newline character so you are asking if any previous node has string
value being a newline.

You want to know if the previous sibling element is equal to the current
node
so that's
<xsl:template match="version">
<xsl:choose>
<xsl:when test="preceding-sibling::*=.">

or
<xsl:template match="version">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1]=.">

if your input is already sorted and you only need check teh immediately
preceding element.


David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top