Mapping

Mapping is a flow control function that allows case switching and string replacement. Mapping works by matching keys against a domain and processing accordingly.

Where should it be used?

Common uses for mapping include string replacement with the ability to match using a regular expression. Mapping can also act as a [!docSwitch]/case statement.

Mapping Attributes

Operation: Mapping has 2 modes of operation:
  • [Substitute]*
  • [!docSwitch]
These operations can be used to define the behaviour of the mapping.

Repeat (false */true): This attribute defines whether the mapping repaetedly matches against the same keys until no more matches remain.

Mapping Structue

Mapping must have a single domain (the data subject to search) and at least one condition to match the domain against.

Visual Guide to Mapping

MappingSee also:

Basic Examples

The below example shows a basic literal replace. The values brown and lazy will be replaced by red and boyant respectively.
<mapping>
	<domain>The lazy brown dog</domain>
	<match value="red"><key value="brown" /></match>
	<match value="boyant"><key value="lazy" /></match> 
</mapping>
The boyant red dog


The following example shows a basic switch operation that matches the domain exactly to the key with value 4 and outputs the word accordingly.
<mapping operation="switch">
	<domain>4</domain>
	<match value="zero"><key value="0" /></match>
	<match value="four"><key value="4" /></match> 
	<match value="eight"><key value="8" /></match>
</mapping>
four


Another example here shows how a default match is used to catch a domain that does not match one of the keys.
<mapping operation="switch">
	<domain>5</domain>
	<match value="zero"><key value="0" /></match>
	<match value="four"><key value="4" /></match> 
	<match value="eight"><key value="8" /></match>
	<match value="unknown"></match>
</mapping>
unknown

Advanced Example

The following example shows a substitution mapping using the repeat attribute. The repeat attribute loops repeatedly over the matches matches making replacements until no further matches occur.
<mapping operation="substitute" repeat="true">
	<domain>The quick brown fox jumps over the lazy rabbit</domain>
	<match value="dog"><key value="fox" /></match>
	<match value="rabid"><key value="slow" break="true" /></match> 
	<match value="slow"><key value="q.*k" format="regex" /></match>
</mapping>
The rabid brown dog jumps over the lazy rabbit
As this mapping repeats the keys are evaluated a number of times until there are no more matches. The first iteration happens in this sequence:

  1. fox is changed to dog
  2. slow is not matched
  3. quick is replaced by slow


At this point the domain is now "The slow brown dog jumps over the lazy rabbit"

As there was a match the mapping is repeated on the new domain value:
  1. fox is not matched
  2. slow is replaced by rabid
  3. q.*k is not matched


The domain now stands at "The rabid brown dog jumps over the lazy rabbit"
The mapping repeats again, but no matches are found so the mapping exits execution. The domain is put into the output of the mapping by default.


Last Modified: Thu, 15 Jan 2015