Copyright 2013 Syd Bauman, David Birnbaum, Julia Flanders, and Martin Holmes
This TEI-encoded XML file is available under the terms of the Creative Commons Attribution-ShareAlike 3.0 (Unported) license.
Covers a few basic XPath 2.0 functions.
not()
, as we've already covered it
count()
not()
, concat()
, and last()
count()
not()
position()
and last()
normalize-space()
string-length()
replace()
translate()
concat()
avg()
max()
min()
sum()
distinct-values()
current-date()
things you want the function to work on.
Open the hamlet.xml example file, which you can find here:
http://web.uvic.ca/~mholmes/dhoxss2013/examples/hamlet.xml
Open the xpath_functions.xsl example file, which you can find here:
http://web.uvic.ca/~mholmes/dhoxss2013/examples/xpath_functions.xsl
Switch to the XSLT debugger, so you can experiment with functions. Set the output to XHTML.
not()
not( boolean )
match="persName[ not( surname )]"
normalize-space()
and string-length()
string-length( //l[@xml:id eq 'sha-ham301055']/text() )
→ 70string-length( normalize-space( //l[@xml:id eq 'sha-ham301055']/text() ) )
→ 42normalize-space()
to clean up messy text, especially due to pretty-printing.replace()
replace(input-string, regex-pattern, replacement-string,
flags)
replace('Syd','y','i')
replace(//role,'a','Hi,
Mom!')?
//role/upper-case(.)
means
“find all the translate()
translate(input-string, characters-to-match,
replacement-characters)
replace()
for more complex replacements)translate('Syd','ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')
upper-case()
and
lower-case()
concat()
concat( 'str1', 'str2', 'str3' )
→ str1str2str3concat(/TEI/descendant::title[1], ' by ', /TEI/descendant::author[1])
avg()
, max()
, min()
,
sum()
avg( sequence-of-numbers )
avg( (1,2,3,4,5,6) )
avg( 1,2,3,4,5,6 )
?max()
, min()
, and
sum()
string-length(string)
returns the
length of the string.
) refers to the current item//sp/string-length(.)
will return a sequence
consisting of the length of each string (try it)distinct-values()
distinct-values(//speaker)
//speaker
return?//role
distinct-values(//role)
return?position()
and last()
item/position()
//role/position()
returns the number of each
role in the list of roleslast()
function returns the
sequence number of the last node in the set//sp[@who='#Hamlet']//l[position() = last()]/stage
current-date()
current-date()
current-dateTime()
,
current-time()
format-date()
(-dateTime
,
-time
) to massage output format-date()
works only in XSLT, not in the
XPath browser of <oXygen/>current-date()
format-date(current-date(), '[Y]-[M01]-[D01]')
format-date(current-date(), '[FNn], [MNn] [D1o], [Y] [E]')