Group Attribute-sets
A group can attach a set of attributes to the FME features that enter it. These attribute sets are defined in the group mapping rule by the optional <apply-attribute-sets> element.
The <apply-attribute-sets> element can have one or more <attribute-set> elements that describes an attribute collection through its <attributes> element (see the section “feature mapping rules - attributes element”).
Each <attribute-set> element may also contain an optional <condition> element (see section “group mapping rule - condition element”) that allows or prevents a feature from entering into the attribute set.
The general form of the <apply-attribute-sets> element is:
<apply-attribute-sets> <attribute-set> <!-- optional condition --> <condition .../> <attributes>...</attributes> </attribute-set> ... <attribute-set>...</attribute-set> </apply-attribute-sets>
The following example illustrates the usage of the group mapping rules’s attribute sets. Consider the cleaning.xml input XML document:
cleaning.xml
<?xml version=”1.0”?> <cleaning-schedule date=”09 Mar 2001”> <staff first-name=”John” last-name=”Norton” id=”00098”> <room>302</room> <room>210</room> <room>450</room> </staff> <staff first-name=”Laura” last-name=”Lee” id=”00029”> <room>192</room> <room>597</room> </staff> </cleaning-schedule>
We map each of the above <room> elements into an FME feature. We use group mapping rules to add the information from the <cleaning-schedule> and <staff> elements (refer to the comments in the xfMap document below for further detail):
cleaning.xmp
<?xml version=”1.0”?> <!DOCTYPE xfMap SYSTEM ”xfMap.dtd”> <xfMap> <group-map> <mapping match=”cleaning-schedule”> <!-- This group mapping rule activates when the cleaning-schedule element start-tag is read. The group constructed, called it G0, has one attribute set which attaches to the features that enters it. G0 is pushed into the XML Reader’s g-stack, and it will be the first group in the stack. --> <apply-attribute-sets> <attribute-set> <attributes> <attribute> <name> <literal expr=”cleaning date”/> </name> <value> <extract expr=”@date”/> </value> </attribute> </attributes> </attribute-set> </apply-attribute-sets> </mapping> </group-map> <group-content-map> <mapping match=”staff”> <!-- This mapping rule is activated when the staff element start-tag is read. The group constructed, called it G1, is pushed into the g-stack, it is popped after the staff element’s end-tag is read. G1 contains an attribute set with two attributes which get attached to features that enter the group. --> <!-- The ‘room’ features that are constructed by the feature mapping rule below will pass through G1 and then through G0 before being output. Notice the attribute set contents of G1 changes (there will be two G1s created since there are two staff elements in the input dataset. --> <apply-attribute-sets> <attribute-set> <attributes> <attribute> <name> <literal expr=”staff name”/> </name> <value> <extract expr=”@first-name”/> <literal expr=” ”/> <extract expr=”@last-name”/> </value> </attribute> <attribute> <name> <literal expr=”staff id”/> </name> <value> <extract expr=”@id”/> </value> </attribute> </attributes> </attribute-set> </apply-attribute-sets> </mapping> </group-content-map> <feature-map> <mapping match=”room”> <feature-type> <literal expr=”room”/> </feature-type> <attributes> <attribute> <name> <literal expr=”room number”/> </name> <value> <extract expr=”.”/> </value> </attribute> </attributes> </mapping> </feature-map> </xfMap>
The two documents above make the XML Reader output the following 5 FME room features:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Feature Type: `room' Attribute: `cleaning date' has value `09 Mar 2001' Attribute: `room number' has value `302' Attribute: `staff id' has value `00098' Attribute: `staff name' has value `John Norton' Attribute: `xml_type' has value `xml_no_geom' Geometry Type: Unknown (0) ======================================================================= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Feature Type: `room' Attribute: `cleaning date' has value `09 Mar 2001' Attribute: `room number' has value `210' Attribute: `staff id' has value `00098' Attribute: `staff name' has value `John Norton' Attribute: `xml_type' has value `xml_no_geom' Geometry Type: Unknown (0) ======================================================================= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Feature Type: `room' Attribute: `cleaning date' has value `09 Mar 2001' Attribute: `room number' has value `450' Attribute: `staff id' has value `00098' Attribute: `staff name' has value `John Norton' Attribute: `xml_type' has value `xml_no_geom' Geometry Type: Unknown (0) ======================================================================= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Feature Type: `room' Attribute: `cleaning date' has value `09 Mar 2001' Attribute: `room number' has value `192' Attribute: `staff id' has value `00029' Attribute: `staff name' has value `Laura Lee' Attribute: `xml_type' has value `xml_no_geom' Geometry Type: Unknown (0) ======================================================================= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Feature Type: `room' Attribute: `cleaning date' has value `09 Mar 2001' Attribute: `room number' has value `597' Attribute: `staff id' has value `00029' Attribute: `staff name' has value `Laura Lee' Attribute: `xml_type' has value `xml_no_geom' Geometry Type: Unknown (0) =======================================================================