Almost every template tag acts against one or more elements in the application definition (input XML) file. Some tags (iterade and cond) act on a set of nodes and some tags (attr and content) work against a single node. In both cases you use the same search and filter syntax to specify the node or nodes on which to act. You build a single string that describes the node or nodes and pass that string in to the tag on a single attribute ("nodes" for a multiple-node tag and "node" for a single node tag).
The node attribute value begins with a specification of the single node from which we navigate to the target node(s). If the node attribute value (from here on called the "search string") begins with a forward slash then the search begin with the document node for the input XML. Another way to say that is that the search begins with the parent of the high-level XML element. If, on the other hand, the search string does not begin with a forward slash, the first token in the string is assumed to be the assigned name of the node (see naming nodes) from which the search will begin.
Once the start node has been specified, the search string (broken up by forward slashes) describes a sequence of element names through which the search will navigate. The following examples illustrate various possible search strings:
It is possible to further restrict the collection of nodes resulting from a search. The search string is broken up into a sequence of element names by forward slashes and the search navigates through the sequence of elements with those names to get the final search result. For any or all of the element names in the search string you can specify a set of filter criteria that will restrict the nodes that qualify for the search. After the node name and a blank and before the delimiting forward slash you can list a sequence of name-value pairs seperated by blanks. For each name-value pair, a node will only be included in the search result if its attribute by the given name matches the value specified. There are several possible specifications. Note that values are in single quotes.
For example, assume that the generation tool is acting against the following input XML:
<swim-meet> <event stroke="freestyle" distance="100"> <entry swimmer="37"/> <entry swimmer="21"/> <entry swimmer="43"/> </event> <event stroke="butterfly" distance="50"> <entry swimmer="37"/> <entry swimmer="29"/> </event> <event stroke="freestyle" distance="50"> <entry swimmer="21"> </event> <team name="North All-Stars"> <swimmer id="37" name="Tom" /> <swimmer id="21" name="Geoff" /> </team> <team name="South All-Stars"> <swimmer id="43" name="Chris" /> <swimmer id="29" name="Kay" /> </team> </swim-meet>
The follow examples show how the node and nodes attributes are resolved into a set of XML DOM parse tree nodes:
In addition, the navigation strings can involve dynamic, run-time values. Using the XML example above, we can associate the name "tom" with the <swimmer> node representing tom. We can use the attribute value of that <swimmer> node named "tom" to navigate to the <entry> elements for that swimmer: "/swim-meet/event/entry swimmer='%tom(id)%'".
© Copyright IBM Corporation 2000,
2005. All Rights Reserved.