When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Sunday, August 13, 2000

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!

    - continued -

    '

    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>
    



  • ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article