XProc Unit Test: choose001

Inputs

Port=source:

<document>
<title>Some Title</title>
<para>Some paragraph.</para>
</document>

Pipeline

pipeline:

<p:pipeline name="pipeline" xmlns:p="http://www.w3.org/2007/03/xproc">
<p:input port="source"/>
<p:output port="result"/>

<p:choose>
  <p:when test="count(//*) mod 2 = 0">
    <p:output port="result"/>
    <p:identity>
      <p:input port="source">
        <p:inline> 
          <p>There are an even number of elements in the document.</p>
        </p:inline>
      </p:input>
    </p:identity>
  </p:when>
  <p:otherwise>
    <p:output port="result"/>
    <p:identity>
      <p:input port="source">
        <p:inline> 
          <p>There are an odd number of elements in the document.</p>
        </p:inline>
      </p:input>
    </p:identity>
  </p:otherwise>
</p:choose>

</p:pipeline>

Outputs

Port=result:

<p>There are an odd number of elements in the document.</p>