XML
  Home arrow XML arrow Page 7 - XPath Basics
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
XML

XPath Basics
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2001-08-15


    Table of Contents:
  • XPath Basics
  • Dog Days
  • First Steps
  • Revolving Around An Axis
  • Proof Of The Pudding
  • Playing Chicken
  • Operating With Extreme Caution
  • Be Cool
  • The Next Step

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    XPath Basics - Operating With Extreme Caution
    ( Page 7 of 9 )

    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
     

       

    XML ARTICLES

    - 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...
    - Practical XML Data Design and Manipulation f...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek