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" 
                 attribute-name="genre">
  <p:with-option name="attribute-value" select="$genre-value"/>
</p:add-attribute>

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" 
                 attribute-value="{$genre-value}"/>

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="http://www.w3.org/ns/xproc" 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">
      <p:inline>
        <artist name="{$artist}"/>
      </p:inline>
    </p:with-input>
  </p:insert>
  
</p:declare-step>

Output

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

Read more…