[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Removing duplicates for unknown number of elements
Sorry Chris, I thought something like... <xsl:for-each select="../node()/ROW/node()"> <xsl:choose> <xsl:when test="not(.=preceding::node())"> <th><xsl:value-of select="name()"/></th> </xsl:when> </xsl:choose> </xsl:for-each> would have worked for this. Hope that someone is able to help Cheers, Tim -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Christopher Go Sent: Wednesday, 14 March 2001 12:56 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: Removing duplicates for unknown number of elements Hi Tim, Hmmm... my problem is that I do not have the name of the node in advance... trying to do a not(.=preceding::node()) doesn't seem to be picking it up... Thanks, Chris -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Tim Watts Sent: Tuesday, March 13, 2001 4:15 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: Removing duplicates for unknown number of elements Chris, A way to ensure that the nodes are not duplicated in your output is to use a test to see if the node() is not equal to a preceding node() I have used the code below to test to show only values of a node which are unique for a drop down list, and I am sure it could be adapted for your display. <select class="select" name="customer/city"> <option value="" selected="selected">All Cities</option> <xsl:for-each select="customer/city"> <xsl:choose> <xsl:when test="not(.=preceding::customer/city)"> <option value="{.}"><xsl:value-of select="."/></option> </xsl:when> </xsl:choose> </xsl:for-each> </select> Tim Watts -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Christopher Go Sent: Wednesday, 14 March 2001 10:50 AM To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx Subject: Removing duplicates for unknown number of elements 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 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|