[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: [Fwd: Muenchian method -- how to optimize this cod
On 8/18/06, Michael Fourneau <Michael.Fourneau@xxxxxxx> wrote:
=== Question 2 ===
Given this XML: <customers> <customer> <name>CUSTOMER1</name> <team> <member> <name>NAME1</name> <title>T1</title> <title>T2</title> </member> <member> <name>NAME2</name> <title>T3</title> </member> </team> </customer> <customer> <name>CUSTOMER2</name> <team> <member> <name>NAME3</name> <title>T4</title> </member> <member> <name>NAME2</name> <title>T3</title> <title>T1</title> </member> </team> </customer> </customers> This stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="yes" /> <xsl:key name="by-title" match="title" use="." /> <xsl:template match="/"> <html> <head> <title/> </head> <body> <table border="1"> <tr> <th>Title</th> <th>Team member</th> <th>Customers</th> </tr> <xsl:for-each select="//title[generate-id() = generate-id(key('by-title', .)[1])]"> <xsl:variable name="title" select="." /> <xsl:for-each select="//member[title = $title]"> <xsl:choose> <xsl:when test="position() = 1"> <tr> <td><xsl:value-of select="$title" /></td> <td><xsl:value-of select="name" /></td> <td><xsl:value-of select="../../name" /></td> </tr> </xsl:when> <xsl:otherwise> <tr> <td></td> <td> <xsl:if test="not(preceding::member[title = $title]/name = current()/name)"> <xsl:value-of select="name" /> </xsl:if> </td> <td><xsl:value-of select="../../name" /></td> </tr> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Produces output: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <table border="1"> <tr> <th>Title</th> <th>Team member</th> <th>Customers</th> </tr> <tr> <td>T1</td> <td>NAME1</td> <td>CUSTOMER1</td> </tr> <tr> <td></td> <td>NAME2</td> <td>CUSTOMER2</td> </tr> <tr> <td>T2</td> <td>NAME1</td> <td>CUSTOMER1</td> </tr> <tr> <td>T3</td> <td>NAME2</td> <td>CUSTOMER1</td> </tr> <tr> <td></td> <td></td> <td>CUSTOMER2</td> </tr> <tr> <td>T4</td> <td>NAME3</td> <td>CUSTOMER2</td> </tr> </table> </body> </html> I believe, this is what you want. The solution is probably not very optimized. -- Regards, Mukul Gandhi http://gandhimukul.tripod.com
|
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
|