xsl-list
[Top] [All Lists]

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

2004-09-02 16:11:08
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(_at_)telenet(_dot_)be] 
Sent: Thursday, September 02, 2004 2:51 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--