The logo is a pig framed between two angle brackets.

Attribute and Text Value Templates (AVTs and TVTs)

Attribute and Text Value Templates are XPath expressions in curly braces. AVTs and TVTs can be considered to save you code and make your code more readable, or more briefly, as syntactic sugar. Let’s take the example from the previous lesson:

<p:add-attribute match="artist" 
  <p:with-option name="attribute-value" select="$genre-value"/>

With AVTs, we can omit p:with-option because the curly braces indicate that the option value should be evaluated as XPath expression. Both examples lead to the same result, but the example with AVT is much easier to read.

<p:add-attribute match="artist" attribute-name="genre" 

In the following example, we take the output from above as input and define an option that holds the artist name to be inserted. A Text Value Template is used to evaluate our option value as XPath variable in the document in the insertion port.

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="" version="3.0">
  <p:input port="source"/>
  <p:output port="result"/>
  <p:option name="artist" select="'Ramones'"/>

  <p:insert match="/music" position="last-child">
    <p:with-input port="insertion">
        <artist name="{$artist}"/>


<?xml version="1.0" encoding="UTF-8"?>
  <artist name="The Clash">
    <album title="The Clash"/>
    <album title="Give 'Em Enough Rope"/>
    <album title="London Calling"/>
  <artist name="Dead Kennedys">
    <album title="Fresh Fruit for Rotting Vegetables"/>
  <artist name="Ramones"/>

Read more…