XMLTemplater
Populates an XML document with FME feature attribute values. The document is provided as a template, and the transformer will use XQuery to insert attribute values and geometry information into the template. The template may be loaded from an attribute, a file, or entered directly into the transformer parameters.
Input Ports
For each feature that enters the Root input port, the Root XML template is evaluated, and the result is put into the Result Attribute parameter.
Output Ports
Features are output from this port after being processed by the transformer.
Parameters
Grouping Sub-Features
The Group Sub-Features By parameter allows for more coarse-grained filtering of sub-features than the parameters in the fme:process-features function. When this parameter is set to a list of attribute names, the fme:process-features function will only process sub-features which have the same values for these attributes as the feature currently being processed. Note that this parameter has no effect on the Root features. Each Root feature will be processed and output from the transformer.
When grouping sub-features, if all features in each group are consecutive, the performance of the transformer can be improved by setting the Grouped Sub-Features are Consecutive parameter to Yes. When this value is set, Root features will be processed as soon as all the applicable sub-features have arrived at the transformer. This means the transformer will operate in a non-blocking manner, rather than waiting for all features to arrive before starting to process templates. The behavior of the transformer is undefined if the features in a group do not all arrive consecutively. It is likely that some sub-features will not be processed if this happens.
In the XMLTemplater, the fme:get-attribute, fme:get-list-attribute and fme:get-xml-attribute functions are particularly useful. Only functions which do not alter the feature are permitted. See the XQuery Functions Documentation for more information on the available functions.
The following XML template populates an XML element with the value of the ‘id’ feature attribute.
<road>
<id>{fme:get-attribute("id")}</id>
</road>
The XQuery functions may be used to populate XML attribute values as well.
<road id="{fme:get-attribute("id")}" />
To populate a sequence of XML elements with the contents of a list attribute, a loop is used to iterate over the list items, as in this sample:
<roads>
{
for $road_id in fme:get-list-attribute("road_ids{}")
return <road id="{$road_id}"/>
}
</roads>
A common use case is to write out an XML element only if a feature attribute has a value. To do this, an if-then-else statement is used. The following example writes out the displayName element only if the feature contains a display_name attribute, and value of the attribute is not an empty string.
<road> { if( fme:has-attribute("display_name") and not(fme:get-attribute("display_name") eq "") ) then <displayName>{fme:get-attribute("display_name")}</displayName> else () } </road>
When a template is evaluated, it can only access the attributes of the feature which is currently being processed. In order to allow a template to access the attributes of multiple features, the concept of sub-templates was introduced. Using the fme:process-features function, the transformer can evaluate a sub-template on a set of features, and then insert the results into the first template. In the transformer interface, each sub templates will be given a name. This name will then be used in the fme:process-features call to identify the sub-template to evaluate. In addition, a transformer input port will be created for each sub-template. The sub-template will be processed on features which enter the corresponding transformer input. Features which enter one of these input ports will be referred to as sub-features.
In the following example, the Root template constructs a <village> element, with information from a single feature. It then populates the <houses> element, using attribute values from features which entered the HOUSE input port.
<village>
<name>{fme:get-attribute("name")}</name>
<population>{fme:get-attribute("population")}</population>
<houses>
{fme:process-features("HOUSE")}
</houses>
</village>
The template associated with the HOUSE input port creates a <house> element.
<house>
<address>{fme:get-attribute("address")}</address>
<owner>{fme:get-attribute("owner")}</owner>
</house>
If a single feature enters the Root input and two features enter the HOUSE input, the resulting XML document could look like this:
<village>
<name>Anytown, USA</name>
<population>2568</population>
<houses>
<house>
<address>123 Main Street</address>
<owner>John Doe</owner>
</house>
<house>
<address>324 Main Street</address>
<owner>Jane Doe</owner>
</house>
</houses>
</village>
A template may call many sub-templates. For example, in the above example, we could add another sub-template named BUSINESS, and then used the process-features function to run this sub-template from the Root template. Additionally, a sub-template may run another sub-template, with the restriction that a sub-template may not directly or indirectly run itself.
Selecting the Sub-Features to Process
Often there is a hierarchical structure to the features that enter the XMLTemplater. For example, each village will have a number of houses, and each house will have several rooms, etc. If the fme:process-features function is used as described above, the resulting document will probably not be correct. Suppose there are two villages, each with five houses. Each village and house is represented by a separate FME feature. The village features are routed into the Root input port while the house features are routed into the HOUSE input port.
If the transformer is run with the above templates, there will be two output features, as expected. However, both of the <village> elements will include all ten <house> elements. The correct behavior is to only evaluate the sub-template on the HOUSE features which correspond to the current village feature.
The fme:process-features function provides a way to do this. Additional function parameters may be used to filter the sub-features which are to be processed. The second parameter is a list of attribute names, and the third is a list of attribute values. Only sub-features whose attributes match the given list of attribute names and values will be processed.
This function call will evaluate the HOUSE sub-template on all HOUSE features whose village_id attribute matches the id attribute of the current feature.
fme:process-features("HOUSE", "village_id", fme:get-attribute("id"))
More than one attribute/value pair can be specified. In this case, the attribute names and attribute values have to be contained in parenthesis. The following function call will evaluate the HOUSE sub-template on all HOUSE features whose village_id attribute matches the id attribute of the current feature, and whose num_floors attribute is 2.
fme:process-features("HOUSE", ("village_id","num_floors"), (fme:get-attribute("id"), 2) )
Running Multiple Sub-Templates with a Single Function Call
It is possible to evaluate multiple sub-templates using a single function call. Simply pass a list of template names to the fme:process-features function. The sub-templates will be evaluated on each of the sub-features named in the list. The features will be processed in the order that they entered the transformer. The following function call processes the HOUSE and BUSINESS sub-templates:
fme:process-features( ("HOUSE","BUSINESS") )
The sub-feature selection parameters may still be used when the fme:process-features function is used to evaluate multiple sub-templates.
Running a Sub-Template on the Same Feature
It is possible to evaluate a sub-template using the same feature which is being used to evaluate the current template. The fme:process-template function takes a name, or list of names, of sub-templates which should be evaluated. These templates will be evaluated and the results will be inserted into the current template. To evaluate a template, just enter the name of the sub-template as a function parameter. For example, while a HOUSE feature is being processed, we could evaluate the OWNER template using the following function call. The OWNER template will be evaluated using the feature that entered the HOUSE input port.
fme:process-template("OWNER")
To evaluate a set of templates, pass a list of names:
fme:process-template( ("OWNER","ADDRESS") )
This technique may be used to modularize XML templates, by moving repeated template structures into a single place. For example, if both houses and businesses have an address, the address could be extracted into an ADDRESS template, and the HOUSE and BUSINESS templates could then use the fme:process-template function to insert the address values. This way, the address template does not have to be duplicated inside the HOUSE and BUSINESS templates.
Geometry templates can be used to write out custom XML geometry. There are a large number of functions which allow the extraction of geometric data, and the processing of sub-templates on geometries. For more information, see the XQuery Functions Documentation for a list of all the geometry functions, and how to write out geometric data using sub-templates.
Geometry sub-templates operate in the same way as regular sub-templates, with the exception that a geometry sub-template does not create an input port on the transformer.
While a geometry template is being evaluated, the functions that access feature attributes (fme:get-attribute, etc.), are still usable.
When specifying an XML template through the Template Expression parameter or the Template File parameter, the transformer will verify that all referenced feature attributes are present in an incoming feature. If attributes are missing (not exposed) from input features, the transformer will be highlighted red as incomplete. When this situation occurs, the transformer’s Summary Annotation will indicate the missing attributes the XML template is referencing.
In addition, when sub-template names are passed to the fme:process-features and fme:process-template functions, the names will be validated to ensure they match the names given in the transformer interface.
To override this additional validation behavior, set the parameter Validate Attribute/Template Names to No.
The attribute to which the updated XML document is written. The default is _result.
Specifies whether the updated XML document should start with an XML header declaration. By default, the output will contain an XML header. Omitting the header can be useful when the output is to be concatenated with other values into a larger XML document.
Automatic Generation of XML Templates
In the XMLTemplater editor windows, the ‘Generate’ button may be used to bring up a dialog which can be used to generate an XML document which may be used as a base for an XML template. This dialog uses the same functionality as the XMLSampleGenerator transformer. For more information on how to use this dialog, refer to the XMLSampleGenerator documentation.
Editing Transformer Parameters
Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace. More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers. To access a menu of these options, click beside the applicable parameter. For more information, see Transformer Parameter Menu Options.
Defining Values
There are several ways to define a value for use in a Transformer. The simplest is to simply type in a value or string, which can include functions of various types such as attribute references, math and string functions, and workspace parameters. There are a number of tools and shortcuts that can assist in constructing values, generally available from the drop-down context menu adjacent to the value field.
Using the Text Editor
The Text Editor provides a convenient way to construct text strings (including regular expressions) from various data sources, such as attributes, parameters, and constants, where the result is used directly inside a parameter.
Using the Arithmetic Editor
The Arithmetic Editor provides a convenient way to construct math expressions from various data sources, such as attributes, parameters, and feature functions, where the result is used directly inside a parameter.
Conditional Values
Set values depending on one or more test conditions that either pass or fail.
Parameter Condition Definition Dialog
Content
Expressions and strings can include a number of functions, characters, parameters, and more.
When setting values - whether entered directly in a parameter or constructed using one of the editors - strings and expressions containing String, Math, Date/Time or FME Feature Functions will have those functions evaluated. Therefore, the names of these functions (in the form @<function_name>) should not be used as literal string values.
These functions manipulate and format strings. | |
Special Characters |
A set of control characters is available in the Text Editor. |
Math functions are available in both editors. | |
Date/Time Functions | Date and time functions are available in the Text Editor. |
These operators are available in the Arithmetic Editor. | |
These return primarily feature-specific values. | |
FME and workspace-specific parameters may be used. | |
Creating and Modifying User Parameters | Create your own editable parameters. |
Dialog Options - Tables
Transformers with table-style parameters have additional tools for populating and manipulating values.
Row Reordering
|
Enabled once you have clicked on a row item. Choices include:
|
Cut, Copy, and Paste
|
Enabled once you have clicked on a row item. Choices include:
Cut, copy, and paste may be used within a transformer, or between transformers. |
Filter
|
Start typing a string, and the matrix will only display rows matching those characters. Searches all columns. This only affects the display of attributes within the transformer - it does not alter which attributes are output. |
Import
|
Import populates the table with a set of new attributes read from a dataset. Specific application varies between transformers. |
Reset/Refresh
|
Generally resets the table to its initial state, and may provide additional options to remove invalid entries. Behavior varies between transformers. |
Note: Not all tools are available in all transformers.
FME Licensing Level
FME Professional edition and above
FME Community
The FME Community is the place for demos, how-tos, articles, FAQs, and more. Get answers to your questions, learn from other users, and suggest, vote, and comment on new features.
Search for samples and information about this transformer on the FME Community.