XSL Filtering

XSL Filter Query

Where to put the Filter Information

Take a new look at the XML document that you have seen in almost every chapter (or open it with IE5):

<?xml version="1.0" encoding="ISO8859-1" ?>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>

To filter the XML file, simply add filter to the select attribute in your for-each element like this:

<xsl:for-each select=”CATALOG/CD[ARTIST=’Bob Dylan’]”>

Leagal filter operators are:

  • =  (equal)
  • =! (not equal)
  • &LT& less than
  • &GT& greater than

Now take a look at your slightly adjusted XSL stylesheet (or open it with IE5):

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
    <table border="2" bgcolor="yellow">
      <xsl:for-each select="CATALOG/CD[ARTIST='Bob Dylan']">
        <td><xsl:value-of select="TITLE"/></td>
        <td><xsl:value-of select="ARTIST"/></td>


Transforming it on the Client

Here is the simple source code needed transform the XML file to HTML on the client (try it yourself):

<script language="javascript">
// Load XML 
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false

// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false

// Transform