keyword Expressions
The keyword expression allows access to values that are declared in the FME mapping file. It is represented in the xfMap document with the <keyword> element, and it has the following general form:
<keyword expr=”...” default=”...” keyword-group=”…” op=”compare|contains”> <arg name=”expr”>...</arg> <arg name=”default”>...</arg> </keyword>
Note: The keyword expression supports positional arguments for backwards compatibility, but named arguments are recommended.
The keyword expression takes the following form when using positional arguments:
<keyword expr=”...” default=”...” keyword-group=”…” op=”compare|contains”> <arg> <!-- keyword --> </arg> <arg> <!-- optional default value --> </arg> </keyword>
When using positional arguments, the order of the two arguments cannot be changed and in order to specify default as an arg, expr must also be specified.
The expression string (i.e., the expr
attribute) denotes the name of the keyword, which would have been specified in the FME mapping file through the XFMAP_KEYWORD
keyword, or via a file through the XFMAP_KEYWORD_FILE
keyword. The optional default
attribute specifies the default value in the case the specified keyword was not defined.
The expr
attribute may be an empty string, in which case, the first argument, the first <arg>
element, must be present. The evaluated expression sequence for this first argument becomes the keyword to search.
If the default
attribute is absent or if it is the empty string, then the second argument if it is present will be evaluated to become the default value in the case the keyword was not defined.
The keyword-group attribute is only applicable if keywords were specified via a file through the XFMAP_KEYWORD_FILE
. Each keyword in a file may be optionally partitioned into groups. The value for this attribute indicates the group name.
The op
attribute indicates the way in which a keyword is retrieved. The attribute defaults to compare, which retrieves a keyword value if a keyword with the exact name is found. If the op
attribute is set to contains
then a value is retrieved when the specified name is contained in any of the stored keywords.
Example
Assuming the FME mapping file has the following XML XFMAP_KEYWORD
's defined:
XML_XFMAP_KEYWORD key0 value0
XML_XFMAP_KEYWORD key1 “my other value”
keywords.xml
<?xml version="1.0" encoding="UTF-8"?> <items> <item> <primary-id>key0</primary-id> <alternate-id>he5390</alternate-id> </item> <item> <primary-id>key1</primary-id> <alternate-id>a2046</alternate-id> </item> <item> <primary-id>key566</primary-id> <alternate-id>ad249</alternate-id> </item> </items>
keywords.xmp
<?xml version="1.0" encoding="UTF-8"?> <xfMap> <feature-map> <mapping match="item"> <feature-type> <keyword> <arg name="expr"> <extract expr="./primary-id"/> </arg> <arg name="default"> <extract expr="./alternate-id"/> </arg> </keyword> </feature-type> </mapping> </feature-map> </xfMap>
FME features constructed:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Feature Type: `value0' Attribute(string): `xml_type' has value `xml_no_geom' Geometry Type: Unknown (0) =================================================================== xml-feat +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Feature Type: `my other value' Attribute(string): `xml_type' has value `xml_no_geom' Geometry Type: Unknown (0) =================================================================== xml-feat +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Feature Type: `ad249' Attribute(string): `xml_type' has value `xml_no_geom' Geometry Type: Unknown (0) ===================================================================