March 29, 2024

Applying selection to XML data

 

Data can be selected according to some criteria or condition. This is a common programming mechanism and you will use it in JavaScript programming.

Download and save this file and modify your book.xml file with this line
<?xml-stylesheet type="text/xsl" href="book4.xsl"?>

Reload book.xml

Browser output displaying titles and authors of books published before 2000.

 

In this case if the value of the YEAR element is less than 2000, then the values of the TITLE and AUTHOR elements will be selected for output. Note that:

  • The XSL syntax for "is less than" is &lt; in the line
    <xsl:if test="YEAR &lt; 2000">
    You can try other selections using
    = meaning equal
    != meaning not equal
    &gt; meaning is greater than
  • Unlike the instruction for sorting, the XSL <xsl:if test> element requires a matching
    </xsl:if>

Next page » Applying more complex selection

Previous page « Sorting XML Data

 

 

 

 

 

 

 

 

 

 

 

 

Up to top of page