Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XSLT Developer's Guide

Sample HTML File for XML Data Islands

XML File (book_catalog.xml)

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <title>XML Developer's Guide</title>
      <author>Gambardella, Matthew</author>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>      
      <description>An in-depth look at creating applications with XML.</description>
   </book>
   <book id="bk102">
      <title>Midnight Rain</title>
      <author>Ralls, Kim</author>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description>
   </book>
   <book id="bk103">
      <title>Maeve Ascendant</title>
      <author>Corets, Eva</author>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-11-17</publish_date>
      <description>After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.</description>
   </book>
   <book id="bk104">
      <title>Oberon's Legacy</title>
      <author>Corets, Eva</author>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-03-10</publish_date>
      <description>In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant.</description>
   </book>
   <book id="bk105">
      <title>The Sundered Grail</title>
      <author>Corets, Eva</author>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-09-10</publish_date>
      <description>The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy.</description>
   </book>
   <book id="bk106">
      <title>Lover Birds</title>
      <author>Randall, Cynthia</author>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-09-02</publish_date>
      <description>When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled.</description>
   </book>
   <book id="bk107">
      <title>Splish Splash</title>
      <author>Thurman, Paula</author>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>A deep sea diver finds true love twenty thousand leagues beneath the sea.</description>
   </book>
   <book id="bk108">
      <title>Creepy Crawlies</title>
      <author>Knorr, Stefan</author>      
      <genre>Horror</genre>
      <price>4.95</price>
      <publish_date>2000-12-06</publish_date>
      <description>An anthology of horror stories about roaches, centipedes, scorpions  and other insects.</description>
   </book>
   <book id="bk109">
      <title>Paradox Lost</title>
      <author>Kress, Peter</author>
      <genre>Science Fiction</genre>
      <price>6.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum.</description>
   </book>
   <book id="bk110">
      <title>Microsoft .NET: The Programming Bible</title>
      <author>O'Brien, Tim</author>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-09</publish_date>
      <description>Microsoft's .NET initiative is explored in detail in this deep programmer's reference.</description>
   </book>
   <book id="bk111">
      <title>MSXML3: A Comprehensive Guide</title>
      <author>O'Brien, Tim</author>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-01</publish_date>
      <description>The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more.</description>
   </book>
   <book id="bk112">
      <title>Visual Studio 7: A Comprehensive Guide</title>
      <author>Galos, Mike</author>
      <genre>Computer</genre>
      <price>49.95</price>
      <publish_date>2001-04-16</publish_date>
      <description>Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment.</description>
   </book>   
</catalog>

HTML File (DataIsland.htm)

<HTML>
<HEAD>
   <TITLE>Untitled</TITLE>
    <STYLE>
        .catalog_genre_head {background-color:darkGreen;font-size:24pt;color:white;font-family:Impact;}
        .catalog_head {background-color:green;font-size:18pt;color:white;font-family:Impact;}
        .catalog_row0 {background-color:lightGreen;}
        .catalog_row1 {background-color:white;}
        .catalog_row_end {background-color:darkGreen;}
    </STYLE>
</HEAD>

<BODY>
<H1>Scootney Press Book Catalog</H1>
<P>Select a genre to see all books in that genre:</P>
<DIV id="catalog_table"></DIV>

<xml id="book_catalog" src="book_catalog.xml">
</xml>

<xml id="catalog_filter">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt"
        version="1.0">
    
        <xsl:output method="xml" omit-xml-declaration="yes"/>
        
        <xsl:param name="selected_genre" select="'all'"/>
        
        <xsl:template match="/">
                <div>
                    <form method="post" action="catalog.asp">
                    Genre
                    <select name="genre" value="{$selected_genre}" onchange="showGenre(this.value)">
                        <option value="all"><xsl:if test="$selected_genre='all'"><xsl:attribute name="selected">Selected</xsl:attribute></xsl:if>All</option>
                        <option value="Computer"><xsl:if test="$selected_genre='Computer'"><xsl:attribute name="selected">Selected</xsl:attribute></xsl:if>Computer</option>
                        <option value="Fantasy"><xsl:if test="$selected_genre='Fantasy'"><xsl:attribute name="selected">Selected</xsl:attribute></xsl:if>Fantasy</option>
                        <option value="Horror"><xsl:if test="$selected_genre='Horror'"><xsl:attribute name="selected">Selected</xsl:attribute></xsl:if>Horror</option>
                        <option value="Romance"><xsl:if test="$selected_genre='Romance'"><xsl:attribute name="selected">Selected</xsl:attribute></xsl:if>Romance</option>
                        <option value="Science Fiction"><xsl:if test="$selected_genre='Science Fiction'"><xsl:attribute name="selected">Selected</xsl:attribute></xsl:if>Science Fiction</option>
                    </select>
                    </form>
                    <br/>
                    <xsl:apply-templates select="catalog"/>
            </div>                    
        </xsl:template>
        
        <xsl:template match="catalog">
            <table class="catalog_table">
                <xsl:apply-templates select="book[($selected_genre='all') or ($selected_genre=./genre)]">
                    <xsl:sort select="title"/>
                </xsl:apply-templates>
            </table>
        </xsl:template>
        
        <xsl:template match="book">
            <xsl:if test="position()=1">
            <tr class="catalog_genre_head"><td colspan="6">
            <xsl:choose>
            <xsl:when test="$selected_genre='all'">
            All Genres
            </xsl:when>
            <xsl:otherwise>
            Genre: <xsl:value-of select="genre"/>
            </xsl:otherwise>
            </xsl:choose>
            </td></tr>            
            <tr class="catalog_head">
                <td>#</td>
                <td>Title</td>
                <td>Author</td>
                <td>Publication Date</td>
                <td>Description</td>
                <xsl:if test="$selected_genre='all'">
                <td>Genre</td>
                </xsl:if>
            </tr>
            </xsl:if>
            <tr class="catalog_row{position() mod 2}">
                <td><xsl:value-of select="position()"/></td>
                <td class="catalog_cell"><xsl:value-of select="title"/></td>
                <td class="catalog_cell"><xsl:value-of select="author"/></td>
                <td class="catalog_cell"><xsl:value-of select="publish_date"/></td>                    
                <td class="catalog_cell"><xsl:value-of select="description"/></td>
                <xsl:if test="$selected_genre='all'">
                <td class="catalog_cell"><xsl:value-of select="genre"/></td>
                </xsl:if>
            </tr>
            <xsl:if test="position()=last()">
            <tr class="catalog_row_end"><td colspan="6"> </td></tr>
            </xsl:if>
        </xsl:template>
    </xsl:stylesheet>
</xml>


<SCRIPT language="JavaScript">
function loadSource(sourceObj){
    var xmlDoc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument.5.0");
    xmlDoc.async=false;
    xmlDoc.load(sourceObj.XMLDocument);
    return xmlDoc;
    }

var table_proc=null;

function getProcessor(transformObj){
    if (table_proc==null){
        var xslDoc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument.5.0");
        var xslTemplate=new ActiveXObject("Msxml2.XSLTemplate.5.0");
        xslDoc.async=false;
        xslDoc.load(transformObj.XMLDocument);
        xslTemplate.stylesheet=xslDoc;
        xslProcessor=xslTemplate.createProcessor();
        table_proc=xslProcessor;
        }
    else {
        xslProcessor=table_proc;
        }
    return xslProcessor;
    }
    
function transformData(srcDoc,processor){
    var resultDoc=new ActiveXObject("MSXML.DOMDocument");
    processor.input=srcDoc;
    processor.output=resultDoc;
    processor.transform();
    return resultDoc;
    }

function showGenre(genre){
    var srcDoc=loadSource(book_catalog);
    var processor=getProcessor(catalog_filter);
    processor.addParameter("selected_genre",genre);
    var rsltDoc=transformData(srcDoc,processor);
    catalog_table.innerHTML=rsltDoc.xml
    }    

showGenre("all");    

</SCRIPT>

</BODY>
</HTML>