[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Re: Structuring multiple HTML tables based on the

Subject: RE: Re: Structuring multiple HTML tables based on the value of a child node
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 5 Jun 2007 13:26:17 +0100
RE:  Re: Structuring multiple HTML tables based on the
You failed to guess the right keyword: "grouping".

This is a classic grouping problem. In XSLT 2.0 such problems are easy, use
xsl:for-each-group. In XSLT 1.0 they are much harder, except that the code
has been written many times. See http://www.jenitennison.com/xslt/grouping.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Mark Peters [mailto:flickrmeister@xxxxxxxxx] 
> Sent: 05 June 2007 13:15
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Re: Structuring multiple HTML tables based on 
> the value of a child node
> 
> Hi Everyone,
> 
> Sorry for the long subject line. I've been reading Dave 
> Pawson's site for a starting point on a particular project, 
> but I'm not even sure how to distill it into browse/search 
> terms. None of the general headings I've explored seem to 
> quite describe it.
> 
> Here's what I'm trying to do. I'd like to structure my data 
> as multiple HTML tables based on the value of a child node.
> 
> For example, in the sample input file below, I'd like to 
> generate three HTML tables, one for each <color> value. The 
> tables would include two columns: Name and Shape. The table 
> rows display the name and shape data for each color. The 
> <table> element would include an id attribute that contains 
> the <color> value.
> 
> 
> Sample input file:
> 
> <signs>
>    <sign>
>       <name>stop</name>
>       <shape>hexagon</shape>
>       <color>red</color>
>    </sign>
>    <sign>
>        <name>yield</name>
>       <shape>triangle</shape>
>        <color>yellow</color>
>     </sign>
>    <sign>
>        <name>steep incline</name>
>       <shape>diamond</shape>
>        <color>yellow</color>
>     </sign>
>    <sign>
>        <name>slippery when wet</name>
>       <shape>diamond</shape>
>        <color>yellow</color>
>     </sign>
>    <sign>
>        <name>city name</name>
>       <shape>rectangle</shape>
>        <color>green</color>
>     </sign>
> </signs>
> 
> 
> If I use <for-each>, I end up with a table for every <sign> element.
> How could someone create a single table for each <color> value?
> 
> Here's what I have so far:
> 
>     <xsl:template match="\">
>       <xsl:for-each select="signs/sign/color">
>       <xsl:sort select="."/>
>         <table frame="all" colsep="1" rowsep="1">
>             <xsl:attribute name="id"><xsl:value-of 
> select="."/></xsl:attribute>
>              <tr>
>                  <th>Name</entry>
>                  <th>Shape</entry>
>              </tr>
>              <xsl:for-each select="../name">
>                   <xsl:sort select="."/>
>                       <tr>
>                           <td>
>                              <xsl:value-of select="."/>
>                           </td>
>                           <td>
>                              <xsl:value-of select="shape"/>
>                           </td>
>                       </tr>
>                   </xsl:for-each>
>             </table>
>         </xsl:for-each>
>     </xsl:template>
> 
> 
> Thanks for any suggestions. I appreciate all of the help the 
> kind people on this list have provided over the past year. 
> I've learned a lot from reading the posts and exploring on my own.
> 
> Regards,
> Mark

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.