XML templates are specified for a grammar element by placing one of the following tags within it:




Encloses an XML fragment that is associated with the grammar element. If the grammar element has children with their own XML templates, then an embedded <apply-xml-templates/> element determines the location in the fragment at which the children’s associated XML will be spliced in.


Specifies that the grammar element is associated with the absence of any parsed or emitted XML. This is only meaningful when other alternative constructs in a choice have non-empty XML templates.

<xml-template-attribute name="..."/>

Specifies that the grammar element is associated with an XML attribute.

Here is an example to clarify the use of XML templates. Suppose you have a custom scenario action whose expression grammar takes the following form:

Perform action in ( this way | that way ) on [literal]

This action will be represented as a sequence beginning with the token Perform MyAction in, followed by a choice of tokens this way and that way, followed by the on token, and finally a literal for the user to supply a value. In the case where the token this way is chosen, the expression will correspond to the following PDL fragment (all of which would be automatically enclosed in an <action> element by the scenario editor):

<action-param name="mode">
<action-param name="value">
  <constant type="java.lang.Integer">value</constant>

(In the case where that way is chosen, the PDL would be identical but the value of the mode argument would be that.)

The expression grammar for such a custom action could look like this:

<sequence id="action-MyAction">
  <!-- XML template specifying the action name.  Child elements' XML will
       be processed following the <action-name> element. -->
  <!-- "noise" token that simply acts as a choice handle in the UI;
       it is not associated with any PDL. -->
  <token><description>Perform action</description></token>
  <!-- further "noise" token providing connective to choice.  We
       separate it because "Perform action" is nicer in a dropdown
       list than "Perform action in". -->
  <!-- choice of mode arguments -->
    <!-- XML template specifying the "mode" parameter.  This XML
         template is processed where the <apply-xml-templates/>
         element occurred in the parent sequence's template, so the
         parameter will follow the <action-name> element. -->
      <action-param name="mode">
    <!-- mode tokens.  Because these have values, the tokens are
         associated with XML text nodes at the point where the
         <apply-xml-templates/> element occurred in the parent
         choice's template, i.e. within the <constant> element. -->
    <token value="this"><description>this way</description></token>
    <token value="that"><description>that way</description></token>
    <!-- XML template for the "value" parameter.  Note that the
         value of the literal will be associated with an XML text
         node processed at the point of <apply-xml-templates/>. -->
      <action-param name="value">
    <default><value type="java.lang.Integer">1</value></default>