Library tutorials & articles

XML Strengths & Weakness’ with DOM, ASP & XSL

Converting XML to HTML

We can maintain XML data on the server and format it into HTML using XSL and then send it to the client. We can do so using any server-side techniques, such as an ASP page. To use XSL, you need to first create an XSL document. This document is a glorified stylesheet, explaining how to display the various XML tags. For example, we could have the following XSL stylesheet:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
 <xsl:template match="/">
 <HTML>
 <STYLE>
   .fr1  { width: 30em; }
   BODY       { margin:0px; width: 30em;
                font-family: Arial, Helvetica, sans-serif; font-size: smaller;}
   P          { margin-top: .5em; margin-bottom: .25em; }
   HR         { color: #888888; }
   .H1        { color: #660033; font-weight: bold; vertical-align: top; }
   .Param     { font-size: smaller; vertical-align: top; }
   .tagline   { font-style: italic; font-size: smaller; text-align: right; }
   .body      { text-align: justify; background-color: #FFFFDD; }
   .dingbat   { font-family: WingDings; font-style: normal; font-size: xx-small; }
   .person    { font-weight: bold; }
   .label     { font-weight: bold; }
   .self      { font-style: italic; font-size: smaller;}
   #menu      { border: 2px solid black; padding: 1em; background-color: #888833; }
   .menutext  { color: #FFFFDD; font-family: Times, serif; font-style: italic;
                vertical-align: top; text-align:center; }
   .menuhead  { color: #FFFFDD; font-family: Times, serif; font-weight: bold;
                vertical-align: top; text-align:center; margin-bottom: .5em; }
 </STYLE>  
   <xsl:for-each select="Hi-Tech/Employee">
       <TABLE>
   <TR><TD Class="H1"><xsl:value-of select="Name" /></TD> </TR>
   <TR>
   <xsl:for-each select="Titles">
   <TR><TD><xsl:entity-ref name="nbsp"/></TD>
         <TD Class="H1"><xsl:value-of select="TitleId" /></TD>
         <TD Class="H1"><xsl:value-of select="royalty" /></TD>
   </TR>
   </xsl:for-each></TR>
       </TABLE>
  </xsl:for-each>
 </HTML>
 </xsl:template>
</xsl:stylesheet>

This XSL stylesheet can then be loaded and applied using the transformNode method. (For an example of this, see the previous code example, where, at the end, we displayed the XML data from an ADO recordset using an XSL stylesheet.

Well, I hope this article has answered some of your questions on XML. Hopefully you've learned some of the advantages and disadvantages of XML, when it should be used, and how it can be used.

Comments

  1. 11 Dec 2005 at 12:29

    Hi


    Do you have any experiences about the performance of automate generated HTML by XSL & XML


    for example which one is faster:


    1. seperate Asp-Sites
    2. 1 Asp-Site that was generated by 1 XSL-Site (C# XslTransform)


    Thanks
    Schneeblitz

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of XML Strengths & Weakness’ with DOM, ASP & XSL.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related discussion

Related podcasts

  • Java Posse #202 - Newscast for Aug 22nd 2008

    Newcast for August 22nd, 2008Fully formatted shownotes can always be found at http://javaposse.com Sadly, Java does not run on the Mars LanderThe Golden Gate Project http://research.sun.com/projects/goldengate/Space surveillance radar http://www.sun.com/aboutsun/pr/2008-04/sunflash Google has r...

Related jobs