XProc steps

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

p:split-sequence

<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>

On the basis of an appropriate XPath expression, the <p:split-sequence> step divides a document into two categories. The documents are loaded at the “source“ input port. There are two output ports (“matched“ and “not-matched“). A XPath expression is passed on to the “test“ option. This expression is used for all documents. If the expression is valid, which means it applies for the document being currently read, a complete copy of the document is written on the “matched“ output port. Similarly, a complete copy of the document is written on the “not-matched“ output port, if the XPath expression does not apply. If the “initial-only“ option is set to “true“, from the time when a document does not met the XPath condition the current and all following (regardless of whether they met the XPath condition or not) documents will be written on the “not-matched“ ouput port.

Example

In the following example two documents are read in and sent through a <p:split-sequence> step. The first document fulfils the XPath expression and the second not.

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
   <p:input port="source" sequence="true">
      <p:document href="FilmCollection.xml"/>
      <p:document href="FilmCollection_3.xml"/>
   </p:input>
   <p:split-sequence test="/FilmCollection" name="Split"/>
   <p:identity>
      <p:input port="source">
         <p:pipe port="matched" step="Split"/>
      </p:input>
   </p:identity>
   <p:store href="matched.xml"/>
   <p:identity>
      <p:input port="source">
         <p:pipe port="not-matched" step="Split"/>
      </p:input>
   </p:identity>
   <p:store href="not-matched.xml"/>
</p:declare-step>

At first, the initial documents at the input port (“source“) are read in via <p:document>. The XPath expression “/FilmCollection“ is passed on to the <p:split-sequence> step as an option. It checks whether the root element of the document is “FilmCollection“. If so, the document is written on the primary “matched“ output port, otherwise on “not-matched“. These outputs are caught by <p:identity> and then written by <p:store>.

<FilmCollection>
[...]
</FilmCollection>
<FilmCollectionDifferent>
[...]    
</FilmCollectionDifferent>

In the example the name of the root element of the documents “FilmCollection.xml“ and “FilmCollection_different.xml“ differs. The first applies for the XPath expression and is accordingly outputted on “matched“; “FilmCollection_different.xml“ is written on “not-matched“.