Skip to Content

XPath

XPath, XML Path Language, is a language used to identify specific tags and nodes within an XML document. In OU Campus, the XML document is modeled as a tree structure with a single root node defined as <document>.

Axis Selection OptionsLink to this section

An axis is a relationship between a specific node identified using XPath and other nodes within the file's tree structure. Below is a listing of commonly used axis options within OU Campus.

Axis Option Description Example
ancestor Selects all ancestors of the specified node including parent nodes, parent of parent nodes, etc.
<xsl:copy-of select="ancestor::p" />
ancestor-or-self Selects the specified nodes and all ancestor nodes.
<xsl:copy-of select="ancestor-or-self::p" />
attribute Selects the specified nodes attributes.
<xsl:copy-of select="p/attribute()" />
child Selects the immediate child nodes of the specified node.
<xsl:copy-of select="child::p" />
descendant Selects all descendants of the specified node including child nodes, child of child nodes, etc.
<xsl:copy-of select="descendant::p" />
descendant-or-self Selects the specified nodes and all descendent nodes.
<xsl:copy-of select="descendant-or-self::p" />
following Selects all nodes that appear after the specified node but excludes any direct ancestors.
<xsl:copy-of select="following::p" />
following-siblings Selects all nodes that appear after the specified node and are at the same depth within the file's tree structure.
<xsl:copy-of select="following-sibling::p" />
parent Selects all the parents of the specified node.
<xsl:copy-of select="parent::p" />
preceding Selects all nodes that appear before the specified node but excludes any direct ancestors.
<xsl:copy-of select="preceding::p" />
preceding-siblings Selects all nodes that appear before the specified node and are at the same depth within the file's tree structure.
<xsl:copy-of select="preceding-sibling::p" />

Abbreviated Axis Selection OptionsLink to this section

Some of the axis selections above have abbreviations to make the XSL easier to follow.

attribute
<xsl:copy-of select="p/@" />
descendant-or-self
<xsl:copy-of select="//p" />
parent
<xsl:copy-of select=".." />
self
<xsl:copy-of select="." />
An element of any name
<xsl:copy-of select="*" />
The nth element
<xsl:copy-of select="//p[n]" />

XPath FunctionsLink to this section

XPath functions add flexibility and enhance values returned using XPath. Below is a listing of commonly used XPath functions within OU Campus. More functions can be found on the W3C XPath and XQuery Functions page.

Function Description Output
concat()

Takes two or more arguments, converts each into a string, and combines them into a single string on output.

<xsl:variable name="index-filename" select="concat($index-file, '.' , $extension)"/>
default.html
upper-case()

Converts lowercase characters into a string of uppercase characters.

<xsl:value-of select="upper-case('Gallena University')"/>
GALLENA UNIVERSITY
lower-case()

Converts uppercase characters into a string of lowercase characters.

<xsl:value-of select="lower-case('Gopher News')"/>
gopher news
substring-after()

Returns the portion of a string located after the first instance of a delimiter.

<xsl:value-of select="substring-after('index.html', '.')"/>
html
substring-before()

Returns the portion of a string located before the first instance of a delimiter.

<xsl:value-of select="substring-before('index.html', '.')"/>
index
tokenize()

Splits a string into a sequence of substrings at each instance of a delimiter.

<xsl:value-of select="tokenize('one, two, three', ',')"/>
one two three