Previous Up Next


p:count — Counts the number of documents that appear in a sequence.


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


The p:count step counts the number of documents on the source port. It returns a single c:result element containing the number.

If the limit option is specified and is greater than zero, the p:count step will count at most that many documents. This provides a convenient mechanism to discover, for example, if a sequence consists of more than 1 document, without requiring every single document to be buffered before processing can continue.


This pipeline counts the number of paragraphs in the document.

  1 <p:pipeline xmlns:p=""
  5     <p:input port="source" select="//para"/>
Input Output
1 <doc>
<para>First para.</para>
<para>Second para.</para>
<para>Third para.</para>
5 </doc>
1 <c:result xmlns:c="">3</c:result>