Home arrow XML arrow Page 7 - XPath Basics

Operating With Extreme Caution - XML

One of the fundamental constructs for XSL transformations and XML links, XPath is nonetheless one of the lesser lights of the XML universe. However, if you're serious about developing your XML skills, you need to know it inside out - and this tutorial has all you need to get started.

TABLE OF CONTENTS:
  1. XPath Basics
  2. Dog Days
  3. First Steps
  4. Revolving Around An Axis
  5. Proof Of The Pudding
  6. Playing Chicken
  7. Operating With Extreme Caution
  8. Be Cool
  9. The Next Step
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 6
August 15, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
In addition to what you've just seen, XPath also allows you to build expressions using simple logical and comparison operators. Consider the following table, which illustrates the common ones with examples:


Operator What It Means Example ---------------------------------------------------------------------------- -- = is equal to item[desc = 'Ginger'] != is not equal to item[desc != 'Ginger'] is greater than servings > 2 < is less than servings < 5 = is greater than or equal to servings >= 2 <= is less than or equal to servings <= 10


Most of these comparison operators are used in conjunction with XSLT's "if" and "choose" tests (note that if you use them in an XSLT stylesheet, the < symbol must be replaced with the pre-defined XML entity < to avoid XML errors.).

You can combine expressions using the "and" and "or" operators,


Operator Example ---------------------------------------------------------------------------- --

and desc = 'Ginger' and quantity = '1 tsp'

or desc = 'Cinnamon' or servings >= 3


Here's an example of how you could apply this in an XSLT stylesheet:


<xsl:template match="/"> <xsl:if test="//item/desc = 'Cinnamon' or //servings >= 3"> <xsl:value-of select="//name"/> </xsl:if> </xsl:template>


Finally, you can perform arithmetic operations with the various arithmetic operators:


Operator What It Means Example ---------------------------------------------------------------------------- -- + Addition quantity + 5 - Subtraction quantity - 5 * Multiplication quantity * 5 div Division quantity div 5 mod Modulo quantity mod 5


Here's an example of how you could apply this in an XSLT stylesheet:


<xsl:template match="/"> Current servings: <xsl:value-of select="//servings"/> Updated servings: <xsl:value-of select="//servings * 6"/> </xsl:template>


This article copyright Melonfire 2001. All rights reserved.

 
 
>>> More XML Articles          >>> More By Vikram Vaswani, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: