Library sample chapters
Using XML Queries and Transformations
- Introduction
- XPath Query Syntax
- Building a Path
- Selecting Subsets
- Built-In Functions
- IE5 Conformance
- XLST
- XLST Elements
- Pre-defined Templates
- Number Calculation Example
- Commands
- Control of Flow
- Variables and Parameters
- Top Level Settings
- Built-in Functions
- Simplified Syntax
- The IE5 Implementation
- XLST Examples
- Giving Style to XML
- Summary
Building a Path
Several of the XPath expressions we have seen up until now can be appended
to each other to form a longer expression. This is done in a way similar to
building a full directory path from several directory names: by separating them
with forward slashes. The first expression in the path is evaluated in the original
context; the result set from this expression forms the context for the next.
Each of the nodes in the result set is used as context for the expression that
follows, and all the results of each query are combined to one result set at
the end. This would work as follows: this command selects the parent
element of all name
elements along the descendant axis of our context node:
descendant::name/parent::*
This selects all text nodes from paragraph
elements that are children of chapter elements that are children of
book
elements that are children of our context node:
child::book/child::chapter/child::paragraph/child::text()
Absolute vs. Relative Paths
Just as with directory paths, we can make the XPath expression absolute
by prefixing a slash. This sets the expression context to the document root.
This is not the root element (compare with the documentElement
attribute of the DOMDocument object in the DOM), but the parent of the root
element (compare with the DOMDocument object itself). This example
would select all attributes on the root element:
/child::*/attribute::*
However, the next example would select nothing, because the document root cannot carry attributes:
/attribute::*
An XPath that consists of only a slash (/)
always refers to the document root.
Abbreviated Form / IE5 Compatible Form
The abbreviated notation of XPath is intended to keep the queries shorter. But the most important reason to learn the shorthand notation is that it used to be the full notation (according to the working draft) at the moment that the first release of IE5 hit the shops. In fact, it wasn't even called XPath back then, but was part of the XSL specification, which was later split up in three parts. (More on that later in this chapter.) That's why in IE5, only the shorthand syntax of XPath is implemented (in January 2000; Microsoft released a preview of the newer version of the library, which will support the full XPath specification). The main rulesĀ for the abbreviated syntax are:
|
Shorthand Rule |
Example |
|
The |
|
|
The |
|
Table Continued on Following Page
|
Shorthand Rule |
Example |
|
The |
|
|
The |
|
|
The |
|
So these XPath expressions are valid in the IE5 implementation. The first command
returns all ID
attributes from TABLE elements in the whole document:
//TABLE/@ID
While this returns all text nodes that are children of PARAGRAPH
elements that are children of CHAPTER elements that are children of
the context element:
CHAPTER/PARAGRAPH/text()
Related articles
Related discussion
-
How to import Xml file into a table in MS-ACCESS database using Visual Basic 6.0?
by sutanu_halder (0 replies)
-
XML transformation: how to save it into a hmtl file.
by srinathnrk (1 replies)
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
The table under "format attribute" on the following page also seems to be truncated: http://www.developerfusion.com/show/89/10/
my apologies for that, it appears the article became truncated. The rest of the text on 'giving style to XML' is now there.
Regards,
The 'giving style to XML' part of the article (which is the only part that interested me, sigh) is apparently corrupt - It ends in the middle of a sentence, and so it doesn't explain one bit of what it promises to...
This thread is for discussions of Using XML Queries and Transformations.