Subject: [xsl] Removing duplicates for unknown number of elements From: "Christopher Go" <cgo@xxxxxxxxxxx> Date: Tue, 13 Mar 2001 15:49:54 -0800 |
Hi all, Been reading all about the grouping/removing duplicates using keys, etc. but I'm still confused as to what to do on this situation... somebody else is giving me the input XML but if it is not formed properly, I am also open to suggestions as to how to properly send the XML in a *xsl-friendlier* format. I'm using Xalan Processor (transform() method). =================================== XML input <WS> <CONTENT TYPE="DB"> <TITLE>Laker Players</TITLE> <ROWS> <ROW> <NAME>Shaq O'Neal</NAME> <EMAIL>shaq@xxxxxxxxxx</EMAIL> </ROW> <ROW> <NAME>Kobe Bryant</NAME> <EMAIL>kobe@xxxxxxxxxx</EMAIL> </ROW> <ROW> <NAME>Rick Fox</NAME> <EMAIL>rick@xxxxxxxxxx</EMAIL> </ROW> </ROWS> </CONTENT> <CONTENT TYPE="DB"> <TITLE>Sports Teams in CA</TITLE> <ROWS> <ROW> <SPORT>Basketball</SPORT> <TEAM>Lakers</TEAM> <CITY>Los Angeles</CITY> </ROW> <ROW> <SPORT>Basetball</SPORT> <TEAM>Angels</TEAM> <CITY>Anaheim</CITY> </ROW> <ROW> <SPORT>Hockey</SPORT> <TEAM>Kings</TEAM> <CITY>Los Angeles</CITY> </ROW> </ROWS> </CONTENT> </WS> =================================== XSL <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:template name="main" match="WS"> <html> <body> <xsl:if test="CONTENT/@TYPE[.='DB']"> <xsl:for-each select="CONTENT/@TYPE[.='DB']"> <p/> <b><xsl:value-of select="../node()/../TITLE"/></b> <br/> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td bgcolor="#666666"> <table width="100%" cellspacing="1" cellpadding="2" border="0"> <tr bgcolor="#ffffff"> <!------ ***** -------> <xsl:for-each select="../node()/ROW/node()"> <th><xsl:value-of select="name()"/></th> </xsl:for-each> </tr> <xsl:for-each select="../node()/ROW"> <tr bgcolor="#ffffff"> <xsl:for-each select="node()"> <td><xsl:value-of select="node()"/></td> </xsl:for-each> </tr> </xsl:for-each> </table> </td> </tr> </table> </xsl:for-each> </xsl:if> </body> </html> </xsl:template> </xsl:stylesheet> =================================== Desired output <html> <body> <p> <b>Laker Players</b> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td bgcolor="#666666"> <table width="100%" cellspacing="1" cellpadding="2" border="0"> <tr bgcolor="#ffffff"> <th>NAME</th> <th>EMAIL</th> </tr> <tr bgcolor="#ffffff"> <td>Shaq O'Neal</td> <td>shaq@xxxxxxxxxx</td> </tr> <tr bgcolor="#ffffff"> <td>Kobe Bryant</td> <td>kobe@xxxxxxxxxx</td> </tr> <tr bgcolor="#ffffff"> <td>Rick Fox</td> <td>rick@xxxxxxxxxx</td> </tr> </table> </td> </tr> </table> <p> <b>Sports Teams in CA</b> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td bgcolor="#666666"> <table width="100%" cellspacing="1" cellpadding="2" border="0"> <tr bgcolor="#ffffff"> <th>SPORT</th> <th>TEAM</th> <th>CITY</th> </tr> <tr bgcolor="#ffffff"> <td>Basketball</td> <td>Lakers</td> <td>Los Angeles</td> </tr> <tr bgcolor="#ffffff"> <td>Basetball</td> <td>Angels</td> <td>Anaheim</td> </tr> <tr bgcolor="#ffffff"> <td>Hockey</td> <td>Kings</td> <td>Los Angeles</td> </tr> </table> </td> </tr> </table> </body> </html> =================================== Questions: 1. The first problem I have is that (from the XML input) you can see that after WS/CONTENT/ROWS/ROW, the nodes beneath that change .. is this bad XML design? 2. Most of the stuff above works... it's just *bad-looking*... i got node() calls hooked up which don't look very nice... 3. I got most of the stuff to work on this page except for 1 thing... on the XSL stylesheet, right after the <!---- ***** ----> comment tag, I get duplicate <th></th> tags generated because the loop I have there has no concept of uniqueness... so for the first chunk, I get: <tr><th>NAME</th><th>EMAIL</th><th>NAME</th><th>EMAIL</th><th>NAME</th><th>E MAIL</th></tr> instead of: <tr><th>NAME</th><th>EMAIL</th></tr> (which is my desired output). =================================== Thanks, Chris XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Dash (Script Link Removed, Stephen Cunliffe | Thread | RE: [xsl] Removing duplicates for u, Tim Watts |
[xsl] dash, YueMa | Date | RE: [xsl] Removing duplicates for u, Tim Watts |
Month |