Sorts lines in a text document.
<p:declare-step type="p:text-sort"> <input port="source" primary="true" content-types="text" sequence="false"/> <output port="result" primary="true" content-types="text" sequence="false"/> <option name="case-order" as="xs:string?" required="false" select="()" values="('upper-first', 'lower-first')"/> <option name="collation" as="xs:string" required="false" select="'https://www.w3.org/2005/xpath-functions/collation/codepoint'"/> <option name="lang" as="xs:language?" required="false" select="()"/> <option name="order" as="xs:string" required="false" select="'ascending'" values="('ascending', 'descending')"/> <option name="sort-key" as="xs:string" required="false" select="'.'"/> <option name="stable" as="xs:boolean" required="false" select="true()"/> </p:declare-step>
The p:text-sort
step sorts lines in the text document appearing on its source
port.
Ports:
Port | Type | Primary? | Content types | Seq? | Description |
---|---|---|---|---|---|
|
|
|
|
| The text document to sort the lines of. |
|
|
|
|
| The resulting document. |
Options:
The p:text-sort
step takes the text document appearing on its source
port and turns this into lines. These lines are then sorted
according to the values of the step options. This sort process is the same as described for the XSLT xsl:sort
instruction. The result appears on the result
port.
Assume we have a text document, called lines.txt
, that looks like this and we want to sort the lines using p:text-sort
:
XProc steps rock! An important addition to our XML processing toolkit. What a joy!
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-sort/> </p:declare-step>
Result document:
An important addition to our XML processing toolkit. What a joy! XProc steps rock!
This example is not very useful in itself, but it shows the use of the position()
and last()
function in the
sort-key
option. We set this option to last() - position()
, which has the effect of
reversing the line order.
Source document (lines-2.txt
):
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-2.txt"/> <p:output port="result"/> <p:text-sort sort-key="last() - position()"/> </p:declare-step>
Result document:
line 3 line 2 line 1
p:text-sort
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-sort
are terminated with a line-end character (line-feed, 

).
This description of the p:text-sort
step is for XProc version: 3.0. This is a required step (an XProc 3.0 processor must support this).
The formal specification for the p:text-sort
step can be found here.
The p:text-sort
step is part of categories:
The p:text-sort
step is also present in version:
3.1.