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

Re: Dynamically building a HTML table from variable ro

Subject: Re: Dynamically building a HTML table from variable row data
From: Jörg Heinicke <joerg.heinicke@xxxxxx>
Date: Sun, 16 Dec 2001 13:20:04 +0100
html table variables
I don't know whether it's the best solution but it's a generic one:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:key name="columns" match="ROW/*" use="name()"/>

 <xsl:template match="BLOCK">
  <table border="1">
   <tr>
    <xsl:for-each select="ROW/*[count(.|key('columns',name())[1]) = 1]">
     <xsl:sort select="name()"/>
     <td><xsl:value-of select="name()"/></td>
    </xsl:for-each>
   </tr>
   <xsl:apply-templates/>
  </table>
 </xsl:template>

 <xsl:template match="ROW">
  <xsl:variable name="id" select="generate-id()"/>
  <tr>
   <xsl:for-each select="../ROW/*[count(.|key('columns',name())[1]) = 1]">
    <xsl:sort select="name()"/>
    <td><xsl:value-of select="../../ROW[generate-id() = $id]/*[name() =
name(current())]"/></td>
   </xsl:for-each>
  </tr>
 </xsl:template>
</xsl:stylesheet>


----- Original Message -----
From: "Michael Leditschke" <ammd@xxxxxxxxxxxxxx>
To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Cc: ""Robert Koberg"" <rob@xxxxxxxxxx>
Sent: Sunday, December 16, 2001 11:16 AM
Subject: Re:  Dynamically building a HTML table from variable row data


> Thanks for the reply Robert. The problem
> I have is that there are a large number of
> similarly formatted blocks but the sub-element
> names vary in each one. Thus hardcoding each
> one is something I'm trying to avoid if possible.
>
> Regards
> Michael
>
>
> how about:
>
> <xsl:template match="BLOCK">
>
> >   <table border="10">
>
>            <xsl:apply-templates select="row"/>
>
> >   </table>
> >  </xsl:template>
>
> <xsl:template match="ROW">
>
> <tr>
>     <td><xsl:value-of select="A"/></td>
>     <td><xsl:value-of select="B"/></td>
>     <td><xsl:value-of select="C"/></td>
>     <td><xsl:value-of select="D"/></td>
>     <td><xsl:value-of select="E"/></td>
> </tr>
>
>  </xsl:template>
>
>
>
> - ----- Original Message -----
> From: "Michael Leditschke" <ammd@xxxxxxxxxxxxxx>
> To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
> Sent: Saturday, December 15, 2001 8:25 AM
> Subject:  Dynamically building a HTML table from variable row data
>
>
> > I am attempting to populate an HTML table
> > where the column names are generated by the
> > set of element names on each row. Not all
> > elements occur on all rows.
> >
> > My problem is thus to dynamically work out
> > the total set of columns (using the element
> > names) and dynamically position each piece
> > of data in the correct column.
> >
> > For example, assume XML looks like
> >
> > <BLOCK>
> >   <ROW>
> >     <A>1</A>
> >     <B>2</B>
> >   </ROW>
> >   <ROW>
> >     <A>9</A>
> >     <B>3</B>
> >     <C>4</C>
> >   </ROW>
> >   <ROW>
> >     <A>5</A>
> >     <D>6</D>
> >     <E>7</E>
> >   </ROW>
> > <BLOCK>
> >
> > I'd like to end up with a table something like
> >
> > A  B  C  D  E
> > 1  2
> > 9  3  4
> > 5        6  7
> >
> >
> > Thus far I have code something like
> >
> > <xsl:template match="BLOCK">
> >   <xsl:variable name="ColumnNames"
> > select="ROW/*[not(local-name()=local-name(preceding::ROW/*)))]"/>
> >   <table border="10">
> >     <tr>
> >       <xsl:for-each select="$ColumnNames">
> >         <th>
> >           <xsl:value-of select="local-name()"/>
> >         </th>
> >       </xsl:for-each>
> >     </tr>
> >   </table>
> >  </xsl:template>
> >
> > I know its wrong because the local-name function is going
> > to process the first node only. So it handles the <A>
> > element ok but not any of the others.
> >
> > I'm trying to follow the
> > examples I've seen of grouping but most seem to be based
> > on element/attribute content rather than element names.
> >
> > Various wild and whacky schemes have come to mind but
> > before I looked for a zebra, I thought I'd check if anyone
> > knew of a horse.
> >
> > Any pointers much appreciated.
> >
> > Regards
> > Michael


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


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.