Expressions and Location Paths

This section describes expressions and location paths. A sequence of data objects, operators, grouping parenthesis and function calls is called a location path, if it is used to represent a set of nodes in the source XML document.

Expression: A sequence of data objects, operators, grouping parenthesis and function calls. Examples of expressions:

( 6 + 2 ) * 3 div 4

Location Path: An expression resulting a node set of the source XML document. The semantics for a location path is:

LocationPath ::= RelativeLocationPath | AbsoluteLocationPath

AbsoluteLocationPath ::= '/' | '/'RelativeLocationPath

RelativeLocationPath ::= LocationStep 
   | RelativeLocationPath'/'LocationStep

LocationStep ::= AxisName'::'NodeTest | LocationStep'['Predicate']'
   | LocationStep'|'LocationStep

AxisName ::= 'ancestor' | 'ancestor-or-self' | 'attribute' | 'child' 
   | 'descendant' | 'descendant-or-self' | 'following' 
   | 'following-sibling' | 'namespace' | 'parent' | 'preceding' 
   | 'preceding-sibling' | 'self' 

NodeTest ::= NameTest | 'node()' | 'text()' | 'comment()' 
   | 'processing-instruction()' 
   | 'processing-instruction(' StingLiteral ')' 
NameTest ::= '*' | NameSpacePrefix':*' | NameSpacePrefix':'NodeName

NodeName ::= Any node name in the XML structure

StringLiteral ::= A sequence of valid characters enclosed in quotes

Predicate ::= A boolean expression | AxisName'::'NodeTest

Note that there are two operators introduced in here:

Evaluation rules on location path:

There is a number of abbreviations for the axis name and node test parts of the location step:

.       self::node()
..      parent::node()
name    child::name
@name   attribute::name
//      /descendant-or-self::node()/

Let's look at some examples of location paths:

Last update: 2014.

Table of Contents

 About This Book

 Introduction of XML (eXtensible Markup Language)

 XML File Syntax

 XML File Browsers

 DOM (Document Object Model) Programming Interface

 SAX (Simple API for XML) Programming Interface

 DTD (Document Type Definition) Introduction

 Syntaxes of DTD Statements

 Validating an XML Document against the Specified DTD Document Type

 XSD (XML Schema Definition) Introduction

 Syntaxes of XSD Statements

 Validating XML Documents Against Specified XML Schemas

 XSL (Extensible Stylesheet Language) Introduction

 XSLT (XSL Transformations) Introduction

 Java Implementation of XSLT

XPath (XML Path) Language

 What is XPath (XML Path)?

 Data Types, Literals and Variables

 Evaluation Context

 Built-in Functions

Expressions and Location Paths

 Using XPath in XSLT Templates

 XSLT Elements as Programming Statements

 Control and Generate XML Element in the Result

 XML Notepad - XML Editor

 XML Tools Plugin for Notepad++

 XML 1.1 Changes and Parsing Examples

 Outdated Tutorials


 PDF Printing Version