In the following example the use of variables in XProc will be introduced.


  name = QName
  select = XPathExpression>
   ((p:empty |
   p:pipe |
   p:document |
   p:inline |
   p:data)? &

Variables can only be generated in Compound Steps. They include values which are defined via an appropriate XPath expression. The name of a variable has to be a QName. They can be further used within this step. They can also be loaded with <p:empty>, <p:pipe>, <p:document>, <p:inline> or <p:data> (afterwards, the "select" attribute extracts the desired contents and stores them in the variable).


In the following example the use of <p:variable> is demonstrated.

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="" xmlns:c="" version="1.0">
  <p:input port="source">
        <text>This is just a small example text.</text>
  <p:output port="result">
    <p:variable name="Inline" select="block/fileName"/>
      <p:with-option name="href" select="$Inline"/>

In the example a XML document is generated by <p:inline>. This document has a value in the “fileName“ element which shall be assigned to the variable. In order to be able to generate a variable, it has to be within a Compound Step. Therefore, <p:group>, a Compound Step, is used as enclosing element. The variable gets the name “Inline“ and “text.xml“ as value, this corresponds to the return value of the indicated XPath expression. The <p:identity> step re-outputs the entire content of <p:inline> which then becomes the content of <p:store> and is stored by it. As file name the value stored in the variable is used. The content of the variable is resolved by the preceding Dollar character ($) and so it can be used as file name.

The result of this pipeline is as follows:

<block xmlns:c="">
   <text>This is just a small example text.</text>

The result is the content of the “text.xml“ file generated by the pipeline.

<< back next >>