Attributes Element
A feature mapping rule can contain optional attributes that specifies one or more attributes for the FME feature that is under construction.
The attributes is composed by one or more attribute, and each attribute has a name and a value that have expression sequences as their values. They are represented in xfMap by the <attributes>, <attribute>, <name>, and <value> elements:
<attributes> <attribute> <name> <!-- an expression sequence --> </name> <value> <!-- an expression sequence --> </value> </attribute> ... <attribute> ... </attribute> ... </attributes>
Note: In a feature mapping rule, the definition of the <attributes> element must appear after the definition of the <feature-type> element.
The following xfMap document, attributes.xmp, contains the mapping rule Rp, which matches a <point> element from the points1.xml document. Rp contains an <attributes> element which directs the XML Reader to set some attributes for the FME feature that is under construction.
attributes.xmp
<?xml version="1.0"?> <!DOCTYPE xfMap SYSTEM "xfMap.dtd"> <xfMap> <feature-map> <mapping match="point"> <feature-type> <extract expr="@name"/> <literal expr="_"/> <extract expr="@num"/> </feature-type> <attributes> <!-- a1 --> <attribute> <name> <literal expr="red"/> </name> <value> <extract expr="./color/red"/> </value> </attribute> <!-- a2 --> <attribute> <name> <literal expr="green"/> </name> <value> <extract expr="./color/green"/> </value> </attribute> <!-- a3 --> <attribute> <name> <literal expr="blue"/> </name> <value> <extract expr="./color/blue"/> </value> </attribute> <!-- a4 --> <attribute> <name> <literal expr="color"/> </name> <value> <!-- the expression sequence below construct the value of this attribute to be: "r=x,g=y,b=z" where x,y,z are reals --> <literal expr="r="/> <extract expr="./color/red"/> <literal expr=",g="/> <extract expr="./color/green"/> <literal expr=",b="/> <extract expr="./color/blue"/> </value> </attribute> <!-- a5 --> <attribute> <name> <literal expr="location"/> </name> <value> <!-- the expression sequence below construct the value of this attribute to be: "x:a y:b", where a,b are reals --> <literal expr="x:"/> <extract expr="./location[@x]"/> <literal expr=" y:"/> <extract expr="./location[@y]"/> </value> </attribute> </attributes> </mapping> </feature-map> </xfMap>
When the points1.xml and the above attributes.xmp documents are fed into the XML Reader the following FME features are constructed:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Feature Type: ~myPoint_0'
Attribute: ~blue' has value 0.596'
Attribute: ~color' has value r=0.324,g=0.233,b=0.596'
Attribute: ~green' has value 0.233'
Attribute: ~location' has value x:10.0 y:0.0'
Attribute: ~red' has value 0.324'
Attribute: ~xml_type' has value xml_no_geom'
Geometry Type: Unknown (0) ==============================================================
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Feature Type: ~myPoint_1'
Attribute: ~blue' has value 0.554'
Attribute: ~color' has value r=0.874,g=0.948,b=0.554'
Attribute: ~green' has value 0.948'
Attribute: ~location' has value x:5.0 y:5.0'
Attribute: ~red' has value 0.874'
Attribute: ~xml_type' has value xml_no_geom'
Geometry Type: Unknown (0)
==============================================================