To read the article online, visit http://www.4GuysFromRolla.com/webtech/081300-2.2.shtml

Using XSL Stylesheets to Translate XML into HTML, Part 2

By Arno Jansen


  • Read Part 1

  • In Part 1 we looked at the various components of the XSL stylesheet for each part of the memo-style information: the TO, FROM, SUBJECT, etc. At this part we'll look at putting all of this information together!

    Now we know how to display the from tag, we also know how to display the TO, the SUBJECT and the MESSAGE tags. And you can make up the HTML output as fancy as you like, as long as you keep the three basic "XML rules of engagement" in mind, which are:

    • All tags that are opened, have to closed also and cannot have overlapping tags, only nested tags. (e.g. <I><U>something</U></I> is okay, but <I><U>something</I></U> is not okay)

    • All values of attributes have to be between quotes. (e.g. <TABLE BORDER="1"> instead of <TABLE BORDER=1>).

    • All tags are case sensitive. This means that <I> has to be closed by a </I> tag, and not a </i> tag.

    One small note is needed here: all empty tags (the ones that do not have a specific closing tag, such as <IMG>, <BR> and <HR>) need to have a forward slash just before there greater-than bracket. So, <BR> becomes <BR/>. Now we need enough to make the complete stylesheet for viewing a memo, which can be seen below.

    In Part 3 we'll look at ways to extend the XSL stylesheet to allow for a more detailed HTML output!

  • Read Part 3!


    <?xml version="1.0"?> 
    <xsl:stylesheet 
       xmlns:xsl="http://www.w3.org/TR/WD-xsl"
       xmlns="http://www.w3.org/TR/REC-html40" 
       result-ns="">
    
      <xsl:template match="/">
        <xsl:apply-templates />
      </xsl:template>		
    
      <xsl:template match="memo">
        <html>
          <head>
    	<title>XML/XSL memo example by Arno Jansen</title>
          </head>
          <body>
       	<xsl:apply-templates />
          </body>
          </html>
      </xsl:template>
    
      <xsl:template match="from">
        <B>
          From: 
        </B>
        <xsl:value-of select="."/><br/>
      </xsl:template>
    
      <xsl:template match="to">
        <B>
          To: 
        </B>
        <xsl:value-of select="."/>
         <br/>
      </xsl:template>
    	
      <xsl:template match="subject">
        <U>
          Subject: 
        </U>
        <xsl:value-of select="."/>
        <br/>
      </xsl:template>
    	
      <xsl:template match="message">
        <I>  
          <xsl:value-of select="."/>
        </I>
      </xsl:template>
    </xsl:stylesheet>
    


  • Article Information
    Article Title: Using XSL Stylesheets to Translate XML into HTML, Part 2
    Article Author: Arno Jansen
    Published Date: Sunday, August 13, 2000
    Article URL: http://www.4GuysFromRolla.com/webtech/081300-2.2.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers