Previous Up Next


p:identity

p:identity — Passes its input through unchanged.

Synopsis

<p:declare-step type="p:identity">
     <p:input port="source" sequence="true"/>
     <p:output port="result" sequence="true"/>
</p:declare-step>

Description

The p:identity step makes a verbatim copy of its input available on its output. By itself, this may not seem very useful, but it is, at least in two common situations.

The first is when you want to extract some portion of a document flowing through a pipeline. Using a select attribute on the input to p:identity extracts those parts and copies them through unchanged.

The second is in p:choose steps, where you may want one or more of the branches of the choice to “do nothing”.

Examples

In the simplest case, p:identity just passes its input to the result port.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:identity/>
  5 </p:pipeline>
Input Output
1 <doc>
<para>Hello world.</para>
</doc>
 
1 <doc>
<para>Hello world.</para>
</doc>

A common use of p:identity is to extract some portion or portions of a document.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:identity>
  5     <p:input port="source" select="/doc/div"/>
      </p:identity>
    </p:pipeline>
Input Output
1 <doc>
<para>Hello world!</para>
<div>
<para>Work.</para>
5 <para>Sleep.</para>
<para>Eat.</para>
<para>Play.</para>
</div>
<para>Goodbye, cruel world.</para>
10 </doc>
 
<doc>
<para>Hello world!</para>
1 <div>
<para>Work.</para>
<para>Sleep.</para>
<para>Eat.</para>
5 <para>Play.</para>
</div>
<para>Goodbye, cruel world.</para>
</doc>

Another common use is in one of the branches of a p:choose.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:db="http://docbook.org/ns/docbook"
                version="1.0">
    
  5   <p:choose>
        <p:when test="/db:*">
          <p:xslt>
            <p:input port="stylesheet">
              <p:document href="docbook.xsl"/>
 10         </p:input>
          </p:xslt>
        </p:when>
        <p:otherwise>
          <p:identity/>
 15     </p:otherwise>
      </p:choose>
    </p:pipeline>
Input Output
1 <doc xmlns:db="http://docbook.org/ns/docbook">
<para>Hello world!</para>
</doc>
 
1 <doc xmlns:db="http://docbook.org/ns/docbook">
<para>Hello world!</para>
</doc>