Previous Up Next


p:split-sequence

p:split-sequence — Divides a sequence of documents into two sequences.

Synopsis

<p:declare-step type="p:split-sequence">
     <p:input port="source" sequence="true"/>
     <p:output port="matched" sequence="true" primary="true"/>
     <p:output port="not-matched" sequence="true"/>
     <p:option name="initial-only" select="'false'"/>              <!-- boolean -->
     <p:option name="test" required="true"/>                       <!-- XPathExpression -->
</p:declare-step>

Description

The p:split-sequence step accepts a sequence of documents and divides it into two sequences. For each input document, the test expression is evaluated using that document as the context node. If the effective boolean value of the expression is “true”, then the document is passed to the matched port, otherwise it is passed to the not-matched port.

If the initial-only option is true, then when the first document that does not satisfy the test expression is encountered, it and all the documents that follow it are written to the not-matched port. In other words, it only writes the initial series of matched documents (which may be empty) to the matched port. All other documents are written to the not-matched port, irrespective of whether or not they match.

When evaluating the test, the context position (position()) is the position of that document within the sequence and the context size (last()) is the total number of documents in the sequence.

Examples

This pipeline accepts a sequence of documents and counts the number of DocBook documents in the sequence.

  1 <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                    xmlns:db="http://docbook.org/ns/docbook"
                    version="1.0">
      <p:input port="source" sequence="true"/>
  5   <p:output port="result"/>
    
      <p:split-sequence test="/db:*"/>
    
      <p:count/>
 10 </p:declare-step>
Input Output
1 <doc xmlns:db="http://docbook.org/ns/docbook">
<para>Hello world.</para>
</doc>
 
1 <c:result xmlns:c="http://www.w3.org/ns/xproc-step">0</c:result>

(FIXME: the example doesn't really get a sequence)

This pipeline accepts a sequence of documents and counts the number of non-DocBook documents in the sequence.

  1 <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                    xmlns:db="http://docbook.org/ns/docbook"
                    version="1.0">
      <p:input port="source" sequence="true"/>
  5   <p:output port="result"/>
    
      <p:split-sequence name="split" test="/db:*"/>
    
      <p:sink/>
 10 
      <p:count>
        <p:input port="source">
          <p:pipe step="split" port="not-matched"/>
        </p:input>
 15   </p:count>
    </p:declare-step>
Input Output
1 <doc xmlns:db="http://docbook.org/ns/docbook">
<para>Hello world.</para>
</doc>
 
1 <c:result xmlns:c="http://www.w3.org/ns/xproc-step">1</c:result>

(FIXME: the example doesn't really get a sequence)