RE: [xsl] xsl template for simple data-base to transform into html displayable table

Subject: RE: [xsl] xsl template for simple data-base to transform into html displayable table
From: "Bovy, Stephen J" <STEPHEN.Bovy@xxxxxx>
Date: Thu, 2 Sep 2004 19:11:08 -0400
Wow, this is great, I really like it,

Now is their a way to generate the table column headings with out
hard-coding the element names ??

<tr>
    <th>name</th>
    <th>address</th>
    <th>phone-number</th>
    <th>part-number</th>
    <th>quantity</th>
    <th>price</th>
    <th>total</th>
   </tr>

is there a value of element-name ????


-----Original Message-----
From: cking [mailto:cking@xxxxxxxxxx]
Sent: Thursday, September 02, 2004 2:51 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] xsl template for simple data-base to transform into
html displayable table

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
 xmlns="http://www.w3.org/1999/xhtml";
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 >
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
  />

 <xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml";>
   <head>
    <title>Purchase-Orders</title>
   </head>
   <body>
    <xsl:apply-templates/>
   </body>
  </html>
 </xsl:template>

 <xsl:template match="Purchase-Orders">
  <table border="1">
   <tr>
    <th>name</th>
    <th>address</th>
    <th>phone-number</th>
    <th>part-number</th>
    <th>quantity</th>
    <th>price</th>
    <th>total</th>
   </tr>
   <xsl:apply-templates select="Purchase-Order"/>
  </table>
 </xsl:template>

 <xsl:template match="Purchase-Order">
  <tr><xsl:apply-templates/></tr>
 </xsl:template>

 <xsl:template match="Purchase-Order/*">
  <td><xsl:value-of select="."/></td>
 </xsl:template>

</xsl:stylesheet>

This will work if you are certain that the children of <Purchase-Order>
always occur in the same order. If you're not, you can replace the last
two templates with this one:

 <xsl:template match="Purchase-Order">
  <tr>
   <td><xsl:value-of select="name"/></td>
   <td><xsl:value-of select="address"/></td>
   <td><xsl:value-of select="phone-number"/></td>
   <td><xsl:value-of select="part-number"/></td>
   <td><xsl:value-of select="quantity"/></td>
   <td><xsl:value-of select="price"/></td>
   <td><xsl:value-of select="total"/></td>
  </tr>
 </xsl:template>

Cheers,
Anton Triest

Current Thread