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.

You might also like...

Comments

About the author

Nakul Goyal

Nakul Goyal India

Nakul Goyal, currently doing Master of Sciences in Information Technology from Panjab University, Chandigarh. A Bachelor of Computer Applications from Punjab Technical University, he is passiona...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov