p:text-count (3.1) 

Counts the number of lines in a text document.

Summary

<p:declare-step type="p:text-count">
  <input port="source" primary="true" content-types="text" sequence="false"/>
  <output port="result" primary="true" content-types="application/xml" sequence="false"/>
</p:declare-step>

The p:text-count step counts the number of lines in the text document appearing on its source port and returns an XML document on its result port containing that number.

Ports:

Port

Type

Primary?

Content types

Seq?

Description

source

input

true

text

false

The text document to count the lines of.

result

output

true

application/xml

false

An XML document consisting of a single <c:result> element containing the number of lines (the c prefix here is bound to the http://www.w3.org/ns/xproc-step namespace).

Example: <c:result xmlns:c="http://www.w3.org/ns/xproc-step">6</c:result>

Description

The p:text-count step simply counts the number of lines in the text document appearing on its source port. This number is returned on the result port, wrapped in an <c:result> element.

Examples

Basic usage

Assume we have a text document, called lines.txt, that looks like this and we want to count the number of lines using p:text-count:

line 1
line 2
line 3

Pipeline document:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="3.0">

  <p:input port="source" href="lines.txt"/>
  <p:output port="result"/>

  <p:text-count/>

</p:declare-step>

Result document:

<c:result xmlns:c="http://www.w3.org/ns/xproc-step">3</c:result>

Additional details

  • No document-properties from the document on the source port survives. The resulting document has a content-type document-property set to application/xml and no base-uri document-property.

  • What exactly constitutes a line-end is defined in the XML specification.

  • If the very last character of the source document is a line-end, this is ignored. So it does not count as a separator between that line and a following line (that contains no characters).

Reference information

This description of the p:text-count step is for XProc version: 3.1. This is a required step (an XProc 3.1 processor must support this).

The formal specification for the p:text-count step can be found here.

The p:text-count step is part of categories:

The p:text-count step is also present in version: 3.0.