EPScript/Functions
EPScript | ||
Contents
Functions
Calling Functions
Functions can be called in two ways:
<when test="is_set( creators )">
or
<when test="creators.is_set">
These are interchangable, but it may be beneficial to use a specific form in some cases.
Generic Functions
is_set
Returns true if the parameter is set, based on the following criteria:
- If the parameter is a string, it is set if it is not empty.
- If the parameter is a list or a complex structure, it is set if at least one value is set.
<when test="is_set( creators )"> ... </when>
yesno
Returns a yes or no string depending on whether the expression is true.
<print expr="yesno(is_set('abstract'))" />
List Functions
length
Returns the number of items in the list.
<if test="length(editors) gt 1">s</if>
one_of
Returns a boolean depenbding on whether a variable is one of a number of values.
<when test="type.one_of('article','conference_item','book')"> ... </when>
String Functions
reverse
Returns the reverse of a string (i.e. 'abc' becomes 'cba').
<when test="type.reverse = 'tnetap'"> ... </when>
join
Returns the concatentation of strings with a particular joining character.
<when test="$list.join(':') = 'a:b:c'"> ... </when>
substr
Returns the substring of a string
<when test="title.substr(0,3) = 'the'"> ... </when>
contains
Returns a boolean depending whether the string contains a particular substring.
<when test="title.contains('the')"> ... </when>
as_string
Converts variable into a string. Can be useful in phrases or for defining class or id attributes for HTML elements
<phrase ref="licenses_description_{license.as_string()}" />.
strlen
Gets the integer length of a string.
<when test="strlen(title) > 50"> ... </when>
Mathematical Functions
add
Returns the addition of one number to another.
<when test="pages + 4 > 10"> ... </when>
subtract
Returns the substraction of one number from another.
<when test="pages - 4 lt 10"> ... </when>
multiply
Returns the multiplication of one number by another.
<when test="pages * 4 gt 10"> ... </when>
divide
Returns the division of one number by another.
<when test="pages / 4 lt 10"> ... </when>
mod
Returns the modulus (i.e. remainder) of a number from a base (e.g 5 % 3 equals 2.
<when test="pages % 2 = 0"> ... </when>
uminus
Returns the negative value of an integer (e.g. 1 becomes -1). This is a unary rather than binary operator like substract.
<when test="-rating gt 5"> ... </when>
Rendering Functions
citation
Renders the XHTML citation for a data object with a specified style. Encapsulated within a link to
<print expr="$item.citation('default')" />
citation_link
Renders the XHTML citation for a data object with a specified style, where the title is encompassed by a link to the data object.
<print expr="$item.citation_link('default')" />
embed_video
Renders an XHTML object to render an HTML5 video preview for a document that is a video or audio file.
<print expr="$doc.embed_video" />
Data Object Functions
property
Get the property of a data object
<print expr="$item.property('note')">
main_item_property
Get the property of parent data object.
<print expr="$doc.main_item_property('note')" />
as_item
Treats a variable as an item so other data object functions can be applied to it.
<when test="$doc.property('eprintid').as_item().property('type') = 'thesis'">
dataset
Returns the string for the dataset of the data object.
<when test="$item.dataset() = 'document'">
Returns an array of objects related to the current data object through a particular property.
<foreach expr="$doc.related_objects('http://eprints.org/relation/hasVersion')" iterator="rel">
url
Returns the URL for a particular data object.
<a href="{$doc.url()}">Download</a>
Date Functions
today
Returns today's date
<print expr="today()" />
datemath
Returns a date relative to the date provided, (e.g. two years ago).
<when test="date lt today().datemath( -2,'year' )">