March 28, 2024

Filtering XML Data

 

We can choose to view data by applying a filter. Download and save this file, which contains some modifications to the XSL that you saw on the previous page. To link this XSL file to the XML data, a small change is required to the book.xml file. Open book.xml in Notepad and change the line that reads
<?xml-stylesheet type="text/xsl" href="book.xsl"?>

to read

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

Save the change and then open book.xml in your IE6 browser.

Browser output displaying titles, with corresponding year, of books by James Lee Burke

 

Look at the XSL instruction (open book2.xsl in Notepad)
<xsl:for-each select="CATALOGUE/BOOK[AUTHOR='James Lee Burke']">
You have already seen the for-each and select instructions. The filter AUTHOR='James Lee Burke' is used to access data only where the corresponding nested value of the AUTHOR element is James Lee Burke; anything else will be ignored. Once this is achieved, the next two lines get the values for TITLE and YEAR and insert them into the cells of a table
<td><xsl:value-of select="TITLE"/></td>
<td><xsl:value-of select="YEAR"/></td>

 

Next page » Sorting XML data

Previous page « Transformation of XML data using XSL

 

 

 

 

 

 

 

 

 

 

 

 

Up to top of page