Skip to content

Metamorph functions

TobiasNx edited this page Sep 29, 2022 · 23 revisions

Functions take as input name-value pairs, subsequently written as (name, value) and output zero to n name-value pairs.

For more information, see also:

blacklist

Filtering based on a blacklist. See also Data Lookup.

in:      ("a","rabbit")("b","turtle")("c","hamster")  ...
<blacklist>
<entry  name="hamster"/>
<entry  name="rabbit"/>
</blacklist>
out:   ("b","turtle")  ...

compose

Wraps the value in a prefix and postfix.

in:      ("a","b")("c","d")  ...
<compose  prefix="Hello,  "  postfix="!"/>
out:   ("a","Hello  b!")("c","Hello  d!")  ...

constant

Replaces the value with a constant string.

in:      ("a","b")("c","d")  ...
<constant  value="V"/>
out:   ("a","V")("c","V")  ...

contains

Filtering based on containing.

in:      ("a","hamster in the house")("b","turtle in the house")  ...
<contains  string="hamster"/>
out:   ("a","hamster in the house")  ...

count

Counts occurrences.

in:      ("a","b")("c","d")  ...
<count/>
out:   ("a","1")("c","2")  ...

dateformat

Formats dates

in: ("a","2018-08-26")
<dateformat inputformat="yyyy-MM-dd" outputformat="FULL" era="AD" removeLeadingZeros="false" language="de"/>
out:("a","Sonntag\, 26. August 2018")

equals

Filtering based on equality.

in:      ("a","hamster")("b","turtle")  ...
<equals  string="hamster"/>
out:   ("a","hamster")  ...

htmlanchor

create an HTML anchor tag.

isbn

ISBN cleaning, checkdigit verification and transformation between ISBN 10 and ISBN 13.

lookup

Lookup and replace based on a data table. See also Data Lookup.

in:      ("a","en")("b","es")("c","xy")  ...
<lookup>
<entry  name="en"  value="english"/>
<entry  name="es"  value="spanish"/>
</lookup>
out:   ("a","english")("c","spanish")  ...

normalize-utf8

UTF-8 normalization. Brings Umlauts into canonical form.

not-contains

Filtering based on not containing.

in:      ("a","hamster in the house")("b","turtle in the house")  ...
<not-contains  string="hamster"/>
out:   ("b","turtle in the house")  ...

not-equals

Filtering based on inequality.

in:      ("a","hamster")("b","turtle")  ...
<not-equals  string="hamster"/>
out:   ("b","turtle")  ...

occurrence

filtering based on occurrence.

in:      ("a","hamster")("b","turtle")("c","butterfly")  ...
< occurrence  only="2"/>
out:   ("b","turtle")  ...
in:      ("a","hamster")("b","turtle")("c","butterfly")  ...
< occurrence  only="moreThan  2"/>
out:   ("c","butterfly")  ...

regexp

Regexp matching. Returns first occurrence of a pattern. The pattern is a Java regex Pattern (see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html).

in:      ("a","baum")("b","pflaume")("d","apfel")  ...
<regexp  match="a.m"/>
out:   ("a","baum")("b","pflaume")  ...

The optional format argument is used to address match groups.

in:      ("a","from  1789  to  1900")  ...
<regexp  match="(\d\d\d\d)  to  (\d\d\d\d)"  format="${1}-${2}"/>
out:   ("b","1789-1900")  ...

replace

Replaces a pattern with a string. The pattern is a Java regex Pattern (see http://docs. oracle.com/javase/6/docs/api/java/util/regex/Pattern.html).

in:      ("a","abcde")("c","efg")  ...
<replace  pattern="[ace]"  with="X"/>
out:   ("a","XbXdX")("c","Xfg")  ...

script and java

processing the value with a JavaScript function or a Java class. See Integration of Java and JavaScript.

setreplace

Replaces multiple strings. The mapping from string to replacement is defined in a map, just as done in the lookup function. See also Data Lookup.

in:      ("a","written  in  $en")("c","$es-speaking")  ...
<setreplace>
<entry  name="$en"  value="english"/>
<entry  name="$es"  value="spanish"/>
</setreplace>
out:   ("a","written  in  english")("c","spanish-speaking")  ...

split

splitting based on a regexp.

in:      ("data","Oahu,Hawaii,Maui")  ...
<split delimiter=","/>
out:   ("data","Oahu")("data","Hawaii")("data","Maui")  ...

substring

Extraction of a substring.

in:      ("a","012345")  ...
<substring  start="3"  end="5"/>
out:   ("a","34")  ...

switch-name-value

Exchanges name and value.

in:      ("hamster","Rodriguez")("cat","Felix")  ...
<switch-name-value/>
out:   ("Rodriguez","hamster")("Felix","cat")  ...

If you wish to set the name of the resulting named values, use the following code:

in:      ("hamster","Rodriguez")("cat","Felix")  ...
<constant value="animal"/>
<switch-name-value/>
out:   ("animal","hamster")("animal","cat")  ...

trim

Trim the value.

in:      ("a","  hamster  ")("b","turtle  ")  ...
<trim  string="hamster"/>
out:   ("a","hamster")("b","turtle")  ...

whitelist

Filtering based on a whitelist. See also Data Lookup

in:      ("a","rabbit")("b","turtle")("c","hamster")  ...
<whitelist>
<entry  name="hamster"/>
<entry  name="rabbit"/>
</whitelist>
out:   ("a","rabbit")("c","hamster")  ...
Clone this wiki locally