Difference between revisions of "EPScript"

From EPrints Documentation
Jump to: navigation, search
(Redirected page to EPScript/Introduction)
(Tag: New redirect)
 
(26 intermediate revisions by 7 users not shown)
Line 1: Line 1:
This is an introduction.
+
#REDIRECT [[EPScript/Introduction]]
 
 
= Data Types =
 
 
 
xxx
 
== Primitive Types ==
 
 
 
=== Strings and characters ===
 
 
 
These are contained within either double quotes ("") or single quotes (<nowiki>''</nowiki>). There is no difference between the two, but it may be easier to use one sort when inside an XML attribute. For example:
 
 
 
<when test="type = 'patent'">
 
... 
 
</when>
 
 
 
=== Integers ===
 
 
 
Integers are defined as a string of numbers from 0-9, e.g. 300. Leading zeros do not have any effect, and decimal values are currently not supported.
 
 
 
== Data Objects ==
 
 
 
Data Objects include most of the key EPrints objects - whether an EPrint itself, documents related to the EPrint, or a user. EPScript treats all of these data objects the same, with a simple approach to retrieve properties. When an EPScript is executed, an 'item' object is supplied. In the case of a citation file, this will be the item for which the citation is being created. For a workflow, this will be the object on which the workflow acts (e.g. an EPrint or a user). Properties of main objects can be accessed using a shortened approach - the following example is from a user workflow, so the usertype property is available:
 
 
 
<if test="usertype = 'editor'">
 
...
 
</if>
 
 
 
There are cases, however, where two or more data objects may be provided - such as an EPrint and a user. Here the main item can still be accessed in the short form, but other objects use a dollar notation. In this example, the EPrint is available as $eprint:
 
 
 
<if test="$eprint.ispublished.one_of('unpub', 'submitted', 'inpress')"> (<print expr="$eprint.ispublished" />)</if>
 
 
 
= Operators =
 
 
 
==Logical Operators==
 
 
 
===and===
 
 
 
Returns true if both the left-hand and the right-hand expressions return true.
 
 
 
<if test="type = 'book' and is_set( creators )">
 
...
 
</if>
 
 
 
===or===
 
Returns true if at least one of the expressions returns true.
 
 
 
<if test="type = 'book' or type = 'patent'">
 
...
 
</if>
 
 
 
===not===
 
Returns true if the expression is false and false if the expression is true.
 
 
 
<if test="!is_set( creators )">
 
...
 
</if>
 
 
 
==Comparison Operators==
 
 
 
===lt===
 
 
 
Returns true if the left-hand expression is less than the right-hand expression. This is only applicable to expressions that return numeric values.
 
 
 
<if test="length(editors) lt 6">
 
...
 
</if>
 
 
 
===gt===
 
 
 
Returns true if the left-hand expression is greater than the right-hand expression. This is only applicable to expressions that return numeric values.
 
 
 
<if test="length(editors) gt 1">
 
...
 
</if>
 
 
 
===equals===
 
 
 
Returns true if the left-hand expression is equal to the right-hand expression. This applies to numeric, boolean, and string values.
 
 
 
<if test="type = 'patent'">
 
...
 
</if>
 
 
 
===not equals===
 
 
 
The inverse of the equals operator, this returns true if the expressions are not equal.
 
 
 
<if test="type != 'book'">
 
...
 
</if>
 
 
 
= 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>
 
 
 
== List Functions ==
 
 
 
=== length ===
 
 
 
Returns the number of items in the list.
 
 
 
<if test="length(editors) gt 1">s</if>
 
 
 
== String Functions ==
 
 
 
=== one_of ===
 
 
 
Returns true if the string is in the list of strings provided.
 
 
 
<when test="type.one_of( 'book','book_section' )">
 
...
 
</when>
 
 
 
=== reverse ===
 
 
 
Returns the reverse of a string (i.e. 'abc' becomes 'cba').
 
 
 
<when test="type.reverse = 'tnetap'">
 
...
 
</when>
 
 
 
= Examples =
 
 
 
Pluralising the editors of a book:
 
 
 
<if test="type = 'book' and is_set(editors)">
 
  <print expr="editors" />, (ed<if test="length(editors) gt 1">s</if>
 
</if>
 

Latest revision as of 02:21, 21 February 2022