[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Building html table from atributes


Subject: RE: [xsl] Building html table from atributes
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 9 Aug 2002 10:03:53 +0100

> 
> To make it sure that I understood correctly:
> 
> > First an XSLT 2.0 solution:
> > 
> > <xsl:variable name="doc" select="/XDocument"/>
> // variable that points to root element 
> 
> > <xsl:for-each select="1 to max($doc/XDocCell/@col)">
> // selects all elements (attribute col of XDocCells) from 1 
> to the max, 
> // using the doc variable.

No, it selects a sequence of numbers 1,2,3 up to the highest value of
@col in your document.
> 
> >   <xsl:variable name="col" select="position()"/>
> // col variable that declares position

We could have equally written select=".": this is the current column
number 
> 
> >   <tr>
> >   <xsl:for-each select="1 to max($doc/XDocCell/@row)">
> // selects all elements (attribute row of XDocCells) from 1 
> to the max, 
// using the doc variable.

We're now selecting a sequence of numbers from 1,2,3 up to the highest
@row number in your document [I can't think why I did it this way round,
you want rows in the outer loop and columns in the inner loop, of
course]
> 
> >     <xsl:variable name="row" select="position()"/>
> // row variable that declares position 
> 
> >     <td><xsl:value-of select="$doc/XDocCell[@row=$row and 
> > @col=$col]"/></td>
> // selects all row and col atributes (from xml file) that 
> equals // variables row and col 

We now select the cell with the particular row and column number, if
there is one, and output it. If there isn't one, we output nothing. If
there are two, <xsl:value-of> selects the first.

The logic is

for row from 1 to n
  <tr>
  for column from 1 to m
    <td>
    output cell[row, column]
    </td>
  end-for
  </tr>
end-for

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords