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

Re: xsl template for simple data-base to transform int

Subject: Re: xsl template for simple data-base to transform into html displayable table
From: "cking" <cking@xxxxxxxxxx>
Date: Fri, 3 Sep 2004 08:45:11 +0200
xsl generic transform table
Bovy, Stephen J wrote:
>

> 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 ?? 
>
> is there a value of element-name ????
>

The name of an element can be obtained with the XPath function 
local-name(). There's also the name() function, returning the
name with its namespace identifier.

Here's a "generic" stylesheet - it will transform any input file
that has the same structure as yours, no matter what the element
names are and no matter how many columns:

<root>
    <row-1>
        <col-A>...</col-A>
        <col-B>...</col-B>
        ...
    </row-1>
    ...
</root>

I changed the templates' select and match attributes to
match all element names ("/*/*/*" means: any element at the 
third level from the root)

Here's some good starting points for learning XSLT/XPath basics:
http://www.w3schools.com/xsl/default.asp
http://www.zvon.org/o_html/group_xsl.html


Cheers
Anton Triest


<?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>
     <xsl:value-of select="local-name(/*)"/>
    </title>
   </head>
   <body>
    <xsl:apply-templates/>
   </body>
  </html>
 </xsl:template>

 <xsl:template match="/*">
  <table border="1">
   <tr>
    <xsl:apply-templates select="/*/*[1]/*" mode="header"/>
   </tr>
   <xsl:apply-templates/>
  </table>
 </xsl:template>

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

 <xsl:template match="/*/*/*" mode="header">
  <th><xsl:value-of select="local-name()"/></th>
 </xsl:template>

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

</xsl:stylesheet>

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.