Sample XSLT File for ASP XSLT Processor Objects
The following is the sample XSLT file.
XSLT File (CatalogFilter.xsl)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
version="1.0">
<xsl:output method="html"/>
<xsl:param name="selected_genre" select="'all'"/>
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Displayed Catalog</TITLE>
</HEAD>
<BODY>
<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>
<FORM method="post" action="catalog.asp">
Genre
<SELECT name="genre" value="{$selected_genre}" onchange="submit()">
<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"/>
</BODY>
</HTML>
</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>