[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Yet another grouping question
At 2003-01-08 08:17 -0700, Martinez, Brian wrote:
Now comes the grouping issue. Cities served by multiple airports are repeated in the table: Grouping isn't only accomplished through keys ... I often use variables and variables work across files. I mocked up some data and the following seems to work fine in a small test. I hope this helps. ............ Ken 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> T:\ftemp>saxon martinez.xml martinez.xsl <?xml version="1.0" encoding="UTF-8"?> <airport-codes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="airport_codes.xsd"> <country name="Algeria"> <city name="Algiers"> <airport code="ALG">Houari Boumedienne Arpt</airport> <airport code="ALG-1">Houari Boumedienne Arpt</airport> </city> </country> <country name="Algeria"> <city name="Annaba"> <airport code="AAE">Les Salines Arpt</airport> </city> </country> <country name="Algeria"> <city name="Annaba2"> <airport code="AAE">Les Salines Arpt</airport> </city> </country> </airport-codes> T:\ftemp>rem Done!
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 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
|