Sorting & duplicates

A

A.T.

Have an XSL file that flags duplicate id's, by painting cells blue and
by adding the word "duplicate" to a new column at the end of the
table. It also sorts the id's. Would like to have the output file
retain these qualities, but also sort the document(using the duplicate
column) so that duplicates come at the beginning.

XML file
<root>
<version size="16">
<id>A1</id>
<type>mac</type>
</version>
<version size="16">
<id>A1</id>
<type>mac</type>
</version>
<version size="32">
<id>A2</id>
<type>pc</type>
</version>
</root>
-----------------------------------
XSL file
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:template match="/">
<html>
<head>
<title>Version Information</title>
</head>
<body>
<table border="1" align="center"
cellPadding="1"
cellSpacing="1">
<tr>
<th>Id</th>
<th>Size</th>
<th>Type</th>
<th>Duplicate</th>
</tr>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>

<xsl:template match="root">
<xsl:apply-templates select="version">
<xsl:sort select="id"/>
</xsl:apply-templates>
</xsl:template>


<xsl:template match="version">
<tr align="center">
<xsl:choose>
<xsl:when test="child::id=preceding::id">
<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>
<td><xsl:value-of select="@size"/></td>
<td><xsl:value-of select="type"/></td>
<xsl:choose>
<xsl:when test="child::id=preceding::id">
<td>duplicate</td>
</xsl:when>
<xsl:eek:therwise/>
</xsl:choose>
</tr>
</xsl:template>
</xsl:stylesheet>
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top