Previous Up Next


p:filter

p:filter — Filters documents with a dynamically constructed select expression.

Synopsis

<p:declare-step type="p:filter">
     <p:input port="source"/>
     <p:output port="result" sequence="true"/>
     <p:option name="select" required="true"/>                     <!-- XPathExpression -->
</p:declare-step>

Description

The p:filter step selects portions of the source document based on a dynamically constructed XPath select expression.

This step behaves just like an p:identity step with a p:input that has a select expression except that the select expression is computed dynamically.

Examples

In this example, we select the element with a particular xml:id where the ID value is an option to the pipeline.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:option name="id" select="'two'"/>
  5 
      <p:filter>
        <p:with-option name="select"
                       select="concat('//*[@xml:id=&#34;',$id,'&#34;]')"/>
      </p:filter>
 10 </p:pipeline>
Input Output
1 <doc>
<p xml:id="one">One</p>
<p xml:id="two">Two</p>
<p xml:id="three">Three</p>
5 </doc>
 
<doc>
<p xml:id="one">One</p>
1 <p xml:id="two">Two</p>
<p xml:id="three">Three</p>
</doc>

In real life it's unlikely that there would be value in having a default for the 'id' option, but it's convenient for the example.)