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

RE: how to convert from list to grid ?

Subject: RE: how to convert from list to grid ?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 30 Oct 2005 23:48:16 -0000
convert list to table
In 2.0, with <list> as the context node, it's something like this:

<xsl:variable name="list" select="."/>
<table>
<xsl:for-each select="1 to max(item/@x)">
  <xsl:variable name="x" select="."/>
  <tr>
  <xsl:for-each select="1 to max(item/@y)">
    <xsl:variable name="y" select="."/>
    <td>
       <xsl:value-of select="count($list/item[@x=$x and @y=$y])"/>
    </td>
  </xsl:for-each>
  </tr>
</xsl:for-each>
</table>

In 1.0, you can replace the for-each loops with a recursion, or with
something like

<xsl:for-each select="//node()[position() &lt;= $max-x]">

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


> -----Original Message-----
> From: Bru, Pierre [mailto:Pierre.Bru@xxxxxxxxxxxx] 
> Sent: 30 October 2005 22:48
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  how to convert from list to grid ?
> 
> hello,
>  
> I've been racking my brains for a couple of weeks now but I 
> can not find
> a way to do the folowing: I have a list reprenting the type 
> and integer
> coordinate of various items on a square grid like this one:
>  
> <list>
>   <item id="1" type="foo" x="1" y="7" />
>   <item id="2" type="bar" x="8" y="2" />
>   <item id="3" type="foo" x="8" y="2" />
>   <item id="4" type="bar" x="8" y="3" />
>   <item id="5" type="bar" x="8" y="3" />
>   <item id="6" type="bar" x="8" y="3" />
>   ...
> </list>
>  
> - "id" are unique
> - each cell may contain any number of item (including 0).
> - there are as many lines as needed for each cell (see [8,2] or [8,3])
> - the cell are in no particular order for now but this can be 
> changed as
> needed
>  
> I would like to transform this list into a square grid (table?) with :
> - if the cell contains no item, an empry cell
> - otherwise, the count of item(s) of each type (one value for 
> each type
> present on the cell)
>  
> is this feasable with XSLT ?
>  
> TIA,
> Pierre.

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.