arraysize: 0
CETEIcean extension: XPath selection
Example 1
For the purpose of demonstration, we have taken part of a document from the CELT website (an invaluable resource!) containing the Annals of Ulster. This partial document is saved on a wiki page. To retrieve a section, for instance one of the entries under the year 1123, we need to select it first; and to select this passage, we need to know what XPath (short for XML Path) expression to use.
The code of this section looks like:
<div2 n="U1123.1"> <p> <on type="people/lineage">Gailenga</on> do ghab<ex>ail</ex> tighi i n-<placeName>Daim Liac <personName><foreName type="saint">Ciannan</foreName></personName></placeName> for <personName><foreName>Murch<ex>adh</ex></foreName> <sn>H. Mael Sechl<ex>ainn</ex></sn></personName> for <term type="king">righ</term> <placeName type="kingdom">Temhrach</placeName> co ro loiscset in tech &ersir; <num value="80"><ex>ocht</ex>mogha</num> taighi ime &ersir; co ro marbsat soch<ex>aid</ex>i dia muinnter. Ternai <ex>imorro</ex> <personName><foreName>Murch<ex>adh</ex></foreName></personName> do ainiuch <personName><foreName type="saint">Ciannan</foreName></personName> cen marb<ex>adh</ex> cen loscadh.</p> </div2>
- In this example, we're going to identify our XML node by specifying the tagname (
div2
), attribute name (n
) and the relevant attribute value (U1123.2
). For security reasons, each tagname (div2
in the example) must be preceded by a namespace prefix (ctc:
).
{{#cetei:doc=Cetei:AU-test |sel=//ctc:div2[@n='U1123.2'] }}
- Result
Minor comment. Because there is no other use of this pair of attribute name and value to be found in the document, we could have left the tagname unspecified, using a wildcard (*) instead:
{{#cetei:doc=Cetei:AU-test |sel=//ctc:*[@n='U1123.2'] }}
Example 2: combining expressions
To join two or more expressions, XPath offers the pipe symbol, i.e. a vertical bar. Because MediaWiki reserves the same symbol for other uses and thus has special meaning, we need to escape it as {{!}}
.
{{#cetei:doc=Cetei:Documents/64162-8515 |sel=//ctc:p[@xml:id='I.i.17'] {{!}} //ctc:p[@xml:id='I.i.18'] }}
- Result
These excerpts are from J. Bately's edition of the Old English Orosius.
Example 3
From the same document of the Annals of Ulster, let's fetch all uses of the tag term
where type="church". P.S. Results appear in the order in which they are found. XPath does not allow you to sort results alphabetically or otherwise, which would be a job for XSLT and might be worth looking into if it solves anyone's problem.
{{#cetei:doc=Cetei:AU-test |sel=//ctc:term[@type='church'] }}
- Result