XProc steps

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

p:count

<p:declare-step type="p:count">
   <p:input port="source" sequence="true"/>
   <p:output port="result"/>
      <p:option name="limit" select="0"/> <!-- integer -->
</p:declare-step>

The <p:count> step counts the number of the documents passing the “source“ input port and outputs the appropriate value as a result (at the “result“ output port). The user can give an integer value to the “limit“ option. The user sets a maximum value which regulates up to which number shall be counted. If the user enters the value 0, the counting never stops.

Example

In the following example the documents of the known “FilmCollection.xml“ input file are counted.

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
   <p:input port="source">
      <p:document href="FilmCollection.xml"/>
   </p:input>
   <p:output port="result"/>
   <p:count limit="0"/>
</p:declare-step>

Since a file is read in at the input port and no further intermediate steps occur in the pipe, which could have an influence on the result of <p:count>, the result of this pipeline is the numerical value “1“.

In the next example a <p:filter> step is put in front of the <p:count> step. It shall devide the document into the “Film“ elements.

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
   <p:input port="source">
      <p:document href="FilmCollection.xml"/>
   </p:input>
   <p:output port="result"/>
   <p:filter select="/FilmCollection/Film"/>
   <p:count limit="0"/>
</p:declare-step>

Since there are three “Film“ elements in the “FilmCollection.xml“ input document and <p:filter> filters the input data by these elements due to the XPath instruction, the result of this pipline is the numerical value “3“.