|
Subject: Re: [xsl] Yet another grouping question From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 08 Jan 2003 11:17:51 -0500 |
Now comes the grouping issue. Cities served by multiple airports are repeated in the table:
<tr> <td>Buenos Aires</td> <td>Jorge Newbery</td> <td>AEP</td> </tr> <tr> <td>Buenos Aires</td> <td>Ministro Pistarini</td> <td>EZE</td> </tr>
Obviously I'd like both of these airports listed in one city node for Buenos Aires, but I can't figure out how to modify my stylesheet to do this. I don't think I can use methods involving keys
T:\ftemp>type martinez1.xml <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td>
<b class="title-destination">Algeria</b> <!-- country -->
<table width="100%">
<tr>
<td>Algiers</td> <!-- city -->
<td>Houari Boumedienne Arpt</td> <!-- airport name -->
<td>ALG</td> <!-- airport code -->
</tr>
<tr>
<td>Annaba</td>
<td>Les Salines Arpt</td>
<td>AAE</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
</xsl:template></xsl:stylesheet> T:\ftemp>type martinez2.xml <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td>
<b class="title-destination">Algeria</b> <!-- country -->
<table width="100%">
<tr>
<td>Algiers</td> <!-- city -->
<td>Houari Boumedienne Arpt</td> <!-- airport name -->
<td>ALG-1</td> <!-- airport code -->
</tr>
<tr>
<td>Annaba2</td>
<td>Les Salines Arpt</td>
<td>AAE</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
</xsl:template></xsl:stylesheet> T:\ftemp>type martinez.xml <?xml version="1.0" encoding="iso-8859-1"?> <file-names> <file>martinez1.xml</file> <file>martinez2.xml</file> </file-names>
T:\ftemp>type martinez.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<airport-codes>
<xsl:attribute
name="xsi:noNamespaceSchemaLocation">airport_codes.xsd</xsl:attribute> <xsl:variable name="airport-nodes"
select="document(file-names/file)/xsl:stylesheet/
xsl:template[@match='/']/html/body/table[1]/tr/td/table/tr"/>
<xsl:for-each select="$airport-nodes">
<xsl:sort select="td[1]"/>
<xsl:if test="generate-id( . ) =
generate-id( $airport-nodes[ td[1]=current()/td[1] ] )">
<country name="{../../b}">
<city name="{td[1]}">
<xsl:for-each select="$airport-nodes[ td[1]=current()/td[1] ]">
<xsl:sort select="td[3]"/>
<airport code="{td[3]}">
<xsl:value-of select="td[2]"/>
</airport>
</xsl:for-each>
</city>
</country>
</xsl:if>
</xsl:for-each>
</airport-codes>
</xsl:template>
</xsl:stylesheet>
-- Upcoming hands-on in-depth North America: February 3- 7,2003 XSLT/XPath and XSL-FO Europe: February 17-21,2003
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 0-13-140374-5 Definitive XSL-FO ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-10-1 Practical Formatting Using XSL-FO Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Yet another grouping ques, Niko Matsakis | Thread | RE: [xsl] Yet another grouping ques, Martinez, Brian |
| [xsl] Beginner: adding xmlns:mml at, Roel Vanhout | Date | Re: [xsl] Import and variables, Jeni Tennison |
| Month |