|
Originally based on XML Visual Quickstart Guide (chpt.03) by Kevin Howard Goldberg, and notes therefrom by Jack Davis (jcdavis@radford.edu).
video not yet createdIn the last chapter XSL templates were described and examined. When you apply a template,
you use an expression to specify the node set that should be processed. You write
both patterns and expressions using XML Path Language (XPath) syntax.
XPath is a language for selecting nodes and node sets by specifying their location
paths in the XML document. This chapter will describe how to specify XPath location
paths in detail. XPath can be used in XSLT instructions to further process given node sets to
return values instead of nodes. XPath has built-in functions to do math, process strings,
and test conditions in an XML document. The next chapter, XPath Functions, will
describe these functions.
Here is a nice website: an xpath interpreter: chris.photobooks.com/xml/
/* the name of every wonder, but only those with a language * attribute equal to 'English'*/ /ancient_wonders/wonder/name[@language='English'] /* the name node of the last wonder. */ /ancient_wonders/wonder[position()==last()]/name |
Task: What is an xpath expression to find all wonder nodes which have both a greek and english name?
As a corollary: If processing the root-node, then //elementName matches all the nodes named elementName in the entire document.
Usually, you use relative paths.
Beware when using absolute paths inside a loop —
it'll always return the same value!
xpath-ch03-17.xml(bug: absolute xpath in loop)
xpath-ch03-17.xsl(bug: absolute xpath in loop)
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |