This site is work in progress and does not yet describe all available steps.

 p:text-tail (3.1) 

Returns lines from the end of a text document.

Summary

<p:declare-step type="p:text-tail">
  <input port="source" primary="true" content-types="text" sequence="false"/>
  <output port="result" primary="true" content-types="text" sequence="false"/>
  <option name="count" as="xs:integer" required="true"/>
</p:declare-step>

The p:text-tail step returns lines from the end of a text document.

Ports:

Type

Port

Primary?

Content types

Seq?

Description

input

source

true

text

false

The text document to get the lines from.

output

result

true

text

false

The resulting lines.

Options:

Name

Type

Req?

Description

count

xs:integer

true

Indicates what p:text-tail should do:

  • If positive, p:text-tail returns the last count lines.

  • If zero, p:text-tail returns all lines.

  • If negative, p:text-tail returns all lines except the last count lines.

Description

The p:text-tail step takes lines from the end of the text document appearing on its source port and returns these lines as a text document on its result port. What exactly happens depends on the value of the count option.

As you might have guessed there is also a step that returns lines from the beginning of a document: p:text-head.

Examples

Basic usage

Assume we have a text document, called lines.txt, that looks like this and we want to get the last 2 lines using p:text-tail:

line 1
line 2
line 3
line 4
line 5

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-tail count="2"/>

</p:declare-step>

Result document:

line 4
line 5

Setting the count option to 0 will simply return the original document (the step now acts like a p:identity step).

Setting the count option to -2 will return all lines except the last two:

<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-tail count="-2"/>

</p:declare-step>

Result document:

line 1
line 2
line 3

Additional details

  • p:text-tail preserves all document-properties of the document(s) appearing on its source port.

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

  • All lines returned by p:text-tail are terminated with a line-end character (line-feed, &#xA;).

Reference information

This description of the p:text-tail 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-tail step can be found here.

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

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