CHAPTER 4 XPATH, XPOINTER, XINCLUDE, AND THE
CHAPTER 4 XPATH, XPOINTER, XINCLUDE, AND THE FUTURE 161 sum(for $x in /store/* return if($x/@qty > 25) then $x/@qty * $x/price else 0) You could, of course, have performed this in a much simpler manner: sum(for $x in /store/*[@qty > 25] return $x/@qty * $x/price) The last portion of XPath 2.0 I will cover is quantified expressions. These expressions allow a test against a sequence and return TRUE or FALSE depending upon the quantifier used and whether every item in the sequence evaluates to TRUE or only some do. For example, to test whether every item in the store has a price of 12.99, you could use the following expression: every $x in /store/*/price satisfies $x = 12.99 This expression returns FALSE. The price for the items varies, and only one item has a price of 12.99. You could modify the expression using the some quantifier, which returns TRUE if any of the priceelements have a value of 12.99: some $x in /store/*/price satisfies $x = 12.99 This expression returns TRUE, because a book element exists that has a price equal to 12.99. As you can see, XPath 2.0 is extremely more powerful than XPath 1.0. This brief introduction has only touched the surface of what is contained within XPath 2.0. Many additional functions and keywords perform tasks such as casting, instance-of checking, and schema data typing. In time, these technologies may be available for use with libxml and PHP, but as I have mentioned, there is currently no planned support. By the time you are reading this, things may have changed, but unless the specifications become recommendations soon, I highly doubt it. Conclusion The primary focus of this chapter was on XPath 1.0, XPointer, and XInclude. The material presented should give you enough information about the concepts and actual use of these technologies to utilize them in PHP. Future chapters will build upon what you have learned here and provide you with ways to use this information in the PHP 5 programming environment. You also learned about XPath 2.0 in this chapter. Although PHP doesn t support XPath 2.0, XQuery, or XSLT 2.0, you may encounter an extension at a future date that uses one of these technologies. Using everything you have learned to this point, it is time to begin exploring how to use XML in PHP 5. The next chapter will introduce you to some functionality that is common to the XML-based extensions in PHP.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services