XML
  Home arrow XML arrow Page 7 - XPath Basics
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
XML

XPath Basics
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Dell PowerEdge Servers

    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

    - 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...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway