Previous Up Next


p:pack

p:pack — Merges two document sequences.

Synopsis

<p:declare-step type="p:pack">
     <p:input port="source" sequence="true" primary="true"/>
     <p:input port="alternate" sequence="true"/>
     <p:output port="result" sequence="true"/>
     <p:option name="wrapper" required="true"/>                    <!-- QName -->
     <p:option name="wrapper-prefix"/>                             <!-- NCName -->
     <p:option name="wrapper-namespace"/>                          <!-- anyURI -->
</p:declare-step>

Description

The p:pack step merges two document sequences, “packing” their members together. One document is read from each sequence and each pair is placed in the specified wrapper. The result is a sequence of documents containing such pairs.

If the step reaches the end of one input sequence before the other, then it simply wraps each of the remaining documents in the longer sequence.

Note

In the common case, where the document element of a document in the result sequence has two element children, any comments, processing instructions, or white space text nodes that occur between them may have come from either of the input documents; this step does not attempt to distinguish which one.

Errors

Error Description
err:D0034 Occurs if you specify a new namespace or prefix when the lexical value of the specified name contains a colon.

Examples

Steps in XProc read either a single document (and specifying multiple documents is an error) or they read all the documents sent to them. The p:pack step makes it possible to group documents from two input streams, allowing you to effectively read one document at a time.

This example uses p:pack to transform a 4xn table into an nx4 table.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:viewport match="table" name="rotate">
  5     <p:identity name="col1">
          <p:input port="source" select="/table/tr[1]/td">
            <p:pipe step="rotate" port="current"/>
          </p:input>
        </p:identity>
 10     <p:identity name="col2">
          <p:input port="source" select="/table/tr[2]/td">
            <p:pipe step="rotate" port="current"/>
          </p:input>
        </p:identity>
 15     <p:identity name="col3">
          <p:input port="source" select="/table/tr[3]/td">
            <p:pipe step="rotate" port="current"/>
          </p:input>
        </p:identity>
 20     <p:identity name="col4">
          <p:input port="source" select="/table/tr[4]/td">
            <p:pipe step="rotate" port="current"/>
          </p:input>
        </p:identity>
 25     <p:pack name="c12" wrapper="wrap12">
          <p:input port="source">
            <p:pipe step="col1" port="result"/>
          </p:input>
          <p:input port="alternate">
 30         <p:pipe step="col2" port="result"/>
          </p:input>
        </p:pack>
        <p:pack name="c34" wrapper="wrap34">
          <p:input port="source">
 35         <p:pipe step="col3" port="result"/>
          </p:input>
          <p:input port="alternate">
            <p:pipe step="col4" port="result"/>
          </p:input>
 40     </p:pack>
        <p:pack name="c1234" wrapper="wrapper">
          <p:input port="source">
            <p:pipe step="c12" port="result"/>
          </p:input>
 45       <p:input port="alternate">
            <p:pipe step="c34" port="result"/>
          </p:input>
        </p:pack>
        <p:for-each>
 50       <p:for-each>
            <p:iteration-source select="//td"/>
            <p:identity/>
          </p:for-each>
          <p:wrap-sequence wrapper="tr"/>
 55     </p:for-each>
        <p:wrap-sequence wrapper="table"/>
      </p:viewport>
    </p:pipeline>
Input Output
1 <doc>
<para>This is a table.</para>
<table>
<tr>
5 <td>A1</td>
<td>B1</td>
<td>C1</td>
</tr>
<tr>
10 <td>A2</td>
<td>B2</td>
<td>C2</td>
</tr>
<tr>
15 <td>A3</td>
<td>B3</td>
<td>C3</td>
</tr>
<tr>
20 <td>A4</td>
<td>B4</td>
<td>C4</td>
</tr>
</table>
25 </doc>
 
1 <doc>
<para>This is a table.</para>
<table>
<tr>
5 <td>A1</td>
<td>A2</td>
<td>A3</td>
<td>A4</td>
</tr>
10 <tr>
<td>B1</td>
<td>B2</td>
<td>B3</td>
<td>B4</td>
15 </tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>C3</td>
20 <td>C4</td>
</tr>
</table>
</doc>