XPath Boolean Operators

A list of Boolean operators used in XPath expression.

Index Operator Description
1) and It specifies that both conditions must be satisfied.
2) or It specifies that any one of the condition must be satisfied.
3) not() It specifies function to check condition not to be satisfied.

XPath Boolean Operator Example

Let's take an example to create a table of element with its attribute id and its child <firstname>,<lastname> <nickname> and <salary> . In this example, it checks id to be either 001 or 003 and then prints the details.


<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "employee.xsl"?>
   <employee id = "001">
   <employee id = "002">
    <employee id = "003">
    <employee id = "004">


<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
   xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">  
   <xsl:template match = "/">
            <table border = "1">
               <tr bgcolor = "pink">
                  <th>First Name</th>
                  <th>Last Name</th>
                  <th>Nick Name</th>
               <xsl:for-each select = "class/employee[(@id = 001) or ((@id  =  003))]">					
                     <td><xsl:value-of select = "@id"/></td>
                     <td><xsl:value-of select = "firstname"/></td>
                     <td><xsl:value-of select = "lastname"/></td>
                     <td><xsl:value-of select = "nickname"/></td>
                     <td><xsl:value-of select = "salary"/></td>


XPATH Boolean operators 1
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +