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

RE: [xsl] What is a good way to style and show tabular data [snip]


Subject: RE: [xsl] What is a good way to style and show tabular data [snip]
From: Peter Flynn <peter@xxxxxxxxxxx>
Date: 19 Aug 2003 22:30:03 +0100

On Tue, 2003-08-19 at 20:39, SANWAL, ABHISHEK (HP-Houston) wrote:
> To: XSL-List
> Cc: Wendell
> Cc: Peter
> 
> I am wondering if you could give me some suggestions on the actual XML
> at hand. In this matrix/table design I am only thinking for 2-D Data &
> Layout. Of course that is the medium I can write to now and that is the
> content.

In the solution below, I have used the principle of sticking to
templates where possible and using for-each only where absolutely
necessary. 

> I am trying to eliminate the notion of absolute vertical or horizontal
> flow styling for the table thereby allowing me to lay the table out with
> the head on the top or the head on the left ( maybe even the right ?? ).
> 
> I am inserting sample XML and a partially done XSL where I would like
> some suggestions on how I could improve the XML and the XSL to make them
> do the "Vertical" flow that I have not yet completed.

A couple of queries first:

> (V - Vertical, H - Horizontal)
> 
> <Matrix HeadFlow="V|H" HeadExists="1" HeadCount="4" DataCount="1">

V|H I can understand ("this table may be presented vertically or
horizontally"). HeadExists I'm not certain about: XSL can test
if MatrixHeadArray is present as child::*[1] of Matrix, so it seems
unnecessary. The same applies to HeadCount:
count(MatrixHeadArray/MatrixHeadCell) will give you the same value.
Ditto for DataCount (count(MatrixDataArray)).

> 	<MatrixHeadArray>
> 		<MatrixHeadCell i="1">Standard 1</MatrixHeadCell>
> 		<MatrixHeadCell i="2">Maximum 2</MatrixHeadCell>
> 		<MatrixHeadCell i="3">Standard 3</MatrixHeadCell>
> 		<MatrixHeadCell i="4">Maximum 4</MatrixHeadCell>
> 	</MatrixHeadArray>

Does @i exist solely to link the column/row positions between header and
data? Or is there a possibility that the MatrixHeadCell elements will be
out of order (and therefore need sorting)?

> 	<MatrixDataArray j="1">
> 		<MatrixDataCell i="1" j="1">1024 MB </MatrixDataCell>
> 		<MatrixDataCell i="2" j="1">32GB</MatrixDataCell>
> 		<MatrixDataCell i="3" j="1">512 MB </MatrixDataCell>
> 		<MatrixDataCell i="4" j="1">32GB</MatrixDataCell>
> 	</MatrixDataArray>

Same question about @i. What is @j for?

> </Matrix>

///Peter

---------------------------------8<--------------------------------------

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:output method="html" encoding="iso-8859-1"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>
          <xsl:text>Horizontal and Vertical Tables</xsl:text>
        </title>
      </head>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Matrix">
    <xsl:if test="contains(@HeadFlow,'H')">
      <h3>Horizontal</h3>
      <table border="1">
        <xsl:apply-templates mode="H"/>
      </table>
    </xsl:if>
    <xsl:if test="contains(@HeadFlow,'V')">
      <h3>Vertical</h3>
      <table border="1">
        <xsl:apply-templates mode="V"/>
      </table>
    </xsl:if>
  </xsl:template>

  <xsl:template match="MatrixHeadArray" mode="H">
    <tr>
      <xsl:apply-templates mode="H"/>
    </tr>
  </xsl:template>

  <xsl:template match="MatrixHeadCell" mode="H">
    <th>
      <xsl:apply-templates/>
    </th>
  </xsl:template>

  <xsl:template match="MatrixDataArray" mode="H">
    <tr>
      <xsl:apply-templates mode="H"/>
    </tr>
  </xsl:template>

  <xsl:template match="MatrixDataCell" mode="H">
    <td>
      <xsl:apply-templates/>
    </td>
  </xsl:template>

  <xsl:template match="MatrixHeadArray" mode="V">
    <xsl:for-each select="MatrixHeadCell">
      <tr>
        <th>
          <xsl:apply-templates/>
        </th>
        <xsl:variable name="headloc">
          <xsl:value-of select="@i"/>
        </xsl:variable>
        <xsl:for-each select="../../MatrixDataArray">
          <td>
            <xsl:apply-templates select="MatrixDataCell[@i=$headloc]"/>
          </td>
        </xsl:for-each>
      </tr>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="MatrixDataCell" mode="V"/>

</xsl:stylesheet>




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



Current Thread
Keywords