Advertise Here
Need an introduction to XML Extensible Stylesheet Language? Learn how to use XSL to transform XML documents into HTML documents. Learn how the style sheet language of XML can transform XML documents into HTML documents for XSL clients, XSL servers, and more. - Web06
Extensible Markup Language

Search XML Files:

XML Files RSS Feed XML Files Updates

 

DEVELOPER CHANNEL
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

Find a Web Host With:
CGI Capabilities
Active Server Pages
Windows Hosting
Unix Hosting
Dedicated Servers
     
 Advanced Search
 Be a Commerce Partner















IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

XSL Filter Query

by Jan Egil Refsnes

prev next

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" ?>
<CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1985</YEAR>
  </CD>
.
.
.

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="/">
  <html>
  <body>
    <table border="2" bgcolor="yellow">
      <tr>
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="CATALOG/CD[ARTIST='Bob Dylan']">
      <tr>
        <td><xsl:value-of select="TITLE"/></td>
        <td><xsl:value-of select="ARTIST"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>


Transforming it on the Client

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

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

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

// Transform
document.write(xml.transformNode(xsl))
</script>

</body>
</html>


prev next
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 DevX XML Content 
- W3C Has a New XML Standard: XProc
- Create a Map Client with Web Services, Part II
- Why Data as a Service Will Reshape EAI
- Transitioning from XSLT 1.0 to 2.0, Part 2
- Transition from XSLT 1.0 to XSLT 2.0, Part 1

Jump to : Top Of Page or HOME


Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers