Cheap Web Hosting for Developers

PHP, MySQL, Java, Unix Cheap Web Hosting

160 CHAPTER 4 XPATH, XPOINTER, XINCLUDE, AND

Filed under: PHP and XML — webmaster @ 18:26

160 CHAPTER 4 XPATH, XPOINTER, XINCLUDE, AND THE FUTURE Of Mice and Men 9.99 2002-10-01 2.99 Using XPath 1.0, you can retrieve all bookand magazine elements with the following: /store/*[self::book or self::magazine] This query would return all the book and magazine elements in document order, which means you would have a node set that contained a book element, a magazine element, a book element, and finally a magazine element. Under XPath 2.0, you could modify the query to retrieve all book elements followed by all magazine elements, followed again by all bookelements. This type of query is not possible under XPath 1.0, because a node set could never contain the same element more than once. For example: (/store/book, /store/magazine, /store/book) This expression is a sequence, where a comma separates each query. The first query retrieves all bookelements, the second query retrieves all magazine elements, and the last query retrieves all book elements again. The result would be a sequence containing the nodes in the order just detailed. As you saw when performing calculations using XPath 1.0, you had no way to generate the total value of inventory on hand. This is now possible using XPath 2.0. Sequences are iterable. It is similar to being able to perform a foreach in PHP: for $x in /store/* return $x/@qty * $x/price This expression, after every iteration has been performed, will return a sequence containing the value of qty*price for each element in the store. The sequence returned would be (324.75, 224.25, 249.75, 14.95). You could then use this sequence within the sumfunction. The sum function in XPath 2.0 takes a sequence, not a node set: sum(for $x in /store/* return $x/@qty * $x/price) The end result would be 833.7, which is the value of the inventory on hand within the store. Another nice addition is if/then/else. The specification s example looks like this: if ($widget1/unit-cost < $widget2/unit-cost) then $widget1 else $widget2 If my interpretation is correct, then you could calculate the total value on hand for items with a quantity greater than 25 with the following:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Cheap Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Cheap Web Hosting