Step 2: Matching Patterns

You can make the display more readable by creating a new XSL file that transforms the heading data in the Sales.xml file into a presentable format.

To transform the heading data

  1. Use the Copy and Paste commands to place the following text into your HTML editor.

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="">
      <xsl:template match="/">
            <TITLE><xsl:value-of select="//summary/heading"/></TITLE>
            <h1><xsl:value-of select="//summary/heading"/></h1>
            <h2><xsl:value-of select="//summary/subhead"/></h2>
            <p><xsl:value-of select="//summary/description"/></p>
  2. Save the file as Transform.xsl*.*

  3. Open Sales.xml in your HTML editor and add the following line directly below <?xml version="1.0"?>.

    <?xml-stylesheet type="text/xsl" href="transform.xsl"?>

    This identifies the XSL file to be used for formatting information.

  4. Save Sales.xml.

  5. To view the file in Internet Explorer, open Sales.xml.

    The summary information for your sales report is formatted so it is easy to view.

How It Works

The xsl: lines at the beginning and end of Transform.xsl tell Internet Explorer that this is an XSL file. The XSLT parser looks for patterns in the XML data as indicated by <xsl:value-of select=. For example, select="//summary/heading" directs the parser to look for a <heading> tag that is contained in a <summary> tag. When the parser locates this pattern, the tag is formatted as an HTML <h1> tag.

See Also

Step 3: Looping Through Data | Step 1: Creating the Sales.xml File | Tutorial: Getting Started with XSLT | Exploring XSLT Capabilities | XSLT Developer Guide

 Last updated on Saturday, April 10, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.