<?xml version="1.0" encoding="UTF-8"?>
<!--
<?publication-root http://www.w3.org/XML/XProc/docs/?>
<?latest-version http://www.w3.org/XML/XProc/docs/langspec.html?>
-->
<?oxygen RNGSchema="../schema/dbspec.rnc" type="compact"?>
<specification xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:cs="http://www.w3.org/XML/XProc/2006/04/components#"
  xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" class="pr"
  version="5.0-extension w3c-xproc">
  <info><title>XProc: An XML Pipeline Language</title>
    <w3c-shortname>xproc</w3c-shortname>
    <pubdate>2010-03-09</pubdate>
    <bibliorelation type="isformatof" xlink:href="langspec.xml">XML</bibliorelation>
    <bibliorelation type="isformatof" xlink:href="diff.html">Revision markup</bibliorelation>
    <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2010/WD-xproc-20100105/"/>
    <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2009/CR-xproc-20090528/"/>
    <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2008/CR-xproc-20081126/"/>
    <!--
    <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2008/WD-xproc-20080814/"/>
      <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2007/WD-xproc-20071129/"/>
      <bibliorelation type="replaces"
		xlink:href="http://www.w3.org/TR/2007/WD-xproc-20070920/"/>
<bibliorelation type="replaces"
		xlink:href="http://www.w3.org/TR/2007/WD-xproc-20070706/"/>
<bibliorelation type="replaces"
		xlink:href="http://www.w3.org/TR/2007/WD-xproc-20070405/"/>
<bibliorelation type="replaces"
		xlink:href="http://www.w3.org/TR/2006/WD-xproc-20061117/"/>
-->
    <authorgroup>
      <author>
        <personname>Norman Walsh</personname>
        <affiliation>
          <orgname>Mark Logic Corporation</orgname>
        </affiliation>
        <email>norman.walsh@marklogic.com</email>
      </author>
      <author>
        <personname>Alex Milowski</personname>
        <affiliation>
          <orgname>Invited expert</orgname>
        </affiliation>
        <email>alex@milowski.org</email>
      </author>
      <author>
        <personname>Henry S. Thompson</personname>
        <affiliation>
          <orgname>University of Edinburgh</orgname>
        </affiliation>
        <email>ht@inf.ed.ac.uk</email>
      </author>
    </authorgroup>

<abstract>
<para>This specification describes the syntax and semantics of
<citetitle>XProc: An XML Pipeline Language</citetitle>, a language for
describing operations to be performed on XML documents.</para>

<para>An XML Pipeline specifies a sequence of operations to be
performed on zero or more XML documents. Pipelines generally accept
zero or more XML documents as input and produce zero or more XML
documents as output. Pipelines are made up of simple steps which
perform atomic operations on XML documents and constructs similar to
conditionals, iteration, and exception handlers which control which
steps are executed.</para>
</abstract>

<legalnotice role="status">

<para><emphasis>This section describes the status of this document at
the time of its publication. Other documents may supersede this
document. A list of current W3C publications and the latest revision
of this technical report can be found in the <link
xlink:href="http://www.w3.org/TR/">W3C technical reports index</link>
at http://www.w3.org/TR/.</emphasis></para>

<para>This is a
<link xlink:href="http://www.w3.org/2005/10/Process-20051014/tr.html#cfr">Proposed
Recommendation</link>
for review by W3C members and other interested parties. This document
is a product of the
<link xlink:href="http://www.w3.org/XML/Processing/" >XML Processing Model
Working Group</link> which is part of the W3C <link
xlink:href="http://www.w3.org/XML/Activity">XML Activity</link>.
The English version of this specification is the only
normative version. However, for translations of this document, see
<link xlink:href="http://www.w3.org/2003/03/Translations/byTechnology?technology=xproc"/>.
</para>

<para>Though the previous version of this document was a Last Call Working
Draft, there was an earlier Candidate Recommendation version of this
document that has already resulting in successful implementation
feedback. Given that the changes to this draft do not affect the
validity of that earlier implementation feedback, except in specific areas
also now covered by more recent implementation feedback, the Working Group is
now publishing this version as a Proposed Recommendation.</para>

<para>There is an
<link xlink:href="http://www.w3.org/XML/XProc/2010/02/ir.html">Implementation
Report for XProc</link>.
</para>

<para>W3C Advisory Committee Representatives are invited to submit their
formal review per the instructions in the Call for Review (see
<link xlink:href="http://www.w3.org/2002/09/wbs/myQuestionnaires">Advisory
Committee questionnaires</link>). The review period ends on 15 April 2010.
Members of the public are also invited to send comments on this Proposed
Recommendation to the public mailing list
<link xlink:href="mailto:public-xml-processing-model-comments@w3.org"
>public-xml-processing-model-comments@w3.org</link> (public
<link xlink:href="http://lists.w3.org/Archives/Public/public-xml-processing-model-comments/"
>archives</link> are available).</para>

<para>This specification implements all of the requirements
documented in <biblioref linkend="use-cases"/>.</para>

<para>Publication as a Proposed Recommendation does not imply endorsement by
the W3C Membership. This is a draft document and may be updated,
replaced or obsoleted by other documents at any time. It is
inappropriate to cite this document as other than work in progress.</para>

<para>This document was produced by a group operating under the <link
xlink:href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5
February 2004 W3C Patent Policy</link>. W3C maintains a <link
xlink:href="http://www.w3.org/2004/01/pp-impl/38398/status">public
list of any patent disclosures</link> made in connection with the
deliverables of the group; that page also includes instructions for
disclosing a patent. An individual who has actual knowledge of a
patent which the individual believes contains <link
xlink:href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</link> must disclose the information in accordance with <link
xlink:href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</link>.</para>

</legalnotice>
</info>

<section xml:id="introduction">
    <title>Introduction</title>
    <para>An XML Pipeline specifies a sequence of operations to be performed on a collection of XML
      input documents. Pipelines take zero or more XML documents as their input and produce zero or
      more XML documents as their output.</para>
    <para>A <glossterm>pipeline</glossterm> consists of steps. Like pipelines, steps take zero or
      more XML documents as their inputs and produce zero or more XML documents as their outputs.
      The inputs of a step come from the web, from the pipeline document, from the inputs to the
      pipeline itself, or from the outputs of other steps in the pipeline. The outputs from a step
      are consumed by other steps, are outputs of the pipeline as a whole, or are discarded.</para>
    <para>There are three kinds of steps: atomic steps, compound steps, and multi-container steps.
      Atomic steps carry out single operations and have no substructure as far as the pipeline is
      concerned. Compound steps and multi-container steps control the execution of other steps,
      which they include in the form of one or more subpipelines.</para>
    <para>This specification defines a standard library, <xref linkend="std-components"/>, of steps.
      Pipeline implementations <rfc2119>may</rfc2119> support additional types of steps as well. </para>
    <para><xref linkend="fig-xival"/> is a graphical representation of a simple pipeline that
      performs XInclude processing and validation on a document.</para>
    <figure xml:id="fig-xival">
      <title>A simple, linear XInclude/Validate pipeline</title>
      <mediaobject>
        <alt>A simple, linear XInclude/Validate pipeline</alt>
        <imageobject>
          <imagedata fileref="graphics/sch-xinclude-validate-pipeline.png"/>
        </imageobject>
      </mediaobject>
    </figure>
    <para>This is a pipeline that consists of two atomic steps, XInclude and Validate with XML
      Schema. The pipeline itself has two inputs, “source” (a source document) and “schemas” (a
      sequence of W3C XML Schemas). The XInclude step reads the pipeline input “source” and produces
      a result document. The Validate with XML Schema step reads the pipeline input “schemas” and
      the result of the XInclude step and produces its own result document. The result of the
      validation, “result”, is the result of the pipeline. (For consistency across the step
      vocabulary, the standard input is usually named “source” and and the standard output is
      usually named “result”.) </para>
    <para>The pipeline document determines how the steps are connected together inside the pipeline,
      that is, how the output of one step becomes the input of another.</para>
    <para>The pipeline document for this pipeline is shown in <xref linkend="ex1"/>.</para>
    <example xml:id="ex1">
      <title>A simple, linear XInclude/Validate pipeline</title>
      <programlisting><xi:include href="examples/fig1.xml" parse="text"/></programlisting>
    </example>
    <para>The example in <xref linkend="ex1"/> is very verbose. It makes all of the connections seen
      in the figure explicit. In practice, pipelines do not have to be this verbose. XProc supports
      defaults for many common cases:</para>
    <itemizedlist>
      <listitem>
        <para>If you use <tag>p:pipeline</tag> instead of <tag>p:declare-step</tag>, the
            “<port>source</port>” input port and “<port>result</port>” output port are implicitly
          declared for you.</para>
      </listitem>
      <listitem>
        <para>Where inputs and outputs are connected between sequential sibling steps, they do not
          have to be made explicit.</para>
      </listitem>
    </itemizedlist>
    <para>The same pipeline, using XProc defaults, is shown in <xref linkend="ex1-abbr"/>.</para>
    <example xml:id="ex1-abbr">
      <title>A simple, linear XInclude/Validate pipeline (simplified)</title>
      <programlisting><xi:include href="examples/fig1-abbr.xml" parse="text"/></programlisting>
    </example>
    <para><xref linkend="fig-style-proc"/> is a more complex example: it performs schema validation
      with an appropriate schema and then styles the validated document.</para>
    <figure xml:id="fig-style-proc">
      <title>A validate and transform pipeline</title>
      <mediaobject>
        <alt>A validate and transform pipeline</alt>
        <imageobject>
          <imagedata fileref="graphics/sch-transform.png"/>
        </imageobject>
      </mediaobject>
    </figure>
    <para>The heart of this example is the conditional. The “choose” step evaluates an XPath
      expression over a test document. Based on the result of that expression, one or another branch
      is run. In this example, each branch consists of a single validate step.</para>
    <example xml:id="ex2">
      <title>A validate and transform pipeline</title>
      <programlisting><xi:include href="examples/fig2.xml" parse="text"/></programlisting>
    </example>
    <para>This example, like the preceding, relies on XProc defaults for simplicity. It is always
      valid to write the fully explicit form if you prefer.</para>
    <para>The media type for pipeline documents is <literal>application/xml</literal>. Often,
      pipeline documents are identified by the extension <filename class="extension"
      >.xpl</filename>.</para>
    <para>In this specification the words <rfc2119>must</rfc2119>, <rfc2119>must not</rfc2119>,
        <rfc2119>should</rfc2119>, <rfc2119>should not</rfc2119>, <rfc2119>may</rfc2119> and
        <rfc2119>recommended</rfc2119> are to be interpreted as described in <biblioref
        linkend="rfc2119"/>.</para>
  </section>

  <section xml:id="pipeline-concepts">
    <title>Pipeline Concepts</title>
    <para><termdef xml:id="dt-pipeline">A <firstterm>pipeline</firstterm> is a set of connected
        steps, with outputs of one step flowing into inputs of another.</termdef> A pipeline is
      itself a <glossterm>step</glossterm> and must satisfy the constraints on steps. Connections
      between steps occur where the input of one step is connected to the output of another. </para>
    <para>The result of evaluating a pipeline (or <glossterm>subpipeline</glossterm>) is the result
      of evaluating the steps that it contains, in an order consistent with the connections between
      them. A pipeline must behave as if it evaluated each step each time it is encountered. Unless
      otherwise indicated, implementations <rfc2119>must not</rfc2119> assume that steps are
      functional (that is, that their outputs depend only on their <link linkend="input-output"
        >inputs</link>, <glossterm baseform="option">options</glossterm>, and <glossterm
        baseform="parameter">parameters</glossterm>) or side-effect free.</para>
    <para>The pattern of connections between steps will not always completely determine their order
      of evaluation. <impl>The evaluation order of steps not connected to one another is
          <glossterm>implementation-dependent</glossterm></impl>. </para>
    <section xml:id="step-concept">
      <title>Steps</title>
      <para><termdef xml:id="dt-step">A <firstterm>step</firstterm> is the basic computational unit
          of a pipeline.</termdef> A typical step has zero or more inputs, from which it receives
        XML documents to process, zero or more outputs, to which it sends XML document results, and
        can have options and/or parameters.</para>
      <para>There are three kinds of steps: <glossterm baseform="atomic step">atomic</glossterm>,
          <glossterm baseform="compound step">compound</glossterm>, and <glossterm
          baseform="multi-container step">multi-container</glossterm>.</para>
      <para><termdef xml:id="dt-atomic-step">An <firstterm>atomic step</firstterm> is a step that
          performs a unit of XML processing, such as XInclude or transformation, and has no internal
            <glossterm>subpipeline</glossterm>. </termdef> Atomic steps carry out fundamental XML
        operations and can perform arbitrary amounts of computation, but they are indivisible. An
        XSLT step, for example, performs XSLT processing; a Validate with XML Schema step validates
        one input with respect to some set of XML Schemas, etc.</para>
      <para>There are many <emphasis>types</emphasis> of atomic steps. The standard library of
        atomic steps is described in <xref linkend="std-components"/>, but implementations
          <rfc2119>may</rfc2119> provide others as well. <impl>It is
            <glossterm>implementation-defined</glossterm> what additional step types, if any, are
          provided. </impl> Each use, or instance, of an atomic step invokes the processing defined
        by that type of step. A pipeline may contain instances of many types of steps and many
        instances of the same type of step.</para>
      <para>Compound steps, on the other hand, control and organize the flow of documents through a
        pipeline, reconstructing familiar programming language functionality such as conditionals,
        iterators and exception handling. They contain other steps, whose evaluation they
        control.</para>
      <para><termdef xml:id="dt-compound-step">A <firstterm>compound step</firstterm> is a step that
          contains a <glossterm>subpipeline</glossterm>.</termdef> That is, a compound step differs
        from an atomic step in that its semantics are at least partially determined by the steps
        that it contains.</para>
      <para>Finally, there are two “multi-container steps”: <tag>p:choose</tag> and
        <tag>p:try</tag>. <termdef xml:id="dt-multi-container-step">A <firstterm>multi-container
            step</firstterm> is a step that contains several alternate <glossterm
            baseform="subpipeline">subpipelines</glossterm>. </termdef> Each subpipeline is
        identified by a non-step wrapper element: <tag>p:when</tag> and <tag>p:otherwise</tag> in
        the case of <tag>p:choose</tag>, <tag>p:group</tag> and <tag>p:catch</tag> in the case of
          <tag>p:try</tag>. </para>
      <para>The output of a multi-container step is the output of exactly one of its subpipelines.
        In this sense, a multi-container step functions like a <glossterm>compound step</glossterm>.
        However, evaluating a multi-container step may involve evaluating, or partially evaluating,
        more than one of its subpipelines. It's possible for steps in a partially evaluated pipeline
        to have side effects that are visible outside the processor, even if the final output of the
        multi-container step is the result of some other subpipeline. For example, a web server
        might record that some interaction was performed, or a file on the local file system might
        have been modified.</para>
      <para><termdef xml:id="dt-container">A compound step or multi-container step is a
            <firstterm>container</firstterm> for the steps directly within it or within non-step
          wrappers directly within it.</termdef>
        <termdef xml:id="dt-contained-steps">The steps that occur directly within, or within
          non-step wrappers directly within, a step are called that step's <firstterm>contained
            steps</firstterm>. In other words, “container” and “contained steps” are inverse
          relationships.</termdef>
        <termdef xml:id="dt-ancestors">The <firstterm>ancestors</firstterm> of a step, if it has
          any, are its <glossterm>container</glossterm> and the ancestors of its
          container.</termdef>
      </para>
      <para><termdef xml:id="dt-subpipeline">Sibling steps (and the connections between them) form a
            <firstterm>subpipeline</firstterm>.</termdef>
        <termdef xml:id="dt-last-step">The <firstterm>last step</firstterm> in a subpipeline is its
          last step in document order.</termdef></para>
      <para xml:id="p.subpipeline"
        role="element-syntax element-syntax-language-construct hanging-indent">
        <code>subpipeline</code>&#xa0;=&#xa0;<tag>p:variable</tag>*,&#160;(<tag>p:for-each</tag>|<tag>p:viewport</tag>|<tag>p:choose</tag>|<tag>p:group</tag>|<tag>p:try</tag>|<code
          xlink:href="#p.atomic">p:<replaceable>standard-step</replaceable></code>|<code
          xlink:href="#p.atomic"><replaceable>pfx:user-pipeline</replaceable></code>)+ </para>
      <note>
        <para>User-defined pipelines (identified with
              <code><replaceable>pfx:user-pipeline</replaceable></code> in the preceding syntax
          summary) are atomic. A pipeline <emphasis>declaration</emphasis> may contain a
          subpipeline, but the invocation of that pipeline is atomic and does not contain a
          subpipeline.</para>
      </note>
      <para>Steps have “ports” into which inputs and outputs are connected. Each step has a number
        of input ports and a number of output ports; a step can have zero input ports and/or zero
        output ports. (All steps have an implicit output port for reporting errors that
          <rfc2119>must not</rfc2119> be declared.) The names of all ports on each step must be
        unique on that step (you can't have two input ports named “source”, nor can you have an
        input port named “schema” and an output port named “schema”). </para>
      <para>A Step may have zero or more <link linkend="options">options</link>, all with unique
        names.</para>
      <para>Steps may have parameter input ports, on which <link linkend="parameters"
          >parameters</link> can be passed. A step can have zero, one, or many parameter input
        ports, and each parameter input port can have zero or more parameters passed on it. If more
        than one parameter with the same name is passed to any given parameter input port, only the
        last value specified will be available to the step; the names of the parameters passed to
        the step are unique on each port. Parameters with the same name can be passed to different
        ports, the uniqueness constraint on names only applies to the parameters passed on each
        individual port.</para>
      <para>All of the different instances of steps (atomic or compound) in a pipeline can be
        distinguished from one another by name. If the pipeline author does not provide a name for a
        step, a default name is <link linkend="step-names">manufactured automatically</link>.</para>
      <section xml:id="step-names">
        <title>Step names</title>
        <para>The <tag class="attribute">name</tag> attribute on any step can be used to give it a
          name. The name must be unique within its scope, see <xref linkend="scoping"/>.</para>
        <para>If the pipeline author does not provide an explicit name, the processor manufactures a
          default name. All default names are of the form
            “<literal>!1</literal><replaceable>.m</replaceable><replaceable>.n</replaceable>…” where
            “<replaceable>m</replaceable>” is the position (in the sense of counting sibling
          elements) of the step's highest ancestor element within the pipeline document or library
          which contains it, “<replaceable>n</replaceable>” is the position of the next-highest
          ancestor, and so on, including both steps and non-step wrappers. For example, consider the
          pipeline in <xref linkend="ex2"/>. The <tag>p:pipeline</tag> step has no name, so it gets
          the default name “<literal>!1</literal>”; the <tag>p:choose</tag> gets the name
            “<literal>!1.1</literal>”; the first <tag>p:when</tag> gets the name
            “<literal>!1.1.1</literal>”; the <tag>p:otherwise</tag> gets the name
            “<literal>!1.1.2</literal>”, etc. If the <tag>p:choose</tag> had had a name, it would
          not have received a default name, but it would still have been counted and its first
            <tag>p:when</tag> would still have been “<literal>!1.1.1</literal>”.</para>
        <para>Providing every step in the pipeline with an interoperable name has several
          benefits:</para>
        <orderedlist>
          <listitem>
            <para>It allows implementors to refer to all steps in an interoperable fashion, for
              example, in error messages.</para>
          </listitem>
          <listitem>
            <para>Pragmatically, we say that <glossterm>readable ports</glossterm> are identified by
              a step name/port name pair. By manufacturing names for otherwise anonymous steps, we
              include implicit connections without changing our model.</para>
          </listitem>
        </orderedlist>
        <para>In a valid pipeline that runs successfully to completion, the manufactured names
          aren't visible (except perhaps in debugging or logging output).</para>
        <note xml:id="def-name-ncname">
          <para>The format for defaulted names does not conform to the requirements of an <link
              xlink:href="http://www.w3.org/TR/xml-names/#NT-NCName">NCName</link>. This is an
            explicit design decision; it prevents pipelines from using the defaulted names on
              <tag>p:pipe</tag> elements. If an explicit connection is required, the pipeline author
            must provide an explicit name for the step.</para>
        </note>
      </section>
    </section>
    <section xml:id="input-output">
      <title>Inputs and Outputs</title>
      <para>Although some steps can read and write non-XML resources, what flows
          <emphasis>between</emphasis> steps through input ports and output ports are exclusively
        XML documents or sequences of XML documents.</para>
      <para>For the purposes of this specification, an XML document is an <biblioref
          linkend="xml-infoset-rec"/>. Implementations are free to transmit Infosets as sequences of
        characters, sequences of events, object models, or any other representation that preserves
        the necessary Infoset properties (see <xref linkend="infoset-conformance"/>).</para>
      <para>Most steps in this specification manipulate XML documents, or portions of XML documents.
        In these cases, we speak of changing elements, attributes, or nodes without prejudice to the
        actual representation used by an implementation.</para>
      <para>An implementation <rfc2119>may</rfc2119> make it possible for a step to produce non-XML
        output (through channels other than a named output port)—for example, writing a PDF document
        to a URI—but that output cannot flow through the pipeline. Similarly, one can imagine a step
        that takes no pipeline inputs, reads a non-XML file from a URI, and produces an XML output.
        But the non-XML data cannot arrive on an input port to a step.</para>
      <para><error code="D0001">It is a <glossterm>dynamic error</glossterm> if a non-XML resource
          is produced on a step output or arrives on a step input.</error></para>
      <para>The common case is that each step has one or more inputs and one or more outputs. <xref
          linkend="fig-atomic-step"/> illustrates symbolically an <glossterm>atomic step</glossterm>
        with two inputs and one output.</para>
      <figure xml:id="fig-atomic-step">
        <title>An atomic step</title>
        <mediaobject>
          <alt>An atomic step with two inputs and one output</alt>
          <imageobject>
            <imagedata fileref="graphics/atomic-step.png"/>
          </imageobject>
        </mediaobject>
      </figure>
      <para>All atomic steps are defined by a <tag>p:declare-step</tag>. The declaration of an
        atomic step type defines the input ports, output ports, and options of all steps of that
        type. For example, every <tag>p:validate-with-xml-schema</tag> step has two inputs, named
          “<literal>source</literal>” and “<literal>schema</literal>”, one output named
          “<literal>result</literal>”, and the same set of options. </para>
      <para>Like atomic steps, top level, user-defined pipelines also have declarations. The
        situation is slightly more complicated for the other compound steps because they don't have
        separate declarations; each instance of the compound step serves as its own declaration. On
        these compound steps, the number and names of the outputs can be different on each instance
        of the step.</para>
      <para><xref linkend="fig-compound-step"/> illustrates symbolically a compound step with one
        subpipeline and one output. As you can see from the diagram, the output from the compound
        step comes from one of the outputs of the subpipeline within the step.</para>
      <figure xml:id="fig-compound-step">
        <title>A compound step</title>
        <mediaobject>
          <alt>A compound step with two inputs and one output</alt>
          <imageobject>
            <imagedata fileref="graphics/compound-step.png"/>
          </imageobject>
        </mediaobject>
      </figure>
      <para><termdef xml:id="dt-declared-inputs">The input ports declared on a step are its
            <firstterm>declared inputs</firstterm>.</termdef>
        <termdef xml:id="dt-declared-outputs">The output ports declared on a step are its
            <firstterm>declared outputs</firstterm>.</termdef> When a step is used in a pipeline, it
        is connected to other steps through its inputs and outputs. </para>
      <para>When a step is used, all of the <glossterm>declared inputs</glossterm> of the step
          <rfc2119>must</rfc2119> be connected. Each input can be connected to:</para>
      <itemizedlist>
        <listitem>
          <para>The output port of some other step.</para>
        </listitem>
        <listitem>
          <para>A fixed, inline document or sequence of documents.</para>
        </listitem>
        <listitem>
          <para>A document read from a URI.</para>
        </listitem>
        <listitem>
          <para>One of the inputs declared on one of its <glossterm>ancestors</glossterm>.</para>
        </listitem>
        <listitem>
          <para>A special port provided by an ancestor compound step, for example,
              “<port>current</port>” in a <tag>p:for-each</tag> or <tag>p:viewport</tag>. </para>
        </listitem>
      </itemizedlist>
      <para>When an input accepts a sequence of documents, the documents can come from any
        combination of these locations.</para>
      <para><error code="S0003">It is a <glossterm>static error</glossterm> if any declared input is
          not connected.</error></para>
      <para>The <glossterm>declared outputs</glossterm> of a step may be connected to:</para>
      <itemizedlist>
        <listitem>
          <para>The input port of some other step (including <tag>p:iteration-source</tag> or
              <tag>p:viewport-source</tag>).</para>
        </listitem>
        <listitem>
          <para>The <tag>p:xpath-context</tag> of a <tag>p:choose</tag> or <tag>p:when</tag>.</para>
        </listitem>
        <listitem>
          <para>An option assigned with <tag>p:with-option</tag> or a parameter assigned with
              <tag>p:with-param</tag>.</para>
        </listitem>
        <listitem>
          <para>One of the outputs declared on its container. </para>
        </listitem>
      </itemizedlist>
      <para>The <glossterm>primary output port</glossterm> of a step <rfc2119>must</rfc2119> be
        connected. <error code="S0005">It is a <glossterm>static error</glossterm> if the primary
          output port of any step is not connected.</error> Other outputs can remain unconnected.
        Any documents produced on an unconnected output port are discarded.</para>
      <para>Primary input and primary output ports may be implicitly connected if no explicit
        connection is given, see <xref linkend="primary-input-output"/>.</para>
      <para>Output ports on compound steps have a dual nature: from the perspective of the compound
        step's siblings, its outputs are just ordinary outputs and must be connected as described
        above. From the perspective of the subpipeline inside the compound step, they are inputs
        into which something may be connected.</para>
      <para>Within a compound step, the <glossterm>declared outputs</glossterm> of the step can be
        connected to:</para>
      <itemizedlist>
        <listitem>
          <para>The output port of some <glossterm baseform="contained steps">contained
              step</glossterm>.</para>
        </listitem>
        <listitem>
          <para>A fixed, inline document or sequence of documents.</para>
        </listitem>
        <listitem>
          <para>A document read from a URI.</para>
        </listitem>
      </itemizedlist>
      <para>If a (non-primary) output port of a compound step is left unconnected, it produces an
        empty sequence of documents from the perspective of its siblings.</para>
      <para>Each input and output on a step is declared to accept or produce either a single
        document or a sequence of documents. It <emphasis>is not</emphasis> an error to connect a
        port that is declared to produce a sequence of documents to a port that is declared to
        accept only a single document. It is, however, an error if the former step actually produces
        more than one document at run time.</para>
      <para>It is also not an error to connect a port that is declared to produce a single document
        to a port that is declared to accept a sequence. A single document is the same as a sequence
        of one document.</para>
      <para>An output port may have more than one connection: it may be connected to more than one
        input port, more than one of its container's output ports, or both. At runtime this will
        result in distinct copies of the output. </para>
      <para><termdef xml:id="dt-signature">The <firstterm>signature</firstterm> of a step is the set
          of inputs, outputs, and options that it is declared to accept.</termdef> The declaration
        for a step provides a fixed signature which all its instances share.</para>
      <para><termdef xml:id="dt-matches">A step <firstterm>matches</firstterm> its signature if and
          only if it specifies an input for each declared input, it specifies no inputs that are not
          declared, it specifies an option for each option that is declared to be required, and it
          specifies no options that are not declared.</termdef> In other words, every input and
        required option <rfc2119>must</rfc2119> be specified and only inputs and options that are
        declared <rfc2119>may</rfc2119> be specified. Options that aren't required do not have to be
        specified.</para>
      <para>Steps <rfc2119>may</rfc2119> also produce error, warning, and informative messages.
        These messages are captured and provided on the <port>error</port> port inside of a
          <tag>p:catch</tag>. <impl>Outside of a <link linkend="p.try">try/catch</link>, the
          disposition of error messages is <glossterm>implementation-dependent</glossterm></impl>. </para>

<para><impl>How inputs are connected to XML documents outside the
pipeline is <glossterm>implementation-defined</glossterm>.</impl>
In order to be consistent with the XPath data model, all general and external parsed
entities in such documents <rfc2119>must</rfc2119> be fully expanded; they
<rfc2119>must not</rfc2119> contain any representation of
<biblioref linkend="xml-infoset-rec"/>
<literal role="infoset-property">unexpanded entity reference information
items</literal>.</para>

<para><impl>How pipeline outputs are connected to XML documents outside the
pipeline is
<glossterm>implementation-defined</glossterm>.</impl></para>

<section xml:id="external-docs">
        <title>External Documents</title>
        <para>It's common for some of the documents used in processing a pipeline to be read from
          URIs. Sometimes this occurs directly, for example with a <tag>p:document</tag> element.
          Sometimes it occurs indirectly, for example if an implementation allows the URI of a
          pipeline input to be specified on the command line or if an <tag>p:xslt</tag> step
          encounters an <tag>xsl:import</tag> in the stylesheet that it is processing. It's also
          common for some of the documents produced in processing a pipeline to be written to
          locations which have, or at least could have, a URI. </para>
        <para>The process of dereferencing a URI to retrieve a document is often more interesting
          than it seems at first. On the web, it may involve caches, proxies, and various forms of
          indirection. <impl>Resolving a URI locally may involve resolvers of various sorts and
            possibly appeal to <glossterm>implementation-dependent</glossterm> mechanisms such as
            catalog files.</impl></para>
        <para>In XProc, the situation is made even more interesting by the fact that many
          intermediate results produced by steps in the pipeline have base URIs. <impl>Whether (and
            when and how) or not the intermediate results that pass between steps are ever written
            to a filesystem is <glossterm>implementation-dependent</glossterm>.</impl></para>
        <para><impl>In Version 1.0 of XProc, how (or if) implementers provide local resolution
            mechanisms and how (or if) they provide access to intermediate results by URI is
              <glossterm>implementation-defined</glossterm>.</impl>
        </para>
        <para>Version 1.0 of XProc does not require implementations to guarantee that multiple
          attempts to dereference the same URI always produce consistent results.</para>
        <note>
          <para>On the one hand, this is a somewhat unsatisfying state of affairs because it leaves
            room for interoperability problems. On the other, it is not expected to cause such
            problems very often in practice. </para>
          <para>If these problems arise in practice, implementers are encouraged to use the existing
            extension mechanisms to give users the control needed to circumvent them. Should such
            mechanisms become widespread, a standard mechanism could be added in some future version
            of the language.</para>
        </note>
      </section>
      <section xml:id="binary">
        <title>Non-XML Documents</title>
        <para>XProc is designed to allow pipeline authors to specify how an XML document, or
          sequence of XML documents, flows through a series of steps. For the most part, non-XML
          documents are considered out-of-scope.</para>
        <para>However, to be useful, XProc pipelines must interact with the real world where non-XML
          documents (HTML documents, raster images, non-XML encodings of data, etc.) are a fact of
          life.</para>
        <para>Accordingly, some pipelines may need to access non-XML documents and some non-XML
          documents may “leak” into pipelines. XProc provides a limited set of tools for processing
          these documents. In particular, XProc offers the ability to turn some “almost-XML”
          documents into XML and to allow some non-XML documents to flow quietly through the
          pipeline.</para>
        <para>It <emphasis>is not</emphasis> a goal of XProc that it should be a general-purpose
          pipeline language for manipulating arbitrary, non-XML resources.</para>
        <para>There are two standard ways that a non-XML document may enter a pipeline: directly
          through <tag>p:data</tag> or as the result of performing an <tag>p:http-request</tag>
          step. Loading non-XML data with a computed URI requires the <tag>p:http-request</tag>
          step. Implementors are encouraged to support the <literal>file:</literal> URI scheme so
          that users can load local data from computed URIs.</para>
        <para>In either case, non-XML documents are converted into text or are base64-encoded,
          depending on their content type and character encoding. The result is an XML document that
          consists of a document element containing either escaped text or base64-encoded text. This
          document can be processed like any other XML document.</para>
        <para>The <tag>p:unescape-markup</tag> step can be used to (attempt to) convert a non-XML
          document into XML. Well-formed XML that just happens to be represented with escaped markup
          can always be recovered. For other media types, the ability to construct XML and the
          precise mechanisms used to make the markup well-formed are <glossterm role="unwrapped"
            >implementation-defined</glossterm>.</para>
        <para>XProc provides no standard means to save encoded data in its unencoded binary form.
          Implementors may provide extension methods to allow the <tag>p:store</tag> step to save
          the binary data. For example, an implementation might provide a <code>ext:binary</code>
          serialization method that decoded base64 encoded data before saving it:</para>
        <programlisting><![CDATA[<p:store method="ext:binary" href="my.png">
  <p:input port="source">
    <p:inline>
      <c:data content-type="image/png">BASE64ENCODEDDATA</c:data>
    </p:inline>
  </p:input>
</p:store>]]></programlisting>
      </section>
    </section>
    <section xml:id="primary-input-output">
      <title>Primary Inputs and Outputs</title>
      <para>As a convenience for pipeline authors, each step may have one input port designated as
        the primary input port and one output port designated as the primary output port.</para>
      <para><termdef xml:id="dt-primary-input-port">If a step has a document input port which is
          explicitly marked “<code>primary='true'</code>”, or if it has exactly one document input
          port and that port is <emphasis>not</emphasis> explicitly marked
            “<code>primary='false'</code>”, then that input port is the <firstterm>primary input
            port</firstterm> of the step.</termdef> If a step has a single input port and that port
        is explicitly marked “<code>primary='false'</code>”, or if a step has more than one input
        port and none is explicitly marked as the primary, then the primary input port of that step
        is undefined. A step can have at most one primary input port.</para>
      <para><termdef xml:id="dt-primary-output-port">If a step has a document output port which is
          explicitly marked “<code>primary='true'</code>”, or if it has exactly one document output
          port and that port is <emphasis>not</emphasis> explicitly marked
            “<code>primary='false'</code>”, then that output port is the <firstterm>primary output
            port</firstterm> of the step.</termdef> If a step has a single output port and that port
        is explicitly marked “<code>primary='false'</code>”, or if a step has more than one output
        port and none is explicitly marked as the primary, then the primary output port of that step
        is undefined. A step can have at most one primary output port.</para>
      <para>The special significance of primary input and output ports is that they are connected
        automatically by the processor if no explicit connection is given. Generally speaking, if
        two steps appear sequentially in a subpipeline, then the primary output of the first step
        will automatically be connected to the primary input of the second.</para>
      <para>Additionally, if a compound step has no declared outputs and the <glossterm>last
          step</glossterm> in its subpipeline has an unconnected primary output, then an implicit
        primary output port will be added to the compound step (and consequently the last step's
        primary output will be connected to it). This implicit output port has no name. It inherits
        the <tag class="attribute">sequence</tag> property of the port connected to it. This rule
        does not apply to <tag>p:declare-step</tag>; step declarations must provide explicit names
        for all of their outputs.</para>
    </section>
    <section xml:id="connections">
      <title>Connections</title>
      <para>Steps are connected together by their input ports and output ports. <error code="S0001"
          >It is a <glossterm>static error</glossterm> if there are any loops in the connections
          between steps: no step can be connected to itself nor can there be any sequence of
          connections through other steps that leads back to itself.</error></para>
      <section xml:id="namespace-fixup">
        <title>Namespace Fixup on Outputs</title>
        <para>XProc processors are expected, and sometimes required, to perform <glossterm>namespace
            fixup</glossterm>. Unless the semantics of a step explicitly says otherwise:</para>
        <itemizedlist>
          <listitem>
            <para>The in-scope namespaces associated with a node (even those that are inherited from
              namespace bindings that appear among its ancestors in the document in which it appears
              initially) are assumed to travel with that node.</para>
          </listitem>
          <listitem>
            <para>Changes to one part of a tree (wrapping or unwrapping a node or renaming an
              element, for example) do not change the in-scope namespaces associated with the
              descendants of the node so changed.</para>
          </listitem>
        </itemizedlist>
        <para>As a result, some steps can produce XML documents which have no direct serialization
          (because they include nodes with conflicting or missing namespace declarations, for
          example). <termdef xml:id="dt-namespace-fixup">To produce a serializable
              <glossterm>XML</glossterm> document, the XProc processor must sometimes add additional
            namespace nodes, perhaps even renaming prefixes, to satisfy the constraints of
              <glossterm>Namespaces in XML</glossterm>. This process is referred to as
              <firstterm>namespace fixup</firstterm>.</termdef>
        </para>
        <para>Implementors are encouraged to perform <glossterm>namespace fixup</glossterm> before
          passing documents between steps, but they are not required to do so. Conversely, an
          implementation which <emphasis>does</emphasis> serialize between steps and therefore must
          perform such fixups, or reject documents that cannot be serialized, is also
          conformant.</para>
        <para>Except where the semantics of a step explicitly require changes, processors are
          required to preserve the information in the documents and fragments they manipulate. In
          particular, the information corresponding to the <biblioref linkend="xml-infoset-rec"/>
          properties <literal role="infoset-property">attributes</literal>, <literal
            role="infoset-property">base URI</literal>, <literal role="infoset-property"
            >children</literal>, <literal role="infoset-property">local name</literal>, <literal
            role="infoset-property">namespace name</literal>, <literal role="infoset-property"
            >normalized value</literal>, <literal role="infoset-property">owner</literal>, and
            <literal role="infoset-property">parent</literal>
          <rfc2119>must</rfc2119> be preserved.</para>
        <para>The information corresponding to <literal role="infoset-property">prefix</literal>,
            <literal role="infoset-property">in-scope namespaces</literal>, <literal
            role="infoset-property">namespace attributes</literal>, and <literal
            role="infoset-property">attribute type</literal>
          <rfc2119>should</rfc2119> be preserved, with changes to the first three only as required
          for <glossterm>namespace fixup</glossterm>. In particular, processors are encouraged to
          take account of prefix information in creating new namespace bindings, to minimize
          negative impact on prefixed names in content.</para>
        <para><impl>Except for cases which are specifically called out in <xref
              linkend="std-components"/>, the extent to which namespace fixup, and other checks for
            outputs which cannot be serialized, are performed on intermediate outputs is
              <glossterm>implementation-defined</glossterm>.</impl></para>
        <para>Whenever an implementation serializes pipeline contents, for example for pipeline
          outputs, logging, or as part of steps such as <tag>p:store</tag> or
            <tag>p:http-request</tag>, it is a <link xlink:href="#err.D0001">dynamic error</link> if
          that serialization could not be done so as to produce a document which is both well-formed
          and namespace-well-formed, as specified in <glossterm>XML</glossterm> and
            <glossterm>Namespaces in XML</glossterm>, regardless of what serialization method, if
          any, is called for.</para>
      </section>
    </section>
    <section xml:id="environment">
      <title>Environment</title>
      <para><termdef xml:id="dt-environment">The <firstterm>environment</firstterm> is a
          context-dependent collection of information available within subpipelines.</termdef> Most
        of the information in the environment is static and can be computed for each subpipeline
        before evaluation of the pipeline as a whole begins. The in-scope bindings have to be
        calculated as the pipeline is being evaluated.</para>
      <para>The environment consists of:</para>
      <orderedlist>
        <listitem>
          <para>A set of readable ports. <termdef xml:id="dt-readable-ports">The <firstterm>readable
                ports</firstterm> are a set of step name/port name pairs.</termdef> Inputs and
            outputs can only be connected to readable ports.</para>
        </listitem>
        <listitem>
          <para>A default readable port. <termdef xml:id="dt-default-readable-port">The
                <firstterm>default readable port</firstterm>, which may be undefined, is a specific
              step name/port name pair from the set of readable ports.</termdef></para>
        </listitem>
        <listitem>
          <para>A set of in-scope bindings. <termdef xml:id="dt-in-scope-bindings">The
                <firstterm>in-scope bindings</firstterm> are a set of name-value pairs, based on
                <glossterm>option</glossterm> and <glossterm>variable</glossterm>
              bindings.</termdef></para>
        </listitem>
      </orderedlist>
      <para><termdef xml:id="dt-empty-environment">The <firstterm>empty environment</firstterm>
          contains no readable ports, an undefined default readable port and no in-scope
          bindings.</termdef>
      </para>
      <para>Unless otherwise specified, the environment of a <glossterm baseform="contained steps"
          >contained step</glossterm> is its <glossterm>inherited environment</glossterm>. <termdef
          xml:id="dt-inherited-environment">The <firstterm>inherited environment</firstterm> of a
            <glossterm baseform="contained steps">contained step</glossterm> is an environment that
          is the same as the environment of its <glossterm>container</glossterm> with the <link
            linkend="dt-standard-modifications">standard modifications</link>. </termdef></para>
      <para>The <phrase xml:id="dt-standard-modifications">standard modifications</phrase> made to
        an inherited environment are:</para>
      <orderedlist>
        <listitem>
          <para>The declared inputs of the container are added to the <glossterm>readable
              ports</glossterm>.</para>
          <para>In other words, contained steps can see the inputs to their container.</para>
        </listitem>
        <listitem>
          <para>The union of all the declared outputs of all of the step's sibling steps are added
            to the <glossterm>readable ports</glossterm>.</para>
          <!--
          <para>The union of all the declared outputs of all of the containers's
              <glossterm>contained steps</glossterm> are added to the <glossterm>readable
              ports</glossterm>.</para>
              -->
          <para>In other words, sibling steps can see each other's outputs in addition to the
            outputs visible to their container.</para>
        </listitem>
        <listitem>
          <para>If there is a preceding sibling step element:</para>
          <itemizedlist>
            <listitem>
              <para>If that preceding sibling has a <glossterm>primary output port</glossterm>, then
                that output port becomes the <glossterm>default readable port</glossterm>.</para>
            </listitem>
            <listitem>
              <para>Otherwise, the <glossterm>default readable port</glossterm> is undefined.</para>
            </listitem>
          </itemizedlist>
        </listitem>
        <listitem>
          <para>If there <emphasis>is not</emphasis> a preceding sibling step element: </para>
          <itemizedlist>
            <listitem>
              <para>If the container has a <glossterm>primary input port</glossterm>, the
                  <glossterm>default readable port</glossterm> is that <glossterm>primary input
                  port</glossterm>.</para>
            </listitem>
            <listitem>
              <para>Otherwise, the default readable port is unchanged.</para>
            </listitem>
          </itemizedlist>
        </listitem>
        <listitem>
          <para>The names and values from each <tag>p:variable</tag> present at the beginning of the
            container are added, in document order, to the <glossterm>in-scope bindings</glossterm>.
            A new binding replaces an old binding with the same name. See <xref linkend="p.variable"
            /> for the specification of variable evaluation.</para>
        </listitem>
      </orderedlist>
      <para>A step with no parent inherits the <glossterm>empty environment</glossterm>. </para>
    </section>
    <section xml:id="xpath-context">
      <title>XPaths in XProc</title>
      <para>XProc uses XPath as an expression language. XPath expressions are evaluated by the XProc
        processor in several places: on compound steps, to compute the default values of options and
        the values of variables; on atomic steps, to compute the actual values of options and the
        values of parameters.</para>
      <para>XPath expressions are also passed to some steps. These expressions are evaluated by the
        implementations of the individual steps.</para>
      <para>This distinction can be seen in the following example:</para>
      <programlisting><xi:include href="examples/xpathcontext.txt" parse="text"/></programlisting>
      <para>The select expression on the variable “<varname>home</varname>” is evaluated by the
        XProc processor. The value of the variable is “<uri>http://example.com/docs</uri>”.</para>
      <para>The <option>href</option> option of the <tag>p:load</tag> step is evaluated by the XProc
        processor. The actual <literal>href</literal> option received by the step is simply the
        string literal “<uri>http://example.com/docs/document.xml</uri>”. (The select expression on
        the <literal>source</literal> input of the <tag>p:split-sequence</tag> step is also
        evaluated by the XProc processor.) </para>
      <para>The XPath expression “<literal>@role='chapter'</literal>” is passed literally to the
          <literal>test</literal> option on the <tag>p:split-sequence</tag> step. That's because the
        nature of the <tag>p:split-sequence</tag> is that <emphasis>it evaluates</emphasis> the
        expression. Only some options on some steps expect XPath expressions. </para>
      <para>The XProc processor evaluates all of the XPath expressions in <tag class="attribute"
          >select</tag> attributes on variables, options, parameters, and inputs, in <tag
          class="attribute">match</tag> attributes on <tag>p:viewport</tag>, and in <tag
          class="attribute">test</tag> attributes on <tag>p:when</tag> steps.</para>
      <para>An XProc implementation can use <emphasis>either</emphasis>
        <biblioref linkend="xpath"/> or <biblioref linkend="xpath2"/> to evaluate these
        expressions.</para>
      <note>
        <para>Allowing either XPath 1.0 or XPath 2.0 is a compromise driven entirely by the timing
          of XProc development. During the development of this specification, the community
          indicated that it was too early to mandate that all implementations use XPath 2.0 and too
          late to mandate that all implementations use XPath 1.0.</para>
      </note>
      <para>Many, many expressions that are likely to be used in XProc pipelines are the same in
        both versions (simple element tests, ancestor and descendant tests, string-based attribute
        tests, etc.).</para>
      <para>As an aid to interoperability, pipeline authors may indicate the version of XPath that
        they require. The attribute <tag class="attribute">xpath-version</tag> may be used on
          <tag>p:pipeline</tag>, <tag>p:declare-step</tag>, or <tag>p:library</tag> to identify the
        XPath version that <rfc2119>must</rfc2119> be used to evaluate XPath expressions on the
        pipeline(s). The attribute is lexically scoped, but see below.</para>

<note>
<para>In Version 1.0 of XProc, no similar level of control is provided
for specifying (or testing) the version of XSLT used when evaluating
<type>XSLTMatchPattern</type>s. The expectation is that XPath 1.0 processors
will be using XSLT 1.0 match patterns and XPath 2.0 processors will be using
XSLT 2.0 match patterns, but that is not necessarily the case.
</para>
<para>As XPath, XSLT, and XProc continue to evolve, additional facilities for
specifying and testing the version of XSLT used to evaluate match patterns
may be added to XProc.</para>
</note>

      <para>If an <tag class="attribute">xpath-version</tag> is specified on a <tag>p:pipeline</tag>
        or <tag>p:declare-step</tag>, then that is the version of XPath that the step requires. If
        it does not specify a version, but a version is specified on one of its ancestors, the
        nearest ancestor version specified is the version that it requires. An <tag
          class="attribute">xpath-version</tag> attribute on a <tag>p:library</tag> specifies a
        default version for all steps defined in that library. <impl>If no version is specified on
          the step or among its ancestors, then its XPath version is
            <glossterm>implementation-defined</glossterm>.</impl>
      </para>
      <note>
        <para>The decision about which XPath version applies can be made dynamically. For example,
          if a pipeline explicitly labeled with <tag class="attribute">xpath-version</tag> “1.0”
          imports a library that does not specify a version, the implementation may elect to make
          the implementation-defined XPath version of the steps in the library also “1.0”. If the
          same implementation imports that library into a pipeline explicitly labeled with <tag
            class="attribute">xpath-version</tag> “2.0”, it can make the implementation-defined
          version of those steps “2.0”. </para>
      </note>
      <para>The following rules determine how the indicated version and the implementation's actual
        version interact:</para>
      <orderedlist>
        <listitem>
          <para>If the indicated version and the implementation version are the same, then that
            version is used.</para>
        </listitem>
        <listitem>
          <para>If the indicated version is 1.0 and the implementation uses XPath 2.0 (or later),
            the expression <rfc2119>must</rfc2119> be evaluated in XPath 1.0 compatibility mode.
              <error code="D0024">It is a <glossterm>dynamic error</glossterm> if a 2.0 processor
              encounters an XPath 1.0 expression and it does not support XPath 1.0 compatibility
              mode.</error>
          </para>
        </listitem>
        <listitem>
          <para>Otherwise: <error code="D0027">It is a <glossterm>dynamic error</glossterm> if the
              processor encounters an <tag class="attribute">xpath-version</tag> that it does not
              support.</error>
          </para>
        </listitem>
      </orderedlist>
      <para>XProc processors divide naturally into two classes: XPath 1.0 processors and XPath 2.0
        processors.</para>
      <para>Irrespective of which version of XPath is used, all expressions evaluated by XProc or
        passed to steps for evaluation must be valid XPath expressions. <error code="D0023">It is a
            <glossterm>dynamic error</glossterm> if an XPath expression is encountered which cannot
          be evaluated (because it is syntactically incorrect, contains references to unbound
          variables or unknown functions, or for any other reason). </error></para>
      <section xml:id="xpath10-processors">
        <title>XPath 1.0 processors</title>
        <para>XProc processors that support only XPath 1.0 do not support any types (or features)
          beyond those described in <biblioref linkend="xpath"/>. They use the XPath 1.0 data model.
          Processors <rfc2119>must</rfc2119> implement all of the XPath 1.0 functions, but are not
          expected to implement the functions described in <biblioref linkend="xslt10"/>.</para>
        <section xml:id="xproc-xpath-context-10">
          <title>Processor XPath Context</title>
          <para>When the XProc processor evaluates an XPath expression using XPath 1.0, unless
            otherwise indicated by a particular step, it does so with the following initial
            context:</para>
          <variablelist>
            <varlistentry>
              <term>context node</term>
              <listitem>
                <para>The document node of a document. The document is either specified with a
                    <glossterm>connection</glossterm> or is taken from the <glossterm>default
                    readable port</glossterm>. <error code="D0008">It is a <glossterm>dynamic
                      error</glossterm> if a document sequence appears where a document to be used
                    as the context node is expected.</error>
                </para>
                <para>If there is no explicit connection and there is no default readable port then
                  the context node is an empty document node.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>context position and context size</term>
              <listitem>
                <para>The context position and context size are both “1”. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>variable bindings</term>
              <listitem>
                <para>The union of the in-scope <glossterm>specified options</glossterm> and
                  variables are available as variable bindings to the XPath processor. </para>
                <note>
                  <para>An option that has neither a specified value nor a default value will not
                    appear as an in-scope variable. Consequently, an attempt to refer to that
                    variable will raise an error.</para>
                </note>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>function library</term>
              <listitem>
                <para>The <biblioref linkend="xpath"/> core function library and the <xref
                    linkend="xpath-extension-functions"/>. Function names that do not contain a
                  colon always refer to the XPath 1.0 functions, any in-scope binding for the
                  default namespace <emphasis>does not</emphasis> apply.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>in-scope namespaces</term>
              <listitem>
                <para>The namespace bindings in-scope on the element where the expression occurred.
                </para>
              </listitem>
            </varlistentry>
          </variablelist>
        </section>
        <section xml:id="step-xpath-context-10">
          <title>Step XPath Context</title>
          <para>When <emphasis>a step</emphasis> evaluates an XPath expression using XPath 1.0,
            unless otherwise indicated by a particular step, it does so with the following initial
            context:</para>
          <variablelist>
            <varlistentry>
              <term>context node</term>
              <listitem>
                <para>The document node that appears on the primary input port of the step, unless
                  otherwise specified by the step. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>context position and context size</term>
              <listitem>
                <para>The position and size are both “1”, unless otherwise specified by the step.
                </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>variable bindings</term>
              <listitem>
                <para>None, unless otherwise specified by the step. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>function library</term>
              <listitem>
                <para>The <biblioref linkend="xpath"/> core function library, unless otherwise
                  specified by the step. Function names that do not contain a colon always refer to
                  the XPath 1.0 functions, any in-scope binding for the default namespace
                    <emphasis>does not</emphasis> apply. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>in-scope namespaces</term>
              <listitem>
                <para>The set of namespace bindings provided by the XProc processor. The processor
                  computes this set of bindings by taking a union of the bindings on the step
                  element itself as well as the bindings on any of the options and parameters used
                  in computing values for the step (see <xref linkend="opt-param-bindings"
                  />).</para>
                <para><impl>The results of computing the union of namespaces in the presence of
                    conflicting declarations for a particular prefix are
                      <glossterm>implementation-dependent</glossterm>.</impl></para>
              </listitem>
            </varlistentry>
          </variablelist>
          <note>
            <para>Some steps may also provide for implementation-defined or implementation-dependent
              amendments to the contexts. Those amendments are in addition to any specified by
              XProc.</para>
          </note>
        </section>
      </section>
      <section xml:id="xpath20-processors">
        <title>XPath 2.0 processors</title>
        <para>XProc processors that support XPath 2.0 are XPath 2.0 processors. Such processors can
          refer to the primitive atomic schema types, but cannot import additional types.</para>
        <para>XPath 2.0 processors <rfc2119>must</rfc2119> implement all of the XPath 2.0 functions,
          but are not expected to implement the functions described in <biblioref linkend="xslt20"
          />.</para>
        <section xml:id="xproc-xpath-context-20">
          <title>Processor XPath Context</title>
          <para>When the XProc processor evaluates an XPath expression using XPath 2.0, unless
            otherwise indicated by a particular step, it does so with the following static
            context:</para>
          <variablelist>
            <varlistentry>
              <term>XPath 1.0 compatibility mode</term>
              <listitem>
                <para>Is true if the indicated XPath version is 1.0, false otherwise.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Statically known namespaces</term>
              <listitem>
                <para>The namespace declarations in-scope for the containing element. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Default element/type namespace</term>
              <listitem>
                <para>The null namespace.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Default function namespace</term>
              <listitem>
                <para>The <biblioref linkend="xpath2"/> function namespace. Function names that do
                  not contain a colon always refer to the default function namespace, any in-scope
                  binding for the default namespace <emphasis>does not</emphasis> apply. This
                  specification does not provide a mechanism to override the default function
                  namespace.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>In-scope schema definitions</term>
              <listitem>
                <para>A basic XPath 2.0 XProc processor includes the following named type
                  definitions in its in-scope schema definitions:</para>
                <itemizedlist>
                  <listitem>
                    <para>All the primitive atomic types defined in <biblioref linkend="xmlschema-2"
                      />, with the exception of <literal>xs:NOTATION</literal>. That is:
                        <literal>xs:string</literal>, <literal>xs:boolean</literal>,
                        <literal>xs:decimal</literal>, <literal>xs:double</literal>,
                        <literal>xs:float</literal>, <literal>xs:date</literal>,
                        <literal>xs:time</literal>, <literal>xs:dateTime</literal>,
                        <literal>xs:duration</literal>, <literal>xs:QName</literal>,
                        <literal>xs:anyURI</literal>, <literal>xs:gDay</literal>,
                        <literal>xs:gMonthDay</literal>, <literal>xs:gMonth</literal>,
                        <literal>xs:gYearMonth</literal>, <literal>xs:gYear</literal>,
                        <literal>xs:base64Binary</literal>, and <literal>xs:hexBinary</literal>.
                    </para>
                  </listitem>
                  <listitem>
                    <para>The derived atomic type <literal>xs:integer</literal> defined in
                        <biblioref linkend="xmlschema-2"/>. </para>
                  </listitem>
                  <listitem>
                    <para>The types <literal>xs:anyType</literal>,
                        <literal>xs:anySimpleType</literal>,
                      <literal>xs:yearMonthDuration</literal>,
                      <literal>xs:dayTimeDuration</literal>, <literal>xs:anyAtomicType</literal>,
                        <literal>xs:untyped</literal>, and <literal>xs:untypedAtomic</literal>
                      defined in <biblioref linkend="xpath-datamodel"/>. </para>
                  </listitem>
                </itemizedlist>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>In-scope variables</term>
              <listitem>
                <para>The union of the in-scope <glossterm>specified options</glossterm> and
                  variables are available as variable bindings to the XPath processor. </para>
                <note>
                  <para>An option that has neither a specified value nor a default value will not
                    appear as an in-scope variable. Consequently, an attempt to refer to that
                    variable will raise an error.</para>
                </note>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Context item static type</term>
              <listitem>
                <para>Document.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Function signatures</term>
              <listitem>
                <para>The signatures of the <biblioref linkend="xpath-functions"/> and the <xref
                    linkend="xpath-extension-functions"/>. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Statically known collations</term>
              <listitem>
                <para>Implementation-defined but <rfc2119>must</rfc2119> include the Unicode code
                  point collation. <impl>The version of Unicode supported is
                      <glossterm>implementation-defined</glossterm>, but it is recommended that the
                    most recent version of Unicode be used.</impl>
                </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Default collation</term>
              <listitem>
                <para>Unicode code point collation.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Base URI</term>
              <listitem>
                <para>The base URI of the element on which the expression occurs.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Statically known documents</term>
              <listitem>
                <para>None.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Statically known collections</term>
              <listitem>
                <para>None.</para>
              </listitem>
            </varlistentry>
          </variablelist>
          <para>And the following dynamic context:</para>
          <variablelist>
            <varlistentry>
              <term>context item</term>
              <listitem>
                <para>The document node of a document. The document is either specified with a
                    <glossterm>connection</glossterm> or is taken from the <glossterm>default
                    readable port</glossterm>. <error code="D0008">It is a <glossterm>dynamic
                      error</glossterm> if a document sequence appears where a document to be used
                    as the context node is expected.</error>
                </para>
                <para>If there is no explicit connection and there is no default readable port then
                  the context node is undefined.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>context position and context size</term>
              <listitem>
                <para>The context position and context size are both “1”. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Variable values</term>
              <listitem>
                <para>The union of the in-scope options and variables are available as variable
                  bindings to the XPath processor. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Function implementations</term>
              <listitem>
                <para>The <biblioref linkend="xpath-functions"/> and the <xref
                    linkend="xpath-extension-functions"/>. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Current dateTime</term>
              <listitem>
                <para><impl>The point in time returned as the current dateTime is
                      <glossterm>implementation-defined</glossterm>.</impl>
                </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Implicit timezone</term>
              <listitem>
                <para><impl>The implicit timezone is
                    <glossterm>implementation-defined</glossterm>.</impl></para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Available documents</term>
              <listitem>
                <para><impl>The set of available documents (those that may be retrieved with a URI)
                    is <glossterm>implementation-dependent</glossterm>.</impl></para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Available collections</term>
              <listitem>
                <para><impl>The set of available collections is
                      <glossterm>implementation-dependent</glossterm>.</impl></para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Default collection</term>
              <listitem>
                <para>None. </para>
              </listitem>
            </varlistentry>
          </variablelist>
        </section>
        <section xml:id="step-xpath-context-20">
          <title>Step XPath Context</title>
          <para>When a step evaluates an XPath expression using XPath 2.0, unless otherwise
            indicated by a particular step, it does so with the following static context:</para>
          <variablelist>
            <varlistentry>
              <term>XPath 1.0 compatibility mode</term>
              <listitem>
                <para>Is true if the indicated XPath version is 1.0, false otherwise.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Statically known namespaces</term>
              <listitem>
                <para>The namespace declarations in-scope for the containing element or made
                  available through <tag>p:namespaces</tag>. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Default element/type namespace</term>
              <listitem>
                <para>The null namespace.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Default function namespace</term>
              <listitem>
                <para>The <biblioref linkend="xpath2"/> function namespace. Function names that do
                  not contain a colon always refer to the default function namespace, any in-scope
                  binding for the default namespace <emphasis>does not</emphasis> apply. This
                  specification does not provide a mechanism to override the default function
                  namespace.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>In-scope schema definitions</term>
              <listitem>
                <para>The same as the <xref linkend="xproc-xpath-context-20"/>. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>In-scope variables</term>
              <listitem>
                <para>None, unless otherwise specified by the step. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Context item static type</term>
              <listitem>
                <para>Document.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Function signatures</term>
              <listitem>
                <para>The signatures of the <biblioref linkend="xpath-functions"/>.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Statically known collations</term>
              <listitem>
                <para>Implementation-defined but <rfc2119>must</rfc2119> include the Unicode code
                  point collation.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Default collation</term>
              <listitem>
                <para>Unicode code point collation.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Base URI</term>
              <listitem>
                <para>The base URI of the element on which the expression occurs.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Statically known documents</term>
              <listitem>
                <para>None.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Statically known collections</term>
              <listitem>
                <para>None.</para>
              </listitem>
            </varlistentry>
          </variablelist>
          <para>And the following initial dynamic context:</para>
          <variablelist>
            <varlistentry>
              <term>context item</term>
              <listitem>
                <para>The document node of the document that appears on the primary input of the
                  step, unless otherwise specified by the step.</para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>context position and context size</term>
              <listitem>
                <para>The context position and context size are both “1”, unless otherwise specified
                  by the step. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Variable values</term>
              <listitem>
                <para>None, unless otherwise specified by the step. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Function implementations</term>
              <listitem>
                <para>The <biblioref linkend="xpath-functions"/>. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Current dateTime</term>
              <listitem>
                <para>An implementation-defined point in time. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Implicit timezone</term>
              <listitem>
                <para><impl>The implicit timezone is
                    <glossterm>implementation-defined</glossterm>.</impl></para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Available documents</term>
              <listitem>
                <para><impl>The set of available documents (those that may be retrieved with a URI)
                    is <glossterm>implementation-dependent</glossterm>.</impl></para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Available collections</term>
              <listitem>
                <para>None. </para>
              </listitem>
            </varlistentry>
            <varlistentry>
              <term>Default collection</term>
              <listitem>
                <para>None. </para>
              </listitem>
            </varlistentry>
          </variablelist>
          <note>
            <para>Some steps may also provide for implementation-defined or implementation-dependent
              amendments to the contexts. Those amendments are in addition to any specified by
              XProc.</para>
          </note>
        </section>
      </section>
    </section>
    <section xml:id="xpath-extension-functions">
      <title>XPath Extension Functions</title>
      <para>The XProc processor <rfc2119>must</rfc2119> support the additional functions described
        in this section in XPath expressions evaluated by the processor.</para>
      <para>In the following descriptions, the names of types (<type>string</type>,
          <type>boolean</type>, etc.) should be taken to mean the corresponding <biblioref
          linkend="xmlschema-2"/> data types for an implementation that uses XPath 2.0 and as the
        most appropriate XPath 1.0 types for an XPath 1.0 implementation.</para>
      <section xml:id="f.system-property">
        <title>System Properties</title>
        <para>XPath expressions within a pipeline document can interrogate the processor for
          information about the current state of the pipeline. Various aspects of the processor are
          exposed through the <function>p:system-property</function> function in the pipeline
          namespace:</para>

<methodsynopsis>
<type>xs:string</type>
<methodname>p:system-property</methodname>
<methodparam><type>xs:string</type><parameter>property</parameter></methodparam>
</methodsynopsis>

        <para>The <varname>$property</varname> string must have the form of a <link
            xlink:href="http://www.w3.org/TR/xml-names/#NT-QName">QName</link>; the QName is
          expanded into a name using the namespace declarations in scope for the expression. <error
            code="D0015">It is a <glossterm>dynamic error</glossterm> if the specified QName cannot
            be resolved with the in-scope namespace declarations.</error> The
            <function>p:system-property</function> function returns the string representing the
          value of the system property identified by the QName. If there is no such property, the
          empty string <rfc2119>must</rfc2119> be returned.</para>
        <para>Implementations <rfc2119>must</rfc2119> provide the following system properties, which
          are all in the XProc namespace:</para>
        <variablelist>
          <varlistentry>
            <term><varname>p:episode</varname></term>
            <listitem>
              <para>Returns a string which <rfc2119>should</rfc2119> be unique for each invocation
                of the pipeline processor. In other words, if a processor is run several times in
                succession, or if several processors are running simultaneously, each invocation of
                each processor should get a distinct value from <varname>p:episode</varname>.</para>
              <para>The unique identifier must be a valid <link
                  xlink:href="http://www.w3.org/TR/XML#NT-Name">XML name</link>. </para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term><varname>p:language</varname></term>
            <listitem>
              <para>Returns a string which identifies the current language, for example, for message
                localization purposes. <impl>The exact format of the language string is
                    <glossterm>implementation-defined</glossterm> but <rfc2119>should</rfc2119> be
                  consistent with the <tag class="attribute">xml:lang</tag> attribute.</impl></para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term><varname>p:product-name</varname></term>
            <listitem>
              <para>Returns a string containing the name of the implementation, as defined by the
                implementer. This should normally remain constant from one release of the product to
                the next. It should also be constant across platforms in cases where the same source
                code is used to produce compatible products for multiple execution platforms.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term><varname>p:product-version</varname></term>
            <listitem>
              <para>Returns a string identifying the version of the implementation, as defined by
                the implementer. This should normally vary from one release of the product to the
                next, and at the discretion of the implementer it may also vary across different
                execution platforms. </para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term><varname>p:vendor</varname></term>
            <listitem>
              <para>Returns a string which identifies the vendor of the processor.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term><varname>p:vendor-uri</varname></term>
            <listitem>
              <para>Returns a URI which identifies the vendor of the processor. Often, this is the
                URI of the vendor's web site.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term><varname>p:version</varname></term>
            <listitem>
<para>Returns the version(s) of XProc implemented by the processor
as a space-separated list. For example, a processor
that supports XProc 1.0 would return “1.0”; a processor that
supports XProc 1.0 and 2.0 would
return “1.0 2.0”; a processor that supports only XProc 2.0 would
return “2.0”.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term><varname>p:xpath-version</varname></term>
            <listitem>
              <para>Returns the version(s) of XPath implemented by the processor for evaluating
                XPath expressions on XProc elements. The result is a space-separated list of versions supported. For
                example, a processor that only supports XPath 1.0 would return “1.0”; a processor
                that supports XPath 2.0 and XPath 1.0 backwards compatibility mode could return “1.0
                2.0”; a processor that supports only XPath 2.0 would return “2.0”.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term><varname>p:psvi-supported</varname></term>
            <listitem>
              <para>Returns true if the implementation supports passing PSVI annotations between
                steps, false otherwise.</para>
            </listitem>
          </varlistentry>
        </variablelist>

<para>Implementations may support additional system properties but such properties
<rfc2119>must</rfc2119> be in a namespace and <rfc2119>must not</rfc2119> be
in the XProc namespace.</para>

      </section>
      <section xml:id="f.step-available">
        <title>Step Available</title>
        <para>The <function>p:step-available</function> function reports whether or not a particular
          type of step is understood by the processor.</para>

<methodsynopsis>
<type>xs:boolean</type>
<methodname>p:step-available</methodname>
<methodparam><type>xs:string</type><parameter>step-name</parameter></methodparam>
</methodsynopsis>

        <para>The <varname>$step-type</varname> string <rfc2119>must</rfc2119> have the form of a
          QName; the QName is expanded into a name using the namespace declarations in-scope for the
          expression. The <function>p:step-available</function> function returns true if and only if
          the processor knows how to evaluate steps of the specified type.</para>
      </section>
      <section xml:id="f.value-available">
        <title>Value Available</title>
        <para>The <function>p:value-available</function> function reports whether or not a
          particular in-scope option has a value.</para>


<methodsynopsis>
<type>xs:boolean</type>
<methodname>p:value-available</methodname>
<methodparam><type>xs:string</type><parameter>option-name</parameter></methodparam>
</methodsynopsis>

<methodsynopsis>
<type>xs:boolean</type>
<methodname>p:value-available</methodname>
<methodparam><type>xs:string</type><parameter>option-name</parameter></methodparam>
<methodparam><type>xs:boolean</type><parameter>fail-if-unknown</parameter></methodparam>
</methodsynopsis>

<para>The <varname>$option-name</varname> string
<rfc2119>must</rfc2119> have the form of a QName; the QName is
expanded into a name using the namespace declarations in-scope for the
expression. The <function>p:value-available</function> function
returns true if and only if the name specified is the name of an
<glossterm baseform="in-scope-bindings">in-scope binding</glossterm>
and the binding has a value. <error code="D0033">It is a
<glossterm>dynamic error</glossterm> if the name specified is not the
name of an in-scope option or variable.</error></para>

<para>In the two-argument form, it is not an error to specify a name
that is not the name of an in-scope option or variable if
<varname>$fail-if-unknown</varname> is false; the function simply
returns false. The semantics of the two-argument form when
<varname>$fail-if-unknown</varname> is true are precisely the same as
the single argument form.</para>

<para>Consider the following example:</para>

<programlisting><xi:include href="examples/value-available.txt" parse="text"/></programlisting>

<para>If the <option>path</option> option is specified in the call to
<code>ex:dir-list</code>, then the first <tag>p:when</tag> clause will
be evaluated and the specified value will be used. If the option is
not specified, then the <tag>p:otherwise</tag> clause will be
evaluated and "<literal>.</literal>" will be used instead.</para>

</section>

<section xml:id="f.iteration-position">
<title>Iteration Position</title>

<para>Both <tag>p:for-each</tag> and <tag>p:viewport</tag> process a
sequence of documents. The iteration position is the position of the
current document in that sequence: the first document has position 1, the
second 2, etc. The <function>p:iteration-position</function> function
returns the iteration position of the nearest
ancestor <tag>p:for-each</tag> or <tag>p:viewport</tag>.</para>

<methodsynopsis>
<type>xs:integer</type>
<methodname>p:iteration-position</methodname>
<void/>
</methodsynopsis>

<para>If there is no <tag>p:for-each</tag> or <tag>p:viewport</tag>
among the ancestors of the element on which the expression involving
<function>p:iteration-position</function> occurs, it returns 1.</para>

</section>

<section xml:id="f.iteration-size">
<title>Iteration Size</title>

<para>Both <tag>p:for-each</tag> and <tag>p:viewport</tag> process a
sequence of documents. The iteration size is the total number of documents
in that sequence. The <function>p:iteration-size</function> function
returns the iteration size of the nearest
ancestor <tag>p:for-each</tag> or <tag>p:viewport</tag>.</para>

<methodsynopsis>
<type>xs:integer</type>
<methodname>p:iteration-size</methodname>
<void/>
</methodsynopsis>

<para>If there is no <tag>p:for-each</tag> or <tag>p:viewport</tag>
among the ancestors of the element on which the expression involving
<function>p:iteration-size</function> occurs, it returns 1.</para>

</section>

      <section xml:id="f.base-uri">
        <title>Base URI</title>
        <para>Returns the base URI of the specified node, if it has one. This function provides an
          interoperable way for XPath 1.0 based processors to access the base URI of a node. It is
          conceptually the same as the XPath 2.0 <literal>fn:base-uri()</literal> function.</para>

<methodsynopsis>
<type>xs:string</type>
<methodname>p:base-uri</methodname>
<void/>
</methodsynopsis>

<methodsynopsis>
<type>xs:string</type>
<methodname>p:base-uri</methodname>
<methodparam><type>node()</type><parameter>node</parameter></methodparam>
</methodsynopsis>

        <para>If no argument is specified, the context node is taken to be the argument.</para>
        <para>This function returns the <literal>[base-uri]</literal> property of its argument, or
          the empty string if no base URI is defined for that argument or argument type.</para>
        <note>
          <para>This function is defined in our namespace because it would be inappropriate to
            require XPath 1.0 based processors to support the <literal>fn:base-uri</literal>
            function; its semantics are deeply rooted in the XPath 2.0 data model which differs from
            the XPath 1.0 data model.</para>
        </note>
      </section>

      <section xml:id="f.resolve-uri">
        <title>Resolve URI</title>
        <para>Resolves a relative URI with respect to a particular base URI. This function provides
          an interoperable way for XPath 1.0 based processors to compose URI references. It is
          conceptually the same as the XPath 2.0 <literal>fn:resolve-uri()</literal>
          function.</para>

<methodsynopsis>
<type>xs:string</type>
<methodname>p:resolve-uri</methodname>
<methodparam><type>xs:string</type><parameter>relative</parameter></methodparam>
</methodsynopsis>

<methodsynopsis>
<type>xs:string</type>
<methodname>p:resolve-uri</methodname>
<methodparam><type>xs:string</type><parameter>relative</parameter></methodparam>
<methodparam><type>xs:string</type><parameter>base</parameter></methodparam>
</methodsynopsis>

        <para>If no base is specified, the base URI of the context node is used. </para>
        <note>
          <para>This function is defined in our namespace because it would be inappropriate to
            require XPath 1.0 based processors to support the <literal>fn:resolve-uri</literal>
            function; its semantics are rooted in the XPath 2.0 data model which differs from the
            XPath 1.0 data model.</para>
        </note>
      </section>

<section xml:id="f.version-available">
<title>Version Available</title>

<para>Returns true if and only if the processor supports the version
specified.</para>

<methodsynopsis>
<type>xs:boolean</type>
<methodname>p:version-available</methodname>
<methodparam><type>xs:decimal</type><parameter>version</parameter></methodparam>
</methodsynopsis>

<para>A version 1.0 processor will return <literal>true()</literal> when
<code>p:version-available(1.0)</code> is evaluated.</para>

</section>

<section xml:id="f.xpath-version-available">
<title>XPath Version Available</title>

<para>Returns true if and only if the processor supports the XPath version
specified.</para>

<methodsynopsis>
<type>xs:boolean</type>
<methodname>p:xpath-version-available</methodname>
<methodparam><type>xs:decimal</type><parameter>version</parameter></methodparam>
</methodsynopsis>

<para>A processor that supports XPath 2.0 will return <literal>true()</literal> when
<code>p:xpath-version-available(2.0)</code> is evaluated.</para>

</section>

      <section xml:id="other-xpath-extension-functions">
        <title>Other XPath Extension Functions</title>
        <para><impl>It is <glossterm>implementation-defined</glossterm> if the processor supports
            any other XPath extension functions.</impl> Additional extension functions, if any,
            <rfc2119>must not</rfc2119> use any of the XProc namespaces. </para>
      </section>
    </section>
    <section xml:id="psvi-support">
      <title>PSVIs in XProc</title>
      <para>XML documents flow between steps in an XProc pipeline. <xref
          linkend="infoset-conformance"/> identifies the properties of those documents that
          <rfc2119>must</rfc2119> be available. Implementations <rfc2119>may</rfc2119> also have the
        ability to pass PSVI annotations between steps.</para>
      <para><impl>Whether or not the pipeline processor supports passing PSVI annotations between
          steps is <glossterm>implementation-defined</glossterm>.</impl>
        <impl>The exact PSVI properties that are preserved when documents are passed between steps
          is <glossterm>implementation-defined</glossterm>.</impl></para>
      <para>A pipeline can use the <varname>p:psvi-supported</varname> system property to determine
        whether or not PSVI properties can be passed between steps.</para>
      <para>A pipeline can assert that PSVI support is required with the <tag class="attribute"
          >psvi-required</tag> attribute:</para>
      <itemizedlist>
        <listitem>
          <para>On a <tag>p:pipeline</tag> or <tag>p:declare-step</tag>, <tag class="attribute"
              >psvi-required</tag> indicates whether or not the declared step requires PSVI support.
              <error code="D0022">It is a <glossterm>dynamic error</glossterm> if a processor that
              does not support PSVI annotations attempts to invoke a step which asserts that they
              are required.</error></para>
        </listitem>
        <listitem>
          <para>On a <tag>p:library</tag>, the <tag class="attribute">psvi-required</tag> attribute
            provides a default value for all of its <tag>p:pipeline</tag> and
              <tag>p:declare-step</tag>
            <emphasis>children</emphasis> that do not specify a value themselves.</para>
        </listitem>
      </itemizedlist>
      <para>Many of the steps that an XProc pipeline can use are transformative in nature. The
          <tag>p:delete</tag> step, for example, can remove elements and attributes; the
          <tag>p:label-elements</tag> step can add attributes; etc. If PSVI annotations were always
        preserved, the use of such steps could result in documents that were inconsistent with their
        schema annotations.</para>
      <para>In order to avoid these inconsistencies, most steps <rfc2119>must not</rfc2119> produce
        PSVI annotated results even when PSVI passing is supported.</para>
      <para>If PSVI passing is supported, the following constraints apply:</para>
      <orderedlist>
        <listitem>
          <para>Implementations <rfc2119>must</rfc2119> faithfully transmit any PSVI properties
            produced on step outputs to the steps to which they are connected.</para>
        </listitem>
        <listitem>
          <para>When only a subset of the input is processed by a step (because a <tag
              class="attribute">select</tag> expression appears on an input port or a <tag
              class="attribute">match</tag> expression is used to process only part of the input),
            any PSVI annotations that appear on the selected input <rfc2119>must</rfc2119> be
            preserved in the resulting documents passed to the step.</para>
          <para>Note that ID/IDREF constraints, and any other whole-document constraints, may not be
            satisfied within the selected portion, irrespective of what its PSVI properties
            claim.</para>
        </listitem>
        <listitem>
          <para>If an output of a compound step is connected to an output which includes PSVI
            properties, those properties <rfc2119>must</rfc2119> be preserved on the output of the
            compound step, <emphasis>except</emphasis> for the output of <tag>p:viewport</tag> which
              <rfc2119>must not</rfc2119> contain any PSVI properties.</para>
        </listitem>
        <listitem>
          <para>If an implementation supports XPath 2.0, the data model constructed with which to
            evaluate XPath expressions and match patterns <rfc2119>should</rfc2119> take advantage
            of as much PSVI information as possible. </para>
        </listitem>
        <listitem>
          <para>Except as specified above, or in the descriptions of individual steps,
            implementations <rfc2119>must not</rfc2119> include PSVI properties in the outputs of
            steps defined by this specification. <impl>It is
                <glossterm>implementation-defined</glossterm> what PSVI properties, if any, are
              produced by extension steps.</impl></para>
          <para>The exceptions in the standard XProc steps are the
              <tag>p:validate-with-xml-schema</tag>, <tag>p:validate-with-relax-ng</tag>, and
              <tag>p:validate-with-schematron</tag> steps, <tag>p:xslt</tag> (when XSLT 2.0 is
            used), <tag>p:xquery</tag>, <tag>p:identity</tag>, and <tag>p:split-sequence</tag>.
          </para>
        </listitem>
      </orderedlist>
      <note>
        <para>A processor that supports passing PSVI properties between steps is always free to do
          so. Even if <code>psvi-required="false"</code> is explicitly specified, it is not an error
          for a step to produce a result that includes additional PSVI properties, provide it does
          not violate the constraints above.</para>
      </note>
    </section>
    <section xml:id="variables">
      <title>Variables</title>
      <para>Variables are name/value pairs. Pipeline authors can create variables to hold computed
        values.</para>
      <para><termdef xml:id="dt-variable">A <firstterm>variable</firstterm> is a name/value pair
          where the name is an <link xlink:href="http://www.w3.org/TR/REC-xml-names/#dt-expname"
            >expanded name</link> and the value <rfc2119>must</rfc2119> be a string or
            <type>xs:untypedAtomic</type>.</termdef>
      </para>
      <para>Variables and options share the same scope and may shadow each other. </para>
    </section>
    <section xml:id="options">
      <title>Options</title>
      <para>Some steps accept options. Options are name/value pairs, like variables. Unlike
        variables, the value of an option can be changed by the caller.</para>
      <para><termdef xml:id="dt-option">An <firstterm>option</firstterm> is a name/value pair where
          the name is an <link xlink:href="http://www.w3.org/TR/REC-xml-names/#dt-expname">expanded
            name</link> and the value <rfc2119>must</rfc2119> be a string or
            <type>xs:untypedAtomic</type>.</termdef>
      </para>
      <para><termdef xml:id="dt-declared-options">The options declared on a step are its
            <firstterm>declared options</firstterm>.</termdef> Option names are always expressed as
        literal values, pipelines cannot construct option names dynamically. </para>
      <para><termdef xml:id="dt-specified-options">The options on a step which have specified
          values, either because a <tag>p:with-option</tag> element specifies a value or because the
          declaration included a default value, are its <firstterm>specified
          options</firstterm>.</termdef>
      </para>
      <para><impl>How outside values are specified for pipeline options on the pipeline initially
          invoked by the processor is <glossterm>implementation-defined</glossterm>.</impl> In other
        words, the command line options, APIs, or other mechanisms available to specify such options
        values are outside the scope of this specification.</para>
    </section>
    <section xml:id="parameters">
      <title>Parameters</title>
      <para>Some steps accept parameters. Parameters are name/value pairs, like variables and
        options. Unlike variables and options, which have names known in advance to the pipeline,
        parameters are not declared and their names may be unknown to the pipeline author. Pipelines
        can dynamically construct sets of parameters. Steps can read dynamically constructed sets on
          <glossterm baseform="parameter input port">parameter input ports</glossterm>. </para>
      <para><termdef xml:id="dt-parameter">A <firstterm>parameter</firstterm> is a name/value pair
          where the name is an <link xlink:href="http://www.w3.org/TR/REC-xml-names/#dt-expname"
            >expanded name</link> and the value <rfc2119>must</rfc2119> be a string or
            <type>xs:untypedAtomic</type>.</termdef>
      </para>
      <para><termdef xml:id="dt-parameter-input-port">A <firstterm>parameter input port</firstterm>
          is a distinguished kind of input port which accepts (only) dynamically constructed
          parameter name/value pairs.</termdef> See <xref linkend="parameter-inputs"/>.</para>
      <para>Analogous to <glossterm baseform="primary input port">primary input ports</glossterm>,
        steps that have parameter inputs may designate at most one parameter input port as a primary
        parameter input port.</para>
      <para><termdef xml:id="dt-primary-parameter-input-port">If a step has a parameter input port
          which is explicitly marked “<code>primary='true'</code>”, or if it has exactly one
          parameter input port and that port is <emphasis>not</emphasis> explicitly marked
            “<code>primary='false'</code>”, then that parameter input port is the <firstterm>primary
            parameter input port</firstterm> of the step.</termdef> If a step has a single parameter
        input port and that port is explicitly marked “<code>primary='false'</code>”, or if a step
        has more than one parameter input port and none is explicitly marked as the primary, then
        the primary parameter input port of that step is undefined.</para>
      <para><impl>How outside values are specified for pipeline parameters on the pipeline initially
          invoked by the processor is <glossterm>implementation-defined</glossterm>.</impl> In other
        words, the command line options, APIs, or other mechanisms available to specify such
        parameter values are outside the scope of this specification.</para>
    </section>
    <section xml:id="security-considerations">
      <title>Security Considerations</title>
      <para>An XProc pipeline may attempt to access arbitrary network resources: steps such as
          <tag>p:load</tag> and <tag>p:http-request</tag> can attempt to read from an arbitrary URI;
        steps such as <tag>p:store</tag> can attempt to write to an arbitrary location;
          <tag>p:exec</tag> can attempt to execute an arbitrary program. Note, also, that some
        steps, such as <tag>p:xslt</tag> and <tag>p:xquery</tag>, include extension mechanisms which
        may attempt to execute arbitrary code. </para>
      <para>In some environments, it may be inappropriate to provide the XProc pipeline with access
        to these resources. In a server environment, for example, it may be impractical to allow
        pipelines to store data. In environments where the pipeline cannot be trusted, allowing the
        pipeline to access arbitrary resources or execute arbitrary code may be a security
        risk.</para>
      <para><error code="D0021">It is a <glossterm>dynamic error</glossterm> for a pipeline to
          attempt to access a resource for which it has insufficient privileges or perform a step
          which is forbidden.</error>
        <impl>Which steps are forbidden, what privileges are needed to access resources, and under
          what circumstances these security constraints apply is
            <glossterm>implementation-dependent</glossterm>.</impl>
      </para>
      <para>Steps in a pipeline may call themselves recursively which could result in pipelines
        which will never terminate.</para>
      <para>A conformant XProc processor may limit the resources available to any or all steps in a
        pipeline. A conformant implementation may raise dynamic errors, or take any other corrective
        action, for any security problems that it detects.</para>
    </section>

<section xml:id="versioning-considerations">
<title>Versioning Considerations</title>

<para>A pipeline author <rfc2119>may</rfc2119> identify the version of XProc
for which a particular pipeline was authored by setting the
<tag class="attribute">version</tag> attribute. The
<tag class="attribute">version</tag> attribute can be specified on
<tag>p:declare-step</tag>, <tag>p:pipeline</tag>, or <tag>p:library</tag>.
If specified, the value of
the <tag class="attribute">version</tag> attribute <rfc2119>must</rfc2119> be a
<type>xs:decimal</type>. <error code="S0063">It is a
<glossterm>static error</glossterm> if the value of the
<tag class="attribute">version</tag> attribute is not a
<type>xs:decimal</type>.</error></para>

<para>The version of XProc defined
by this specification is “<literal>1.0</literal>”.</para>

<para>A pipeline author <rfc2119>must</rfc2119> identify the version of XProc
on the document element of a pipeline document.
<error code="S0062">It is a <glossterm>static error</glossterm> if a
required
<tag class="attribute">version</tag> attribute
is not present.</error></para>

<para>The version identified applies
to the element on which the
<tag class="attribute">version</tag> attribute appears and all of its descendants,
unless or until another version is explicitly identified.</para>

<para>When a processor encounters an explicit version (other than a
version which it implements), it proceeds in backwards- or
forwards-compatible mode. </para>

<section xml:id="vers-backcomp">
<title>Backwards-compatible Mode</title>
<para>If the processor encounters a request for a previous version of
XProc (e.g, if a "2.0" processor encounters an explicit request for
the "1.0" language), it <rfc2119>must</rfc2119> process the pipeline
as if it was a processor for the requested version: it
<rfc2119>must</rfc2119> enforce the semantics
of the requested version, it <rfc2119>must</rfc2119> report steps not
known in that version as errors, etc.
<error code="S0060">It
is a <glossterm>static error</glossterm> if the processor encounters
an explicit request for a previous version of the language and it is
unable to process the pipeline using those semantics.</error></para>
</section>

<section xml:id="vers-forwcomp">
<title>Forwards-compatible Mode</title>

<para>If the processor encounters an explicit version which it does
not recognize, it processes the pipeline in forwards-compatible mode.
Forwards-compatible mode relaxes several static errors, turning them
into dynamic errors so that a pipeline author can write a pipeline
which conditionally uses new language features.</para>

<para>In forwards-compatible mode:</para>
<orderedlist>
<listitem>
<para>On any element in the XProc namespace, unrecognized attributes
(other than extension attributes) are ignored.</para>
</listitem>
<listitem>
<para>On any step in the XProc namespace, unknown options are ignored.
</para>
</listitem>
<listitem>
<para>If a step in the XProc namespace includes an unknown input port
with an explicit connection, the connection is treated normally for
the purpose of computing the dependencies in the pipeline but it is
otherwise ignored. Unknown input ports <rfc2119>must not</rfc2119>
be treated as
<glossterm baseform="primary input port">primary input ports</glossterm>;
it will always be an error if they are used but not explicitly
connected.
</para>
</listitem>
<listitem>
<para>If a step in the pipeline includes an explicit connection to an
unknown output port on a step in the XProc namespace, the connection
is treated normally for the purpose of computing the dependencies in
the pipeline. An empty sequence of documents <rfc2119>must</rfc2119>
appear on that connection.
</para>
</listitem>
</orderedlist>

<para>As a consequence of the rules above, future specifications
<rfc2119>must not</rfc2119> change the semantics of existing step
types without changing their names. Although they may add new input
and output ports, such changes should be done with care; they
<rfc2119>should</rfc2119>
in some sense be limited to ancillary inputs and outputs and they
<rfc2119>must not</rfc2119> be
<glossterm baseform="primary input port">primary input ports</glossterm>.
</para>

<section xml:id="vers-forwcomp-ex">
<title>Examples</title>

<para>In forwards-compatible mode, it is not a static error to
encounter the following step:</para>

<programlisting><![CDATA[<p:string-replace match="div/@class" replace="newclass">
  <p:input port="ancillary">
    <p:document href="doc.xml"/>
  </p:input>
</p:string-replace>]]></programlisting>

<para>The processor will simply ignore the “<port>ancillary</port>” port.
</para>

          <para>Suppose that XProc version 2.0 changes the definition of the <tag>p:xslt</tag> step
            so that it has an additional output port, <code>messages</code>. Then consider the
            following pipeline: </para>
          <programlisting><![CDATA[<p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
            version="2.0">

  <p:xslt name="style">
    <p:input port="stylesheet">
      <p:document href="style.xsl"/>
    </p:input>
  </p:xslt>

  <p:sink/>

  <p:count>
    <p:input port="source">
      <p:pipe step="style" port="messages"/>
    </p:input>
  </p:count>
</p:pipeline>]]></programlisting>

<para>When run by a "2.0" or later processor, it will count the
documents that appear on the <code>messages</code> port. When run by a
“1.0” processor in forwards-compatible mode, the binding to the
“<port>messages</port>” port is not a static error.
Dynamically, the "1.0" processor will always produce
a count of zero, because an empty sequence of documents will always
appear on the <code>messages</code> port.</para>

        </section>
      </section>
    </section>
  </section>
  <section xml:id="syntax">
    <title>Syntax Overview</title>
    <para>This section describes the normative XML syntax of XProc. This syntax is sufficient to
      represent all the aspects of a pipeline, as set out in the preceding sections. <termdef
        xml:id="dt-XML">XProc is intended to work equally well with <biblioref linkend="xml10"/> and
          <biblioref linkend="xml11"/>. Unless otherwise noted, the term
        “<firstterm>XML</firstterm>” refers equally to both versions.</termdef>
      <termdef xml:id="dt-Namespaces-in-XML">Unless otherwise noted, the term <firstterm>Namespaces
          in XML</firstterm> refers equally to <biblioref linkend="xmlns10"/> and <biblioref
          linkend="xmlns11"/>.</termdef>
      <impl>Support for pipeline documents written in XML 1.1 and pipeline inputs and outputs that
        use XML 1.1 is <glossterm>implementation-defined</glossterm>.</impl>
    </para>
    <para>Elements in a pipeline document represent the pipeline, the steps it contains, the
      connections between those steps, the steps and connections contained within them, and so on.
      Each step is represented by an element; a combination of elements and attributes specify how
      the inputs and outputs of each step are connected and how options and parameters are
      passed.</para>
    <para>Conceptually, we can speak of steps as objects that have inputs and outputs, that are
      connected together and which may contain additional steps. Syntactically, we need a mechanism
      for specifying these relationships.</para>
    <para><glossterm baseform="container">Containment</glossterm> is represented naturally using
      nesting of XML elements. If a particular element identifies a <glossterm>compound
        step</glossterm> then the step elements that are its immediate children form its
        <glossterm>subpipeline</glossterm>.</para>
    <para>The connections between steps are expressed using names and references to those
      names.</para>
    <para>Six kinds of things are named in XProc:</para>
    <orderedlist spacing="compact">
      <listitem>
        <simpara>Step types,</simpara>
      </listitem>
      <listitem>
        <simpara>Steps,</simpara>
      </listitem>
      <listitem>
        <simpara>Input ports (both parameter and document),</simpara>
      </listitem>
      <listitem>
        <simpara>Output ports,</simpara>
      </listitem>
      <listitem>
        <simpara>Options and variables, and</simpara>
      </listitem>
      <listitem>
        <simpara>Parameters</simpara>
      </listitem>
    </orderedlist>
    <section xml:id="namespaces">
      <title>XProc Namespaces</title>
      <para>There are three namespaces associated with XProc:</para>
      <variablelist>
        <varlistentry>
          <term><uri type="xmlnamespace">http://www.w3.org/ns/xproc</uri></term>
          <listitem>
            <para>The namespace of the XProc XML vocabulary described by this specification; by
              convention, the namespace prefix “<literal>p:</literal>” is used for this
              namespace.</para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term><uri type="xmlnamespace">http://www.w3.org/ns/xproc-step</uri></term>
          <listitem>
            <para>The namespace used for documents that are inputs to and outputs from several
              standard and optional steps described in this specification. Some steps, such as
                <tag>p:http-request</tag> and <tag>p:store</tag>, have defined input or output
              vocabularies. We use this namespace for all of those documents. The conventional
              prefix “<literal>c:</literal>” is used for this namespace.</para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term><uri type="xmlnamespace">http://www.w3.org/ns/xproc-error</uri></term>
          <listitem>
            <para>The namespace used for errors. The conventional prefix “<literal>err:</literal>”
              is used for this namespace. </para>
          </listitem>
        </varlistentry>
      </variablelist>
      <para>This specification also makes use of the prefix “<literal>xs:</literal>” to refer to the
          <biblioref linkend="xmlschema-1"/> namespace <uri type="xmlnamespace"
          >http://www.w3.org/2001/XMLSchema</uri>. </para>
    </section>
    <section xml:id="scoping">
      <title>Scoping of Names</title>
      <para>Names are used to identify step types, steps, ports, options and variables, and
        parameters. Step types, options, variables, and parameters are named with QNames. Steps and
        ports are named with NCNames. The scope of a name is a measure of where it is available in a
        pipeline. <termdef xml:id="dt-visible">If two names are in the same scope, we say that they
          are <firstterm>visible</firstterm> to each other. </termdef></para>
      <para>The scope of the names of the step types is the pipeline in which they are declared,
        including any declarations imported from libraries via <tag>p:import</tag>. Nested pipelines
        inherit the step types in scope for their parent.</para>
      <para>In other words, the step types that are in scope in a <tag>p:pipeline</tag> or
          <tag>p:declare-step</tag> are:</para>
      <itemizedlist>
        <listitem>
          <para>The standard, built-in types (<tag>p:pipeline</tag>, <tag>p:choose</tag>, etc.).
          </para>
        </listitem>
        <listitem>
          <para>Any implementation-provided types. </para>
        </listitem>
        <listitem>
          <para>Any step types declared in the pipeline (the <tag>p:pipeline</tag> and
              <tag>p:declare-step</tag> children of the pipeline element). </para>
        </listitem>
        <listitem>
          <para>The types of any <tag>p:pipeline</tag>s or <tag>p:declare-step</tag>s that are
            imported. </para>
        </listitem>
        <listitem>
          <para>Any types that are in the scope of any <tag>p:library</tag> that is imported.
          </para>
        </listitem>
        <listitem>
          <para>Any step types that are in scope for the pipeline's parent <tag>p:pipeline</tag> or
              <tag>p:declare-step</tag>, if it has one. </para>
        </listitem>
        <listitem>
          <para>The type of the pipeline itself, if it has one. </para>
        </listitem>
      </itemizedlist>
      <para>The step types that are in scope in a <tag>p:library</tag> are:</para>
      <itemizedlist>
        <listitem>
          <para>The standard, built-in types (<tag>p:pipeline</tag>, <tag>p:choose</tag>, etc.).
          </para>
        </listitem>
        <listitem>
          <para>Any implementation-provided types. </para>
        </listitem>
        <listitem>
          <para>Any step types declared in the library (the <tag>p:pipeline</tag> and
              <tag>p:declare-step</tag> children of the <tag>p:library</tag> element). </para>
        </listitem>
        <listitem>
          <para>The types of <tag>p:pipeline</tag>s or <tag>p:declare-step</tag>s that are imported
            into the library. </para>
        </listitem>
        <listitem>
          <para>Any types that are in the scope of any <tag>p:library</tag> that is imported.
          </para>
        </listitem>
      </itemizedlist>
      <para><error code="S0036">All the step types in a pipeline or library <rfc2119>must</rfc2119>
          have unique names: it is a <glossterm>static error</glossterm> if any step type name is
          built-in and/or declared or defined more than once in the same scope.</error></para>

<para>The scope of the names of the steps themselves is determined by
the <glossterm>environment</glossterm> of each step. In general, the
name of a step, the names of its sibling steps, the names of any steps
that it contains directly, the names of its ancestors, and the names
of the siblings of its ancestors are all in a common scope. <error
code="S0002">All steps in the same scope <rfc2119>must</rfc2119> have
unique names: it is a <glossterm>static error</glossterm> if two steps
with the same name appear in the same scope.</error></para>

<para>The scope of an input or output port name is the step on which
it is defined. The names of all the ports on any step
<rfc2119>must</rfc2119> be unique.</para>

<para>Taken together, these uniqueness constraints guarantee that the
combination of a step name and a port name uniquely identifies exactly
one port on exactly one in-scope step.</para>

<para>The scope of option and variable names is determined by where
they are declared. When an option is declared with <tag>p:option</tag>
(or a variable with <tag>p:variable</tag>), unless otherwise
specified, its scope consists of the sibling elements that follow its
declaration and the descendants of those siblings.
<error code="S0004">It is a <glossterm>static error</glossterm> if
an option or variable declaration duplicates the name of any other
option or variable in the same <glossterm>environment</glossterm>.</error>
That is, no option or variable may lexically shadow another option or
variable with the same name.
</para>

<para>Parameter names are not scoped; they are distinct on each step.</para>
</section>
    <section xml:id="xml-base-attribute">
      <title>Base URIs and xml:base</title>
      <para>When a relative URI appears in an option value, the base URI against which it
          <rfc2119>must</rfc2119> be made absolute is the base URI of the <tag>p:option</tag>
        element. If an option value is specified using a <link linkend="option-shortcut">syntactic
          shortcut</link>, the base URI of the step on which the shortcut attribute appears
          <rfc2119>must</rfc2119> be used. In general, whenever a relative URI appears, its base URI
        is the base URI of the nearest ancestor element.</para>
      <para>The pipeline author can control the base URIs of elements within the pipeline document
        with the <tag class="attribute">xml:base</tag> attribute. The <tag class="attribute"
          >xml:base</tag> attribute <rfc2119>may</rfc2119> appear on any element in a pipeline and
        has the semantics outlined in <biblioref linkend="xml-base"/>.</para>
    </section>
    <section xml:id="xml-id-attribute">
      <title>Unique identifiers</title>
      <para>A pipeline author can provide a globally unique identifier for any element in a pipeline
        with the <tag class="attribute">xml:id</tag> attribute.</para>
      <para>The <tag class="attribute">xml:id</tag> attribute <rfc2119>may</rfc2119> appear on any
        element in a pipeline and has the semantics outlined in <biblioref linkend="xml-id"
        />.</para>
    </section>
    <section xml:id="syntax-docs-ports">
      <title>Associating Documents with Ports</title>
      <para><termdef xml:id="dt-connection">A <firstterm>connection</firstterm> associates an input
          or output port with some data source.</termdef> A document or a sequence of documents can
        be connected to a port in four ways: <glossterm>by source</glossterm>, <glossterm>by
          URI</glossterm>, by providing an <glossterm>inline document</glossterm>, or by making it
          <glossterm baseform="empty-sequence">explicitly empty</glossterm>. Each of these
        mechanisms is allowed on the <tag>p:input</tag>, <tag>p:output</tag>,
          <tag>p:xpath-context</tag>, <tag>p:iteration-source</tag>, and
          <tag>p:viewport-source</tag> elements.</para>
      <variablelist>
        <varlistentry>
          <term>Specified by URI</term>
          <listitem>
            <para><termdef xml:id="dt-by-URI">A document is specified <firstterm>by URI</firstterm>
                if it is referenced with a URI.</termdef> The <tag class="attribute">href</tag>
              attribute on the <tag>p:document</tag> or <tag>p:data</tag> element is used to refer
              to documents by URI.</para>
            <para>In this example, the input to the <tag>p:identity</tag> step named
                “<literal>otherstep</literal>” comes from “<uri>http://example.com/input.xml</uri>”. </para>
            <programlisting><xi:include href="examples/identity.txt" parse="text"/></programlisting>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>Specified by source</term>
          <listitem>
            <para><termdef xml:id="dt-by-source">A document is specified <firstterm>by
                  source</firstterm> if it references a specific port on another step.</termdef> The
                <tag class="attribute">step</tag> and <tag class="attribute">port</tag> attributes
              on the <tag>p:pipe</tag> element are used for this purpose. </para>
            <para>In this example, the “<literal>source</literal>” input to the
                <tag>p:xinclude</tag> step named “<literal>expand</literal>” comes from the
                “<literal>result</literal>” port of the step named
              “<literal>otherstep</literal>”.</para>
            <programlisting><xi:include href="examples/xinclude.txt" parse="text"/></programlisting>
            <para>See the description of <tag>p:pipe</tag> for a complete description of the ports
              that can be connected.</para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>Specified inline</term>
          <listitem>
            <para><termdef xml:id="dt-inline-document">An <firstterm>inline document</firstterm> is
                specified directly in the body of the element to which it connects.</termdef> The
              content of the <tag>p:inline</tag> element is used for this purpose. </para>
            <para>In this example, the “<literal>stylesheet</literal>” input to the XSLT step named
                “<literal>xform</literal>” comes from the content of the <tag>p:input</tag> element
              itself.</para>
            <programlisting><xi:include href="examples/xslt.txt" parse="text"/></programlisting>
            <para>Inline documents are considered “quoted”. The pipeline processor passes them
              literally to the port, even if they contain elements from the XProc namespace or other
              namespaces that would have other semantics outside of the <tag>p:inline</tag>.</para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>Specified explicitly empty</term>
          <listitem>
            <para><termdef xml:id="dt-empty-sequence">An <firstterm>empty sequence</firstterm> of
                documents is specified with the <tag>p:empty</tag> element.</termdef>
            </para>
            <para>In this example, the “<literal>source</literal>” input to the XSLT 2.0 step named
                “<literal>generate</literal>” is explicitly empty:</para>
            <programlisting><xi:include href="examples/xslt-empty.txt" parse="text"/></programlisting>
            <para>If you omit the connection on a primary input port, a connection to the
                <glossterm>default readable port</glossterm> will be assumed. Making the connection
              explicitly empty guarantees that the connection will be to an empty sequence of
              documents.</para>
            <para xml:id="empty-xpath-context">It is inconsistent with the <biblioref
                linkend="xpath"/> specification to specify an empty connection as the context for
              evaluating an XPath expression. When an empty connection is specified for an XPath 1.0
              expression, an empty document node <rfc2119>must</rfc2119> be used instead as the
              context node.</para>
          </listitem>
        </varlistentry>
      </variablelist>
      <para>Note that a <tag>p:input</tag> or <tag>p:output</tag> element may contain more than one
          <tag>p:pipe</tag>, <tag>p:document</tag>, <tag>p:data</tag>, or <tag>p:inline</tag>
        element. If more than one <glossterm>connection</glossterm> is provided, then the specified
        sequence of documents is made available on that port in the same order as the
        connections.</para>
    </section>
    <section xml:id="documentation">
      <title>Documentation</title>
      <para>Pipeline authors may add documentation to their pipeline documents with the
          <tag>p:documentation</tag> element. Except when it appears as a descendant of
          <tag>p:inline</tag>, the <tag>p:documentation</tag> element is completely ignored by
        pipeline processors, it exists simply for documentation purposes. If a
          <tag>p:documentation</tag> is provided as a descendant of <tag>p:inline</tag>, it has no
        special semantics, it is treated literally as part of the document to be provided on that
        port. The <tag>p:documentation</tag> element has no special semantics when it appears in
        documents that flow through the pipeline.</para>
      <para>Pipeline processors that inspect the contents of <tag>p:documentation</tag> elements and
        behave differently on the basis of what they find are <emphasis>not conformant</emphasis>.
        Processor extensions <rfc2119>must</rfc2119> be specified with <tag>p:pipeinfo</tag>.</para>
    </section>
    <section xml:id="annotations">
      <title>Processor annotations</title>
      <para>Pipeline authors may add annotations to their pipeline documents with the
          <tag>p:pipeinfo</tag> element. <impl>The semantics of <tag>p:pipeinfo</tag> elements are
            <glossterm>implementation-defined</glossterm>.</impl> Processors
          <rfc2119>should</rfc2119> specify a way for their annotations to be identified, perhaps
        with <link linkend="extension-attributes">extension attributes</link>.</para>
      <para>Where <tag>p:documentation</tag> is intended for human consumption,
          <tag>p:pipeinfo</tag> elements are intended for processor consumption. A processor might,
        for example, use annotations to identify some particular aspect of an implementation, to
        request additional, perhaps non-standard features, to describe parallelism constraints,
        etc.</para>
      <para>When a <tag>p:pipeinfo</tag> appears as a descendant of <tag>p:inline</tag>, it has no
        special semantics; in that context it <rfc2119>must</rfc2119> be treated literally as part
        of the document to be provided on that port. The <tag>p:pipeinfo</tag> element has no
        special semantics when it appears in documents that flow through the pipeline. </para>
    </section>
    <section xml:id="extension-attributes">
      <title>Extension attributes</title>
      <para><termdef xml:id="dt-extension-attribute">An element from the XProc namespace
            <rfc2119>may</rfc2119> have any attribute not from the XProc namespace, provided that
          the expanded-QName of the attribute has a non-null namespace URI. Such an attribute is
          called an <firstterm>extension attribute</firstterm>.</termdef>
      </para>
      <para>The presence of an extension attribute must not cause the connections between steps to
        differ from the connections that would arise in the absence of the attribute. They must not
        cause the processor to fail to signal an error that would be signaled in the absence of the
        attribute.</para>
      <para>A processor which encounters an extension attribute that it does not implement
          <rfc2119>must</rfc2119> behave as if the attribute was not present.</para>
    </section>

<section xml:id="use-when">
<title>Conditional Element Exclusion</title>

<para>Any element in the XProc namespace may have a
<tag class="attribute">use-when</tag> attribute which
<rfc2119>must</rfc2119> contain an XPath expression that can be
evaluated statically. If the attribute is present and the effective boolean
value of the expression is false, then the element and all of its descendants
are effectively excluded from the pipeline document. If a node is effectively
excluded, the processor <rfc2119>must</rfc2119> behave as if the element
was not present in the document.</para>

<para>Elements that are not in the XProc namespace <rfc2119>may</rfc2119> also
have a <tag class="attribute">use-when</tag> attribute, but the attribute must
be in the XProc namespace. The semantics of a
<tag class="attribute">p:use-when</tag> attribute
on an element not in the XProc namespace are the same as the semantics of a
<tag class="attribute">use-when</tag> attribute on an element in the XProc
namespace.</para>

<para>Conditional element exclusion occurs before any static analysis
of the pipeline.</para>

<note><para>The effective exclusion of <tag class="attribute">use-when</tag>
processing occurs after XML parsing and has no effect on well-formedness
or validation errors which will be reported in the usual way. Note also that
<tag class="attribute">use-when</tag> is not performed when it occurs on the
descendant of a <tag>p:inline</tag> element.</para>
</note>

<para>For the purposes of evaluating a <tag class="attribute">use-when</tag>
expression, the context node, position, and size are all undefined. No
<glossterm>in-scope bindings</glossterm> are available. There are no
readable ports. There are no available documents or available collections.
</para>

<para>There are some additional restrictions on the XPath extension functions
that are available in a <tag class="attribute">use-when</tag>
expression:</para>

<itemizedlist>
<listitem>
<para>The <literal>p:episode</literal> system property
<rfc2119>should not</rfc2119> be used. <impl>The value of
the <literal>p:episode</literal> system property in a
<tag class="attribute">use-when</tag> expression is
<glossterm>implementation-dependent</glossterm>.</impl></para>
</listitem>
<listitem>
<para>The <function>p:step-available</function> function cannot be used
to test for the availability of extension steps (because the libraries
that declare them may not have been imported). <impl>The results of testing
for steps not in the XProc namespace in a
<tag class="attribute">use-when</tag> expression are
<glossterm>implementation-dependent</glossterm>.</impl></para>
</listitem>
<listitem>
<para>The steps available and possibly other aspects of the expression may
depend on the version specified for a pipeline, see
<xref linkend="versioning-considerations"/>. For example, in a “1.0” pipeline,
the processor <rfc2119>should not</rfc2119> report that “2.0” steps are
available.</para>
</listitem>
</itemizedlist>

<para><error code="S0061">It is a <glossterm>static error</glossterm> if a
<tag class="attribute">use-when</tag>
expression refers to the context or attempts to refer to any documents
or collections.</error>
</para>
</section>

    <section xml:id="syntax-summaries"><title>Syntax Summaries</title><para>The description of each
        element in the pipeline namespace is accompanied by a syntactic summary that provides a
        quick overview of the element's syntax:</para>
      <e:rng-fragment name="SomeElement" role="nosummary">
        <grammar xmlns="http://relaxng.org/ns/structure/1.0">
          <define xmlns:sa="http://xproc.org/ns/syntax-annotations" name="SomeElement"
            sa:class="language-example">
            <element name="some-element">
              <optional>
                <attribute name="some-attribute">
                  <data type="some-type"/>
                </attribute>
              </optional>
              <zeroOrMore>
                <choice>
                  <ref name="Some"/>
                  <ref name="Elements"/>
                  <ref name="Allowed"/>
                </choice>
              </zeroOrMore>
              <optional>
                <ref name="OtherElements"/>
              </optional>
            </element>
          </define>
          <define name="Some"><element name="some"><empty/></element></define>
          <define name="Elements"><element name="elements"><empty/></element></define>
          <define name="Allowed"><element name="allowed"><empty/></element></define>
          <define name="OtherElements"><element name="other-elements"><empty/></element></define>
        </grammar>
      </e:rng-fragment>
      <para>The content model fragments in these tableaux are presented in a simple, compact
        notation. In brief:</para><itemizedlist>
        <listitem>
          <para>A name represent exactly one occurrence of an element with that name.</para>
        </listitem>
        <listitem>
          <para>Parentheses are used for grouping. </para>
        </listitem>
        <listitem>
          <para>Elements or groups separated by a comma (“,”) represent an ordered sequence: a
            followed by b followed by c: (a,b,c).</para>
        </listitem>
        <listitem>
          <para>Elements or groups separated by a vertical bar (“|”) represent a choice: a or b or
            c: (a | b | c).</para>
        </listitem>
        <listitem>
          <para>Elements or groups separated by an ampersand (“&amp;”) represent an unordered
            sequence: a and b and c, in any order: (a &amp; b &amp; c).</para>
        </listitem>
        <listitem>
          <para>An element or group followed by a question mark (“?”) is optional; it may or may not
            occur but if it occurs it can occur only once.</para>
        </listitem>
        <listitem>
          <para>An element or group followed by an asterisk (“*”) is optional and may be repeated;
            it may or may not occur and if it occurs it can occur any number of times. </para>
        </listitem>
        <listitem>
          <para>An element or group followed by a plus (“+”) is required and may be repeated; it
            must occur at least once, and it can occur any number of times. </para>
        </listitem>
      </itemizedlist><para>For clarity of exposition, some attributes and elements are elided from
        the summaries:</para><itemizedlist>
        <listitem>
          <para>An <tag class="attribute">xml:id</tag> attribute is allowed on any element. It has
            the semantics of <biblioref linkend="xml-id"/>.</para>
        </listitem>
        <listitem>
          <para>An <tag class="attribute">xml:base</tag> attribute is allowed on any element. It has
            the semantics of <biblioref linkend="xml-base"/>.</para>
        </listitem>
        <listitem>
          <para>A <tag class="attribute">use-when</tag> attribute is allowed on any element, see <xref linkend="use-when"/>.</para>
        </listitem>
        <listitem>
          <para>The <tag>p:documentation</tag> and <tag>p:pipeinfo</tag> elements are not shown, but
            they are allowed anywhere.</para>
        </listitem>
        <listitem>
          <para>The <tag>p:log</tag> element is allowed on any step that has a
            <tag>p:output</tag>.</para>
        </listitem>
        <listitem>
          <para>Attributes that are <link linkend="option-shortcut">syntactic shortcuts for option
              values</link> are not shown.</para>
        </listitem>
      </itemizedlist><para>The types given for attributes should be understood as follows:</para><itemizedlist>
        <listitem>
          <para><type>ID</type>, <type>NCName</type>, <type>NMTOKEN</type>, <type>NMTOKENS</type>,
              <type>anyURI</type>, <type>boolean</type>, <type>integer</type>, <type>string</type>:
            As per <biblioref linkend="xmlschema-2"/> including whitespace normalization as
            appropriate.</para>
        </listitem>
        <listitem>
          <para><type>QName</type>: With whitespace normalization as per <biblioref
              linkend="xmlschema-2"/> and according to the following definition: In the context of
            XProc, a <type>QName</type> is almost always a QName in the <glossterm>Namespaces in
              XML</glossterm> sense. Note, however, that <tag>p:option</tag> and
              <tag>p:with-param</tag> values can get their namespace declarations in a non-standard
            way (with <tag>p:namespaces</tag>) and QNames that have no prefix are always in
            no-namespace, irrespective of the default namespace. </para>
        </listitem>
        <listitem>
          <para><type>PrefixList</type>: As a list with <literal role="infoset-property">item
              type</literal>
            <type>NMTOKEN</type>, per <biblioref linkend="xmlschema-2"/>, including whitespace
            normalization. </para>
        </listitem>
        <listitem>
          <para><type>XPathExpression</type>, <type>XSLTMatchPattern</type>: As a string per
              <biblioref linkend="xmlschema-2"/>, including whitespace normalization, and the
            further requirement to be a conformant Expression per <biblioref linkend="xpath"/> or
              <biblioref linkend="xpath2"/>, as appropriate, or Match pattern per <biblioref
              linkend="xslt10"/> or <biblioref linkend="xslt20"/>, as appropriate. </para>
        </listitem>
      </itemizedlist></section>
    <section xml:id="common-errors">
      <title>Common errors</title>
      <para>A number of errors apply generally:</para>
      <itemizedlist>
        <listitem>
          <para><error code="S0059">It is a <glossterm>static error</glossterm> if the pipeline
              element is not <tag>p:pipeline</tag>, <tag>p:declare-step</tag>, or
                <tag>p:library</tag>.</error>
          </para>
        </listitem>
        <listitem>
          <para><error code="S0008">It is a <glossterm>static error</glossterm> if any element in
              the XProc namespace has attributes not defined by this specification unless they are
                <glossterm baseform="extension
attribute">extension attributes</glossterm>.</error>
          </para>
        </listitem>
        <listitem>
          <para><error code="S0038">It is a <glossterm>static error</glossterm> if any required
              attribute is not provided.</error>
          </para>
        </listitem>
        <listitem>
          <para><error code="D0028">It is a <glossterm>dynamic error</glossterm> if any attribute
              value does not satisfy the type required for that attribute.</error></para>
        </listitem>
        <listitem>
          <para><error code="S0044">It is a <glossterm>static error</glossterm> if any element in
              the XProc namespace or any step has element children other than those specified for it
              by this specification. In particular, the presence of atomic steps for which there is
              no visible declaration may raise this error. </error></para>
        </listitem>
        <listitem>
          <para><error code="S0037">It is a <glossterm>static error</glossterm> if any step directly
              contains text nodes that do not consist entirely of whitespace.</error>
          </para>
        </listitem>
        <listitem>
          <para><error code="D0019">It is a <glossterm>dynamic error</glossterm> if any option value
              does not satisfy the type required for that option.</error>
          </para>
        </listitem>
        <listitem>
          <para><error code="S0015">It is a <glossterm>static error</glossterm> if a compound step
              has no <glossterm>contained steps</glossterm>.</error>
          </para>
        </listitem>
        <listitem>
          <para><error code="D0012">It is a <glossterm>dynamic error</glossterm> if any attempt is
              made to dereference a URI where the scheme of the URI reference is not
              supported.</error> Implementations are encouraged to support as many schemes as is
            practical and, in particular, they <rfc2119>should</rfc2119> support both the
              <literal>file:</literal> and <literal>http(s):</literal> schemes. <impl>The set of URI
              schemes actually supported is <glossterm>implementation-defined</glossterm>.</impl>
          </para>
        </listitem>
        <listitem>
          <para><error code="D0030">It is a <glossterm>dynamic error</glossterm> if a step is unable
              or incapable of performing its function.</error> This is a general error code for
            “step failed” (e.g., if the input isn't of the expected type or if attempting to process
            the input causes the implementation to abort). Users and implementors who create
            extension steps are encouraged to use this code for general failures.</para>
        </listitem>
        <listitem>
          <para>In most steps which use a select expression or match pattern, any kind of node can
            be identified by the expression or pattern. However, some expressions and patterns on
            some steps are only applicable to some kinds of nodes (e.g., it doesn't make sense to
            speak of adding attributes to a comment!). </para>
          <para><error code="C0023">It is a <glossterm>dynamic error</glossterm> if a select
              expression or match pattern returns a node type that is not allowed by the
              step.</error>
          </para>
        </listitem>
      </itemizedlist>
      <para>If an XProc processor can determine statically that a dynamic error will
          <emphasis>always</emphasis> occur, it <rfc2119>may</rfc2119> report that error statically
        provided that the error <emphasis>does not</emphasis> occur among the descendants of a
          <tag>p:try</tag>. Dynamic errors inside a <tag>p:try</tag>
        <rfc2119>must not</rfc2119> be reported statically. They must be raised dynamically so that
          <tag>p:catch</tag> processing can be performed on them. </para>
    </section>
  </section>
  <section xml:id="steps">
    <title>Steps</title>
    <para>This section describes the core steps of XProc.</para>
    <para>Several of the steps defined in this specification refer to other, evolving XML
      technologies (XSLT, XQuery, XSL-FO, etc.). Where this specification identifies a specific
      version of a technology, implementors <rfc2119>must</rfc2119> implement the specified version
      or any subsequent edition or version that is backwards compatible. At user option, they may
      support other, incompatible versions or extensions.</para>
    <section xml:id="p.pipeline"><title>p:pipeline</title><para>A <tag>p:pipeline</tag> declares a
        pipeline that can be evaluated by an XProc processor. It encapsulates the behavior of a
          <glossterm>subpipeline</glossterm>. Its children declare inputs, outputs, and options that
        the pipeline exposes and identify the steps in its subpipeline. (A <tag>p:pipeline</tag> is
        a simplified form of <link linkend="p.declare-step">step declaration</link>.)
        </para>
<para>All <tag>p:pipeline</tag> pipelines have an implicit <glossterm>primary input
          port</glossterm> named “<port>source</port>”, an implicit <glossterm>primary parameter
          input port</glossterm> named “<port>parameters</port>”, and an implicit <glossterm>primary
          output port</glossterm> named “<port>result</port>”. Any input or output ports that the
          <tag>p:pipeline</tag> declares explicitly are <emphasis>in addition</emphasis> to those
        ports and may not be declared primary.</para>
      <e:rng-pattern name="Pipeline"/>
      <para>Viewed from the outside, a <tag>p:pipeline</tag> is a black box which performs some
        calculation on its inputs and produces its outputs. From the pipeline author's perspective,
        the computation performed by the pipeline is described in terms of <glossterm>contained
          steps</glossterm> which read the pipeline's inputs and produce the pipeline's
        outputs.</para>

<para>The <tag class="attribute">version</tag> attribute identifies the version
of XProc for which this pipeline was authored. If the <tag>p:pipeline</tag>
has no ancestors in the XProc namespace, then it <rfc2119>must</rfc2119>
have a <tag class="attribute">version</tag> attribute. 
See <xref linkend="versioning-considerations"/>.</para>

<para>If a pipeline does not have a <tag class="attribute">type</tag>
then that pipeline cannot be invoked as a step.</para>

<para>The <tag>p:pipeline</tag> element is
        just a simplified form of step declaration. A document that
        reads:</para><programlisting>&lt;p:pipeline <replaceable>some-attributes</replaceable>&gt;
  <replaceable>some-content</replaceable>
&lt;/p:pipeline&gt;</programlisting><para>can
        be interpreted as if it
        read:</para><programlisting>&lt;p:declare-step <replaceable>some-attributes</replaceable>&gt;
  &lt;p:input port='source' primary='true'/&gt;
  &lt;p:input port='parameters' kind='parameter' primary='true'/&gt;
  &lt;p:output port='result' primary='true'/&gt;
  <replaceable>some-content</replaceable>
&lt;/p:declare-step&gt;</programlisting><para>See
          <tag>p:declare-step</tag> for more details.</para><section xml:id="example-pipeline"
        role="tocsuppress">
        <title>Example</title>
        <para>A pipeline might accept a document as input; perform XInclude, validation, and
          transformation; and produce the transformed document as its output.</para>
        <example xml:id="ex.p.pipeline">
          <title>A Sample Pipeline Document</title>
          <programlisting><xi:include href="examples/pipeline.txt" parse="text"/></programlisting>
        </example>
      </section></section>
    <section xml:id="p.for-each"><title>p:for-each</title><para>A for-each is specified by the
          <tag>p:for-each</tag> element. It is a <glossterm>compound step</glossterm> that processes
        a sequence of documents, applying its <glossterm>subpipeline</glossterm> to each document in
        turn.</para>
      <e:rng-pattern name="ForEach"/>
      <para>When a pipeline needs to process a sequence of documents using a subpipeline that only
        processes a single document, the <tag>p:for-each</tag> construct can be used as a wrapper
        around that subpipeline. The <tag>p:for-each</tag> will apply that subpipeline to each
        document in the sequence in turn.</para>
<para>The result of the <tag>p:for-each</tag> is a
        sequence of documents produced by processing each individual document in the input sequence.
        If the <tag>p:for-each</tag> has one or more output ports, what appears on each of those
        ports is the sequence of documents that is the concatenation of the sequence produced by
        each iteration of the loop on the port to which it is connected. If the iteration source for
        a <tag>p:for-each</tag> is an empty sequence, then the subpipeline is never run and an empty
        sequence is produced on all of the outputs. </para>
<para>The <tag>p:iteration-source</tag>
        is an anonymous input: its <glossterm>connection</glossterm> provides a sequence of
        documents to the <tag>p:for-each</tag> step. If no iteration sequence is explicitly
        provided, then the iteration source is read from the <glossterm>default readable
          port</glossterm>.</para>
<para>The processor provides each document, one at a time, to the
          <glossterm>subpipeline</glossterm> represented by the children of the
          <tag>p:for-each</tag> on a port named <port>current</port>.</para>
<para>For each declared
        output, the processor collects all the documents that are produced for that output from all
        the iterations, in order, into a sequence. The result of the <tag>p:for-each</tag> on that
        output is that sequence of documents.</para>
      <!--
<para>The <glossterm>environment</glossterm> of a <tag>p:for-each</tag> is its
inherited environment
with the <link linkend="dt-standard-modifications">standard modifications</link>.</para>
-->
      <para>The environment inherited by the <glossterm>contained steps</glossterm> of a
          <tag>p:for-each</tag> is the <glossterm>inherited environment</glossterm> with these
        modifications:</para><itemizedlist>
        <listitem>
          <para>The port named “<port>current</port>” on the <tag>p:for-each</tag> is added to the
              <glossterm>readable ports</glossterm>.</para>
        </listitem>
        <listitem>
          <para>The port named “<port>current</port>” on the <tag>p:for-each</tag> is made the
              <glossterm>default readable port</glossterm>.</para>
        </listitem>
      </itemizedlist><para>If the <tag>p:for-each</tag> has a <glossterm>primary output
          port</glossterm> (explicit or <link linkend="primary-input-output">supplied by
          default</link>) and that port has no <glossterm>connection</glossterm>, then it is
        connected to the <glossterm>primary output port</glossterm> of the <glossterm>last
          step</glossterm> in the <glossterm>subpipeline</glossterm>. <error code="S0006">It is a
            <glossterm>static error</glossterm> if the primary output port has no explicit
          connection and the <glossterm>last step</glossterm> in the subpipeline does not have a
          primary output port.</error></para>
<para>Note that outputs declared for a
          <tag>p:for-each</tag> serve a dual role. Inside the <tag>p:for-each</tag>, they are used
        to read results from the subpipeline. Outside the <tag>p:for-each</tag>, they provide the
        aggregated results.</para>
<para>The <tag class="attribute">sequence</tag> attribute on a
          <tag>p:output</tag> inside a <tag>p:for-each</tag> only applies inside the step. From the
        outside, all of the outputs produce sequences.</para><section
        xml:id="for-each-xpath-context">
        <title>XPath Context</title>
        <para>Within a <tag>p:for-each</tag>, the <function>p:iteration-position</function> and
            <function>p:iteration-size</function> are taken from the sequence of documents that will
          be processed by the <tag>p:for-each</tag>. The total number of documents is the
            <function>p:iteration-size</function>; the ordinal value of the current document (the
          document appearing on the <port>current</port> port) is the
            <function>p:iteration-position</function>.</para>
        <note xml:id="impl1">
          <title>Note to implementers</title>
          <para>In the case where no XPath expression that must be evaluated by the processor makes
            any reference to <function>p:iteration-size</function>, its value does not actually have
            to be calculated (and the entire input sequence does not, therefore, need to be buffered
            so that its size can be calculated before processing begins).</para>
        </note>
      </section><section xml:id="example-for-each" role="tocsuppress">
        <title>Example</title>
        <para>A <tag>p:for-each</tag> might accept a sequence of chapters as its input, process each
          chapter in turn with XSLT, a step that accepts only a single input document, and produce a
          sequence of formatted chapters as its output.</para>
        <example xml:id="ex.p.for-each">
          <title>A Sample For-Each</title>
          <programlisting><xi:include href="examples/for-each.txt" parse="text"/></programlisting>
        </example>
        <para>The <code>//chapter</code> elements of the document are selected. Each chapter is
          transformed into HTML and XSL Formatting Objects using an XSLT step. The resulting HTML
          and FO documents are aggregated together and appear on the <literal>html-results</literal>
          and <literal>fo-results</literal> ports, respectively, of the <literal>chapters</literal>
          step itself.</para>
      </section></section>
    <section xml:id="p.viewport"><title>p:viewport</title><para>A viewport is specified by the
          <tag>p:viewport</tag> element. It is a <glossterm>compound step</glossterm> that processes
        a single document, applying its <glossterm>subpipeline</glossterm> to one or more subtrees
        of the document. </para>
      <e:rng-pattern name="Viewport"/>
      <para>The result of the <tag>p:viewport</tag> is a copy of the original document where the
        selected subtrees have been replaced by the results of applying the subpipeline to
        them.</para>
<para>The <tag>p:viewport-source</tag> is an anonymous input: its
          <glossterm>connection</glossterm> provides a single document to the <tag>p:viewport</tag>
        step. If no document is explicitly provided, then the viewport source is read from the
          <glossterm>default readable port</glossterm>. <error code="D0003">It is a
            <glossterm>dynamic error</glossterm> if the viewport source does not provide exactly one
          document. </error></para>
<para>The <tag class="attribute">match</tag> attribute specifies
        an XSLT match pattern. Each matching node in the source document is wrapped in a document
        node, as necessary, and provided, one at a time, to the viewport's
          <glossterm>subpipeline</glossterm> on a port named <port>current</port>. The base URI of
        the resulting document that is passed to the subpipeline is the base URI of the matched
        element or document. <error code="D0010">It is a <glossterm>dynamic error</glossterm> if the
            <tag class="attribute">match</tag> expression on <tag>p:viewport</tag> does not match an
          element or document.</error>
      </para>
<para>After a match is found, the entire subtree rooted at that match is processed as a
        unit. No further attempts are made to match nodes among the descendants of any matched
        node.</para>
<para>The environment inherited by the <glossterm>contained steps</glossterm> of
        a <tag>p:viewport</tag> is the <glossterm>inherited environment</glossterm> with these
        modifications:</para><itemizedlist>
        <listitem>
          <para>The port named “<port>current</port>” on the <tag>p:viewport</tag> is added to the
              <glossterm>readable ports</glossterm>.</para>
        </listitem>
        <listitem>
          <para>The port named “<port>current</port>” on the <tag>p:viewport</tag> is made the
              <glossterm>default readable port</glossterm>.</para>
        </listitem>
      </itemizedlist><para>The <tag>p:viewport</tag> must contain a single, <glossterm>primary
          output port</glossterm> declared explicitly or <link linkend="primary-input-output"
          >supplied by default</link>. If that port has no <glossterm>connection</glossterm>, then
        it is connected to the <glossterm>primary output port</glossterm> of the <glossterm>last
          step</glossterm> in the <glossterm>subpipeline</glossterm>. <error code="S0006">It is a
            <glossterm>static error</glossterm> if the primary output port is unconnected and the
            <glossterm>last step</glossterm> in the subpipeline does not have a primary output
          port.</error></para>
<para>What appears on the output from the <tag>p:viewport</tag> will
        be a copy of the input document where each matching node is replaced by the result of
        applying the subpipeline to the subtree rooted at that node. In other words, if the match
        pattern matches a particular element then that element is wrapped in a document node and
        provided on the <port>current</port> port, the subpipeline in the <tag>p:viewport</tag> is
        evaluated, and the result that appears on the <port>output</port> port replaces the matched
        element. </para>
<para>If no documents appear on the <port>output</port> port, the matched
        element will effectively be deleted. If exactly one document appears, the contents of that
        document will replace the matched element. If a sequence of documents appears, then the
        contents of each document in that sequence (in the order it appears in the sequence) will
        replace the matched element.</para>
<para>The output of the <tag>p:viewport</tag> itself is a
        single document that appears on a port named “<literal>result</literal>”. Note that the
        semantics of <tag>p:viewport</tag> are special. The <port>output</port> port in the
          <tag>p:viewport</tag> is used only to access the results of the subpipeline. The output of
        the step itself appears on a port with the fixed name “<literal>result</literal>” that is
        never explicitly declared.</para><section xml:id="viewport-xpath-context">
        <title>XPath Context</title>
        <para>Within a <tag>p:viewport</tag>, the <function>p:iteration-position</function> and
            <function>p:iteration-size</function> are taken from the sequence of documents that will
          be processed by the <tag>p:viewport</tag>. The total number of documents is the
            <function>p:iteration-size</function>; the ordinal value of the current document (the
          document appearing on the <port>current</port> port) is the
            <function>p:iteration-position</function>.</para>
        <note xml:id="impl2">
          <title>Note to implementers</title>
          <para>In the case where no XPath expression that must be evaluated by the processor makes
            any reference to <function>p:iteration-size</function>, its value does not actually have
            to be calculated (and the entire input sequence does not, therefore, need to be buffered
            so that its size can be calculated before processing begins).</para>
        </note>
      </section><section xml:id="example-viewport" role="tocsuppress">
        <title>Example</title>
        <para>A <tag>p:viewport</tag> might accept an XHTML document as its input, add an
            <tag>hr</tag> element at the beginning of all <tag>div</tag> elements that have the
          class value “chapter”, and return an XHTML document that is the same as the original
          except for that change.</para>
        <example xml:id="ex.p.viewport">
          <title>A Sample Viewport</title>
          <programlisting><xi:include href="examples/viewport.txt" parse="text"/></programlisting>
        </example>
        <para>The nodes which match <code>h:div[@class='chapter']</code> in the input document are
          selected. An <code>hr</code> is inserted as the first child of each <code>h:div</code> and
          the resulting version replaces the original <code>h:div</code>. The result of the whole
          step is a copy of the input document with a horizontal rule as the first child of each
          selected <code>h:div</code>.</para>
      </section></section>
    <section xml:id="p.choose"><title>p:choose</title><para>A choose is specified by the
          <tag>p:choose</tag> element. It is a <glossterm>multi-container step</glossterm> that
        selects exactly one of a list of alternative <glossterm baseform="subpipeline"
          >subpipelines</glossterm> based on the evaluation of XPath expressions.</para>
      <e:rng-pattern name="Choose"/>
      <para>A <tag>p:choose</tag> has no inputs. It contains an arbitrary number of alternative
          <glossterm baseform="subpipeline">subpipelines</glossterm>, exactly one of which will be
        evaluated.</para>
<para>The list of alternative subpipelines consists of zero or more
        subpipelines guarded by an XPath expression, followed optionally by a single default
        subpipeline.</para>
<para>The <tag>p:choose</tag> considers each subpipeline in turn and
        selects the first (and only the first) subpipeline for which the guard expression evaluates
        to true in its context. If there are no subpipelines for which the expression evaluates to
        true, the default subpipeline, if it was specified, is selected.</para>
<para>After a
          <glossterm>subpipeline</glossterm> is selected, it is evaluated as if only it had been
        present.</para>
<para>The outputs of the <tag>p:choose</tag> are taken from the outputs of
        the selected <glossterm>subpipeline</glossterm>. The <tag>p:choose</tag> has the same number
        of outputs as the selected subpipeline with the same names. If the selected subpipeline has
        a <glossterm>primary output port</glossterm>, the port with the same name on the
          <tag>p:choose</tag> is also a primary output port.</para>
<para>In order to ensure that the
        output of the <tag>p:choose</tag> is consistent irrespective of the
          <glossterm>subpipeline</glossterm> chosen, each <glossterm>subpipeline</glossterm> must
        declare the same number of outputs with the same names. If any of the subpipelines specifies
        a <glossterm>primary output port</glossterm>, each subpipeline must specify exactly the same
        output as primary. <error code="S0007">It is a <glossterm>static error</glossterm> if two
            <glossterm baseform="subpipeline">subpipelines</glossterm> in a <tag>p:choose</tag>
          declare different outputs.</error></para>
<para>As a convenience to authors, it is not an
        error if some subpipelines declare outputs that can produce sequences and some do not. Each
        output of the <tag>p:choose</tag> is declared to produce a sequence if that output is
        declared to produce a sequence in any of its subpipelines.</para>
<para><error code="D0004"
          >It is a <glossterm>dynamic error</glossterm> if no <glossterm>subpipeline</glossterm> is
          selected by the <tag>p:choose</tag> and no default is provided.</error></para>

<para>The <tag>p:choose</tag> can specify the context node against
which the XPath expressions that occur on each branch are evaluated.
The context node is specified as a <glossterm>connection</glossterm>
in the <tag>p:xpath-context</tag>. If no explicit connection is
provided,
the <glossterm>default readable port</glossterm> is used.
In an XPath 1.0 implementation, if the context node is connected
to <tag>p:empty</tag>, or is unconnected and the <glossterm>default
readable port</glossterm> is undefined, an <link
linkend="empty-xpath-context">empty document node</link> is used
instead as the context. In an XPath 2.0 implementation, the context
item is undefined.</para>

<para>Each conditional
          <glossterm>subpipeline</glossterm> is represented by a <tag>p:when</tag> element. The
        default branch is represented by a <tag>p:otherwise</tag> element.</para><section
        xml:id="p.xpath-context"><title>p:xpath-context</title><para>A <tag>p:xpath-context</tag>
          element specifies the context node against which an XPath expression will be evaluated.
          When it appears in a <tag>p:when</tag>, it specifies the context for that
            <tag>p:when</tag>’s <tag class="attribute">test</tag> attribute. When it appears in
            <tag>p:choose</tag>, it specifies the default context for all of the <tag>p:when</tag>
          elements in that <tag>p:choose</tag>.</para>
        <e:rng-pattern name="XPathContext"/>
        <para>Only one <glossterm>connection</glossterm> is allowed and it works the same way that
          connections work on a <tag>p:input</tag>. No <tag class="attribute">select</tag>
          expression is allowed. <error code="D0005">It is a <glossterm>dynamic error</glossterm>
            if more than one document appears on the connection for the
            <tag>xpath-context</tag>.</error></para>
<para>The <tag>p:xpath-context</tag> element
          only provides the context node. The namespace bindings, in-scope variables, and other
          aspects of the context come from the element on which the XPath expression
          occurs.</para>
<para>In an XPath 1.0 implementation, if the context node is connected to
            <tag>p:empty</tag>, or is unconnected and the <glossterm>default readable
            port</glossterm> is undefined, an <link linkend="empty-xpath-context">empty document
            node</link> is used instead as the context. In an XPath 2.0 implementation, the context
          item is undefined.</para></section><section xml:id="p.when"><title>p:when</title><para>A
          when specifies one subpipeline guarded by a test expression. </para>
        <e:rng-pattern name="When"/>
        <para>Each <tag>p:when</tag> branch of the <tag>p:choose</tag> has a <tag class="attribute"
            >test</tag> attribute which <rfc2119>must</rfc2119> contain an XPath expression. That
          XPath expression's effective boolean value is the guard for the
            <glossterm>subpipeline</glossterm> contained within that
          <tag>p:when</tag>.</para>
<para>The <tag>p:when</tag> can specify a context node against
          which its <tag class="attribute">test</tag> expression is to be evaluated. That context
          node is specified as a <glossterm>connection</glossterm> for the
            <tag>p:xpath-context</tag>. If no context is specified on the <tag>p:when</tag>, the
          context of the <tag>p:choose</tag> is used.</para></section><section xml:id="p.otherwise"
          ><title>p:otherwise</title><para>An otherwise specifies the default branch; the
          subpipeline selected if no test expression on any preceding <tag>p:when</tag> evaluates to
          true.</para>
        <e:rng-pattern name="Otherwise"/>
      </section><section xml:id="example-choose" role="tocsuppress">
        <title>Example</title>
        <para>A <tag>p:choose</tag> might test the version attribute of the document element and
          validate with an appropriate schema.</para>
        <example xml:id="ex.p.choose">
          <title>A Sample Choose</title>
          <programlisting><xi:include href="examples/choose.txt" parse="text"/></programlisting>
        </example>
      </section></section>
    <section xml:id="p.group"><title>p:group</title><para>A group is specified by the
          <tag>p:group</tag> element. In a <tag>p:try</tag>, it is a non-step wrapper, everywhere
        else, it is a <glossterm>compound step</glossterm>. A group encapsulates the behavior of its
          <glossterm>subpipeline</glossterm>.</para>
      <e:rng-pattern name="Group"/>
      <para>A <tag>p:group</tag> is a convenience wrapper for a collection of steps. </para><section
        xml:id="example-group" role="tocsuppress">
        <title>Example</title>
        <example xml:id="ex.p.group">
          <title>An Example Group</title>
          <programlisting><xi:include href="examples/group.txt" parse="text"/></programlisting>
        </example>
      </section></section>
    <section xml:id="p.try"><title>p:try</title><para>A try/catch is specified by the
          <tag>p:try</tag> element. It is a <glossterm>multi-container step</glossterm> that
        isolates a <glossterm>subpipeline</glossterm>, preventing any dynamic errors that arise
        within it from being exposed to the rest of the pipeline.</para>
      <e:rng-pattern name="Try"/>
      <para>The <tag>p:group</tag> represents the initial subpipeline and the recovery (or “catch”)
        pipeline is identified with a <tag>p:catch</tag> element.</para>
<para>The <tag>p:try</tag>
        step evaluates the initial subpipeline and, if no errors occur, the outputs of that pipeline
        are the outputs of the <tag>p:try</tag> step. However, if any errors occur, the
          <tag>p:try</tag> abandons the first subpipeline, discarding any output that it might have
        generated, and evaluates the recovery subpipeline.</para>
<para>If the recovery subpipeline
        is evaluated, the outputs of the recovery subpipeline are the outputs of the
          <tag>p:try</tag> step. If the recovery subpipeline is evaluated and a step within that
        subpipeline fails, the <tag>p:try</tag> fails.</para>
<para>The outputs of the
          <tag>p:try</tag> are taken from the outputs of the initial subpipeline or the recovery
        subpipeline if an error occurred in the initial subpipeline. The <tag>p:try</tag> has the
        same number of outputs as the selected subpipeline with the same names. If the selected
        subpipeline has a <glossterm>primary output port</glossterm>, the port with the same name on
        the <tag>p:try</tag> is also a primary output port.</para>
<para>In order to ensure that the
        output of the <tag>p:try</tag> is consistent irrespective of whether the initial subpipeline
        provides its output or the recovery subpipeline does, both subpipelines must declare the
        same number of outputs with the same names. If either of the subpipelines specifies a
          <glossterm>primary output port</glossterm>, both subpipelines must specify exactly the
        same output as primary. <error code="S0009">It is a <glossterm>static error</glossterm> if
          the <tag>p:group</tag> and <tag>p:catch</tag> subpipelines declare different
          outputs.</error></para>
<para>As a convenience to authors, it is not an error if an output
        port can produce a sequence in the initial subpipeline but not in the recovery subpipeline,
        or vice versa. Each output of the <tag>p:try</tag> is declared to produce a sequence if that
        output is declared to produce a sequence in either of its subpipelines.</para>
<para>A
        pipeline author can cause an error to occur with the <tag>p:error</tag> step.</para>
      <!--
<para>The <glossterm>environment</glossterm> of a <tag>p:try</tag> is its
inherited environment with the <link linkend="dt-standard-modifications">standard
modifications</link>.</para>

<para>The environment inherited by its initial subpipeline, the
<tag>p:group</tag>, is the environment of the <tag>p:try</tag>.</para>
-->
      <para>The recovery subpipeline of a <tag>p:try</tag> is identified with a <tag
          xml:id="p.catch">p:catch</tag>:</para>
      <e:rng-pattern name="Catch"/>
      <!--
<para>The environment of a <tag>p:catch</tag> is the environment of
its containing <tag>p:try</tag>.</para>
-->
      <para>The environment inherited by the <glossterm>contained steps</glossterm> of the
          <tag>p:catch</tag> is the <glossterm>inherited environment</glossterm> with this
        modification:</para><itemizedlist>
        <listitem>
          <para>The port named “<port>error</port>” on the <tag>p:catch</tag> is added to the
              <glossterm>readable ports</glossterm>.</para>
        </listitem>
      </itemizedlist><para>What appears on the <port>error</port> output port is an <link
          linkend="err-vocab">error document</link>. The error document may contain messages
        generated by steps that were part of the initial subpipeline. Not all messages that appear
        are indicative of errors; for example, it is common for all <tag>xsl:message</tag> output
        from the XSLT component to appear on the <port>error</port> output port. It is possible that
        the component which fails may not produce any messages at all. It is also possible that the
        failure of one component may cause others to fail so that there may be multiple failure
        messages in the document.</para><section xml:id="err-vocab">
        <title>The Error Vocabulary</title>
        <para>In general, it is very difficult to predict error behavior. Step failure may be
          catastrophic (programmer error), or it may be be the result of user error, resource
          failures, etc. Steps may detect more than one error, and the failure of one step may cause
          other steps to fail as well.</para>
        <para>The <tag>p:try</tag>/<tag>p:catch</tag> mechanism gives pipeline authors the
          opportunity to process the errors that caused the <tag>p:try</tag> to fail. In order to
          facilitate some modicum of interoperability among processors, errors that are reported on
          the <literal>error</literal> output port of a <tag>p:catch</tag>
          <rfc2119>should</rfc2119> conform to the format described here. </para>
        <section xml:id="cv.errors"><title>c:errors</title><para>The error vocabulary consists of a
            root element, <tag>c:errors</tag> which contains zero or more <tag>c:error</tag>
            elements.</para>
          <e:rng-pattern name="Errors"/>
        </section>
        <section xml:id="cv.error"><title>c:error</title><para>Each specific error is represented by
            an <tag>c:error</tag> element:</para>
          <e:rng-pattern name="Error"/>
          <para>The <tag class="attribute">name</tag> and <tag class="attribute">type</tag>
            attributes identify the name and type, respectively, of the step which
            failed.</para>
<para>The <tag class="attribute">code</tag> is a QName which identifies
            the error. For steps which have defined error codes, this is an opportunity for the step
            to identify the error in a machine-processable fashion. Many steps omit this because
            they do not include the concept of errors identified by QNames.</para>
<para>If the error
            was caused by a specific document, or by the location of some erroneous construction in
            a specific document, the <tag class="attribute">href</tag>, <tag class="attribute"
              >line</tag>, <tag class="attribute">column</tag>, and <tag class="attribute"
              >offset</tag> attributes identify this location. Generally, the error location is
            identified either with line and column numbers or with an offset from the beginning of
            the document, but not usually both.</para>
<para>The content of the <tag>c:error</tag>
            element is any well-formed XML. Specific steps, or specific implementations, may provide
            more detail about the format of the content of an error message.</para></section>
        <section xml:id="error-example">
          <title>Error Example</title>
          <para>Consider the following XSLT stylesheet:</para>
          <programlisting><![CDATA[<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:template match="/">
  <xsl:message terminate="yes">
    <xsl:text>This stylesheet is </xsl:text>
    <emph>pointless</emph>
    <xsl:text>.</xsl:text>
  </xsl:message>
</xsl:template>

</xsl:stylesheet>]]></programlisting>
          <para>If it was used in a step named “xform” in a <tag>p:try</tag>, the following error
            document might be produced:</para>
          <programlisting><![CDATA[<c:errors xmlns:c="http://www.w3.org/ns/xproc-step">
  <c:error name="xform" type="p:xslt"
             href="style.xsl" line="6">This stylesheet is <emph>pointless</emph>.</c:error>
</c:errors>]]></programlisting>
          <para>It is not an error for steps to generate non-standard error output as long as it is
            well-formed.</para>
        </section>
      </section><section xml:id="example-try" role="tocsuppress">
        <title>Example</title>
        <para>A pipeline might attempt to process a document by dispatching it to some web service.
          If the web service succeeds, then those results are passed to the rest of the pipeline.
          However, if the web service cannot be contacted or reports an error, the
            <tag>p:catch</tag> step can provide some sort of default for the rest of the
          pipeline.</para>
        <example xml:id="ex.p.trycatch">
          <title>An Example Try/Catch</title>
          <programlisting><xi:include href="examples/trycatch.txt" parse="text"/></programlisting>
        </example>
      </section></section>
    <section xml:id="p.atomic"><title>Atomic Steps</title><para>In addition to the six step types
        described in the preceding sections, XProc provides a standard library of atomic step types.
        The full vocabulary of standards steps is described in <xref linkend="std-components"
        />.</para>
<para>All of the standard, atomic steps are invoked in the same way:</para>
      <e:rng-pattern name="OtherAtomicStep"/>
      <para>Where “<replaceable>p:atomic-step</replaceable>” <rfc2119>must</rfc2119> be in the XProc
        namespace and <rfc2119>must</rfc2119> be declared in either the standard library for the
        XProc version supported by the processor or explicitly imported by the surrounding pipeline
        (see <xref linkend="versioning-considerations"/>). </para></section>
    <section xml:id="p.extension"><title>Extension Steps</title><para>Pipeline authors may also have
        access to additional steps not defined or described by this specification. Atomic extension
        steps are invoked just like standard steps:</para>
      <e:rng-pattern name="OtherAtomicStep"/>
      <para>Extension steps <rfc2119>must not</rfc2119> be in the XProc namespace and there
          <rfc2119>must</rfc2119> be a <glossterm>visible</glossterm> step declaration at the point
        of use (see <xref linkend="scoping"/>).</para>
<para>If the relevant step declaration has no
          <glossterm>subpipeline</glossterm>, then that step invokes the declared atomic step, which
        the processor must know how to perform. These steps are implementation-defined extensions.
        </para>
<para>If the relevant step declaration has a <glossterm>subpipeline</glossterm>, then
        that step runs the declared subpipeline. These steps are user- or implementation-defined
        extensions. Pipelines can refer to themselves (recursion is allowed), to pipelines defined
        in imported libraries, and to other pipelines in the same library if they are in a
        library.</para>
<para><error code="S0010">It is a <glossterm>static error</glossterm> if a
          pipeline contains a step whose specified inputs, outputs, and options do not <glossterm
            baseform="matches">match</glossterm> the <glossterm>signature</glossterm> for steps of
          that type.</error></para>
<para><error code="D0017">It is a <glossterm>dynamic
            error</glossterm> if the running pipeline attempts to invoke a step which the processor
          does not know how to perform.</error></para>
<para><impl>The presence of other <glossterm
            baseform="compound step">compound steps</glossterm> is
            <glossterm>implementation-defined</glossterm>; XProc provides no standard mechanism for
          defining them or describing what they can contain.</impl>
        <error code="S0048">It is a <glossterm>static error</glossterm> to use a declared step as a
            <glossterm>compound step</glossterm>.</error></para><section xml:id="option-shortcut">
        <title>Syntactic Shortcut for Option Values</title>
        <para>Namespace qualified attributes on a step are <glossterm baseform="extension attribute"
            >extension attributes</glossterm>. Attributes, other than <tag class="attribute"
            >name</tag>, that are not namespace qualified are treated as a syntactic shortcut for
          specifying the value of an option. In other words, the following two steps are
          equivalent:</para>
        <para>The first step uses the standard <tag>p:with-option</tag> syntax:</para>
        <programlisting><![CDATA[<ex:stepType>
  <p:with-option name="option-name" select="'some value'"/>
</ex:stepType>]]></programlisting>
        <para>The second step uses the syntactic shortcut:</para>
        <programlisting><![CDATA[<ex:stepType option-name="some value"/>]]></programlisting>
        <para>Note that there are significant limitations to this shortcut syntax:</para>
        <orderedlist>
          <listitem>
            <para>It only applies to option names that are not in a namespace.</para>
          </listitem>
          <listitem>
            <para>It only applies to option names that are not otherwise used on the step, such as
                “<literal>name</literal>”.</para>
          </listitem>
          <listitem>
            <para>It can only be used to specify a constant value. Options that are computed at
              runtime must be written using the longer form.</para>
          </listitem>
        </orderedlist>
        <para><error code="S0027">It is a <glossterm>static error</glossterm> if an option is
            specified with both the shortcut form and the long form.</error>
          <error code="S0031">It is a <glossterm>static error</glossterm> to use an option on an
              <glossterm>atomic step</glossterm> that is not declared on steps of that type.</error>
        </para>
        <para>The syntactic shortcuts apply equally to standard atomic steps and extension atomic
          steps.</para>
      </section></section>
  </section>
  <section xml:id="other-elements">
    <title>Other pipeline elements</title>
    <section xml:id="p.input">
      <title>p:input</title>
      <para>A <tag>p:input</tag> identifies an input port for a step. In some contexts,
          <tag>p:input</tag> declares that a port with the specified name exists and identifies the
        properties of that port. In other contexts, it provides a connection for a port declared
        elsewhere. And in some contexts, it does both. The semantics of <tag>p:input</tag> are
        complicated further by the fact that there are two kinds of inputs, ordinary “document”
        inputs and “parameter” inputs.</para>
      <section xml:id="document-inputs"><title>Document Inputs</title><para>The declaration of a
          document input identifies the name of the port, whether or not the port accepts a
          sequence, whether or not the port is a <glossterm>primary input port</glossterm>, and may
          provide a default connection for the port.</para>
<para>An input
            <emphasis>declaration</emphasis> has the following form:</para>
        <e:rng-pattern name="InputDeclaration"/>
        <para>The <tag class="attribute">port</tag> attribute defines the name of the port. <error
            code="S0011">It is a <glossterm>static error</glossterm> to identify two ports with the
            same name on the same step.</error></para>
<para>The <tag class="attribute"
            >sequence</tag> attribute determines whether or not a sequence of documents is allowed
          on the port. <error code="D0006">If <tag class="attribute">sequence</tag> is not
            specified, or has the value false, then it is a <glossterm>dynamic error</glossterm>
            unless exactly one document appears on the declared port.</error></para>
<para>The <tag
            class="attribute">primary</tag> attribute is used to identify the <glossterm>primary
            input port</glossterm>. An input port is a <glossterm>primary input port</glossterm> if
            <tag class="attribute">primary</tag> is specified with the value <literal>true</literal>
          or if the step has only a single input port and <tag class="attribute">primary</tag> is
          not specified. <error code="S0030">It is a <glossterm>static error</glossterm> to specify
            that more than one input port is the primary.</error></para>
<para>The <tag
            class="attribute">kind</tag> attribute distinguishes between the two kinds of inputs:
          document inputs and parameter inputs. An input port is a document input port if <tag
            class="attribute">kind</tag> is specified with the value “<literal>document</literal>”
          or if <tag class="attribute">kind</tag> is not specified.</para>
<para>If a connection is
          provided in the declaration, then <tag class="attribute">select</tag> may be used to
          select a portion of the input identified by the <tag>p:empty</tag>, <tag>p:document</tag>,
            <tag>p:data</tag>, or <tag>p:inline</tag> elements in the <tag>p:input</tag>. This
          select expression applies <emphasis>only</emphasis> if the default connection is used. If
          an explicit connection is provided by the caller, then the default select expression is
          ignored.</para><note>
          <para>The <tag>p:pipe</tag> element is explicitly excluded from a declaration because it
            would make the default value of an input dependent on the execution of some part of the
            pipeline. Default values are designed so that they can be computed statically.</para>
        </note><para>On a <tag>p:declare-step</tag> for an atomic step, the <tag>p:input</tag>
          simply declares the input port. <error code="S0042">It is a <glossterm>static
              error</glossterm> to attempt to provide a connection for an input port on the
            declaration of an atomic step.</error></para>
<para>An input
            <emphasis>connection</emphasis> has the following form:</para>
        <e:rng-pattern name="InputConnection"/>
        <para>If no connection is provided for a <glossterm>primary input port</glossterm>, the
          input will be connected to the <glossterm>default readable port</glossterm>. <error
            code="S0032">It is a <glossterm>static error</glossterm> if no connection is provided
            and the <glossterm>default readable port</glossterm> is undefined.</error></para>
<para>A
            <tag class="attribute">select</tag> expression <rfc2119>may</rfc2119> also be provided
          with a connection. The <tag class="attribute">select</tag> expression, if specified,
          applies the specified XPath select expression to the document(s) that are read. Each
          selected node is wrapped in a document (unless it is a document) and provided to the input
          port. In other
          words,</para><programlisting><xi:include href="examples/input-doc.txt" parse="text"/></programlisting><para>provides
          a single document,
          but</para><programlisting><xi:include href="examples/input-select.txt" parse="text"/></programlisting><para>provides
          a sequence of zero or more documents, one for each <code>html:div</code> in
            <uri>http://example.org/input.html</uri>. (Note that in the case of nested
            <code>html:div</code> elements, this may result in the same content being returned in
          several documents.)</para>
<para>A select expression can equally be applied to input read
          from another step. This
          input:</para><programlisting><xi:include href="examples/input-port.txt" parse="text"/></programlisting><para>provides
          a sequence of zero or more documents, one for each <code>html:div</code> in the document
          (or each of the documents) that is read from the <literal>result</literal> port of the
          step named <literal>origin</literal>.</para>

<para>The base URI of the document that results from a select
expression is the base URI of the matched element or document. <error
code="D0016">It is a <glossterm>dynamic error</glossterm> if the <tag
class="attribute">select</tag> expression on a <tag>p:input</tag>
returns atomic values or anything other than element or document
nodes (or an empty sequence).</error></para>

<para>An input
          declaration may include a default connection. If no connection is provided for an input
          port which has a default connection, then the input is treated as if the default
          connection appeared.</para>
<para>A default connection does not satisfy the requirement
          that a primary input port is automatically connected by the processor, nor is it used when
          no default readable port is defined. In other words, a <tag>p:declare-step</tag> or a
            <tag>p:pipeline</tag> can define defaults for all of its inputs, whether they are
          primary or not, but defining a default for a primary input usually has no effect. It's
          never used by an atomic step since the step, when it's called, will always connect the
          primary input port to the default readable port (or cause a static error). The only case
          where it has value is on a <tag>p:pipeline</tag> when that pipeline is invoked directly by
          the processor. In that case, the processor <rfc2119>must</rfc2119> use the default
          connection if no external connection is provided for the port.</para></section>

<section xml:id="parameter-inputs"><title>Parameter Inputs</title>

<para>The declaration of a parameter input identifies the name of the
port and that the port is a parameter input.</para>

<e:rng-pattern name="ParameterInputDeclaration"/>

<para>The <tag class="attribute">port</tag> attribute defines the name
of the port. <error code="S0011">It is a <glossterm>static
error</glossterm> to identify two ports with the same name on the same
step.</error>
</para>

<para>The <tag class="attribute" >sequence</tag> attribute determines
whether or not a sequence of documents is allowed on the port. A
sequence of documents is always allowed on a parameter input port.
<error code="S0040">It is a <glossterm>static error</glossterm> to
specify any value other than <literal>true</literal>.</error></para>

<para>The <tag class="attribute">primary</tag> attribute is used to
identify the <glossterm>primary parameter input port</glossterm>. An
input port is a <glossterm>primary parameter input port</glossterm> if
it is a <glossterm>parameter input port</glossterm> and <tag
class="attribute">primary</tag> is specified with the value
<literal>true</literal> or if the step has only a single parameter
input port and <tag class="attribute">primary</tag> is not specified.
<error code="S0030">It is a <glossterm>static error</glossterm> to
specify that more than one parameter input port is the
primary.</error></para>
<para>The <tag class="attribute"
>kind</tag> attribute distinguishes between the two kinds of inputs: document inputs and
parameter inputs. An input port is a parameter input port only if the <tag
class="attribute">kind</tag> attribute is specified with the value “parameter”. <error
code="S0033">It is a <glossterm>static error</glossterm> to specify any kind of input
other than “document” or “parameter”.</error>
</para>

<para>A parameter input port is a distinguished kind of input port. It
exists only to receive computed parameters; if a step does not have a
parameter input port then it cannot receive parameters. A parameter
input port must satisfy all the constraints of a normal, document
input port.</para>

<para><error code="S0035">It is a <glossterm>static error</glossterm>
if the declaration of a parameter input port contains a connection;
parameter input port declarations must be empty.</error>
</para>

<para>When used on a step, parameter input ports are connected just
like ordinary document ports. Parameter input ports always accept a
sequence of documents. If no explicit connection is provided for a
<glossterm>primary parameter input port</glossterm>, then the port
will be connected to the primary parameter input port of the pipeline
which contains the step. If no connection is provided for a parameter
input port other than the primary parameter input port, then the port
will be connected to an <glossterm>empty sequence</glossterm> of
documents.</para>

<para><error code="S0055">It is a <glossterm>static
error</glossterm> if a primary parameter input port is unconnected and
the pipeline that contains the step has no primary parameter input
port unless at least one explicit <tag>p:with-param</tag>
is provided for that port.</error></para>

<para>In other words, it is an error to leave a parameter input port
unconnected, but any parameter passed explicitly to that port satisfies
the connection requirement.</para>

<para>This is an error:</para>

<programlisting
><xi:include href="examples/param-conn-1.xml" parse="text"
/></programlisting>

<para>The parameter input port on the <tag>p:xslt</tag> step has no
connection and the pipeline that contains the step has no primary parameter
input port.</para>

<para>This is not an error:</para>

<programlisting
><xi:include href="examples/param-conn-2.xml" parse="text"
/></programlisting>

<para>Explicitly setting the “<literal>mode</literal>” parameter 
satisfies the binding requirement. No other parameters can be passed
to the <tag>p:xslt</tag> step.</para>

<para>This, also, is not an error:</para>

<programlisting
><xi:include href="examples/param-conn-3.xml" parse="text"
/></programlisting>

<para>The parameter input port on the <tag>p:xslt</tag> step is bound
to the primary parameter input port of the pipeline. The <tag>p:xslt</tag>
step will receive the “<literal>mode</literal>” parameter and any other
parameters passed to the pipeline.</para>

<para>If a parameter input port on a <tag>p:pipeline</tag> is not
connected, it is treated as if it was connected to an automatically
created <tag>p:sink</tag> step. In other words, if a
<tag>p:pipeline</tag> does not contain any steps that have parameter
input ports, or if those ports are all explicitly connected elsewhere,
the parameter input port is ignored. In this one case, it is not an
error for an input port to be unconnected.</para>

<para>A step which accepts a parameter input reads all of the
documents presented on that port, using each <tag>c:param</tag>
(either at the root or inside the <tag>c:param-set</tag>) to establish
the value of the named parameter. If the same name appears more than
once, the last value specified is used. If the step also has literal
<tag>p:with-param</tag> elements, they are also considered in
document order. In other words, <tag>p:with-param</tag> elements that
appear before the parameter input may be overridden by the computed
parameters; <tag>p:with-param</tag> elements that appear after may
override the computed values.</para>

<para>If a connection is manufactured for a primary parameter input
port, that connection occurs logically last among the other
parameters, options, and connections passed to the step. In other
words, the parameter values that appear on that port will be used even
if other values were specified with <tag>p:with-param</tag> elements.
Users can change this priority by making the connection explicit and
placing any <tag>p:with-param</tag> elements that they wish to
function as overrides after the connection.</para>

<para>All of the documents that appear on a parameter input must
either be <tag>c:param</tag> documents or <tag>c:param-set</tag>
documents.</para>

<para>Consider the
example in <xref linkend="ex.parameter"/>.</para><example xml:id="ex.parameter">
<title>A Parameter Example</title>
<programlisting><xi:include href="examples/parameter.xml" parse="text"/></programlisting>
</example>

<para>This <tag>p:pipeline</tag> declares that it accepts parameters.
Suppose that (through some <glossterm
role="unwrapped">implementation-defined</glossterm> mechanism) I have
passed the parameters
“<varname>output-type</varname>=<literal>fo</literal>” and
“<varname>profile</varname>=<literal>unclassified</literal>” to the
pipeline. These parameters are available on the
<literal>parameters</literal> input port.
</para>

<para>When the XSLT step runs, it will read those parameters and combine them with
          any parameters specified literally on the step. Because the parameter input comes
            <emphasis>after</emphasis> the literal declaration for <varname>output-type</varname> on
          the step, the XSLT stylesheet will see both values that I passed in
            (“<varname>output-type</varname>=<literal>fo</literal>” and
            “<varname>profile</varname>=<literal>unclassified</literal>”).</para>
<para>If the
          parameter input came <emphasis>before</emphasis> the literal declaration, then the XSLT
          stylesheet would see “<varname>output-type</varname>=<literal>html</literal>” and
            “<varname>profile</varname>=<literal>unclassified</literal>”.</para>
<para>Most steps
          don't bother to declare parameter inputs, or provide explicit connections for them, and
          “the right thing” usually happens.</para><section xml:id="cv.param"><title>The c:param
            element</title><para>A <tag>c:param</tag> represents a parameter on a parameter
            input.</para>
          <e:rng-pattern name="VocabParam"/>
          <para>The <tag class="attribute">name</tag> attribute of the <tag>c:param</tag> must have
            the lexical form of a QName.</para>
<para>If the <tag class="attribute">namespace</tag>
            attribute is specified, then the expanded name of the parameter is constructed from the
            specified namespace and the <tag class="attribute">name</tag> value. <error code="D0025"
              >It is a <glossterm>dynamic error</glossterm> if the <tag class="attribute"
                >namespace</tag> attribute is specified, the <tag class="attribute">name</tag>
              contains a colon, and the specified namespace is not the same as the in-scope
              namespace binding for the specified prefix.</error>
          </para>
<para>If the <tag class="attribute">namespace</tag> attribute is not specified, and
            the <tag class="attribute">name</tag> contains a colon, then the expanded name of the
            parameter is constructed using the <tag class="attribute">name</tag> value and the
            namespace declarations in-scope on the <tag>c:param</tag> element.</para>
<para>If the
              <tag class="attribute">namespace</tag> attribute is not specified, and the <tag
              class="attribute">name</tag> does not contain a colon, then the expanded name of the
            parameter is in no namespace.</para>
<para>Any namespace-qualified attribute names that
            appear on the <tag>c:param</tag> element are ignored. <error code="D0014">It is a
                <glossterm>dynamic error</glossterm> for any unqualified attribute names other than
                “<literal>name</literal>”, “<literal>namespace</literal>”, or
                “<literal>value</literal>” to appear on a <tag>c:param</tag>
          element.</error></para></section>

<section xml:id="cv.param-set"><title>The c:param-set
            element</title><para>A <tag>c:param-set</tag> represents a set of parameters on a
            parameter input.</para>
          <e:rng-pattern name="VocabParamSet"/>
          <para>The <tag>c:param-set</tag> contains zero or more <tag>c:param</tag> elements. <error
              code="D0018">It is a <glossterm>dynamic error</glossterm> if the parameter list
              contains any elements other than <tag>c:param</tag>.</error></para>
<para>Any
            namespace-qualified attribute names that appear on the <tag>c:param-set</tag> element
            are ignored. <error code="D0014">It is a <glossterm>dynamic error</glossterm> for any
              unqualified attribute names to appear on a <tag>c:param-set</tag>
            element.</error></para></section></section>
    </section>
    <section xml:id="p.iteration-source"><title>p:iteration-source</title><para>A
          <tag>p:iteration-source</tag> identifies input to a <tag>p:for-each</tag>.</para>
      <e:rng-pattern name="IterationSource"/>
      <para>The <tag class="attribute">select</tag> attribute and <glossterm>connection</glossterm>
        of a <tag>p:iteration-source</tag> work the same way that they do in a
        <tag>p:input</tag>.</para></section>
    <section xml:id="p.viewport-source"><title>p:viewport-source</title><para>A
          <tag>p:viewport-source</tag> identifies input to a <tag>p:viewport</tag>.</para>
      <e:rng-pattern name="ViewportSource"/>
      <para>Only one <glossterm>connection</glossterm> is allowed and it works the same way that
        connections work on a <tag>p:input</tag>. <error code="D0003">It is a <glossterm>dynamic
            error</glossterm> unless exactly one document appears on the
            <tag>p:viewport-source</tag>.</error> No <tag class="attribute">select</tag> expression
        is allowed.</para></section>
    <!-- ============================================================ -->
    <section xml:id="p.output"><title>p:output</title><para>A <tag>p:output</tag> identifies an
        output port, optionally connecting an input for it, if necessary.</para>
      <e:rng-pattern name="OutputDeclaration"/>
      <para>The <tag class="attribute">port</tag> attribute defines the name of the port. <error
          code="S0011">It is a <glossterm>static error</glossterm> to identify two ports with the
          same name on the same step.</error></para>
<para>An output declaration can indicate if a
        sequence of documents is allowed to appear on the declared port. If <tag class="attribute"
          >sequence</tag> is specified with the value <literal>true</literal>, then a sequence is
        allowed. <error code="D0007">If <tag class="attribute">sequence</tag> is not specified on
            <tag>p:output</tag>, or has the value false, then it is a <glossterm>dynamic
            error</glossterm> if the step does not produce exactly one document on the declared
          port.</error></para>
<para>The <tag class="attribute">primary</tag> attribute is used to
        identify the primary output port. An output port is a primary output port if <tag
          class="attribute">primary</tag> is specified with the value <literal>true</literal> or if
        the step has only a single output port and primary is not specified. <error code="S0014">It
          is a <glossterm>static error</glossterm> to identify more than one output port as
          primary.</error></para>
<para>On <glossterm baseform="compound step">compound
          steps</glossterm>, the declaration <rfc2119>may</rfc2119> be accompanied by a
          <glossterm>connection</glossterm> for the output.</para>
      <e:rng-pattern name="OutputConnection"/>
      <para><error code="S0029">It is a <glossterm>static error</glossterm> to specify a connection
          for a <tag>p:output</tag> inside a <tag>p:declare-step</tag> for an atomic
        step.</error></para>
<para>If a connection is provided for a <tag>p:output</tag>, documents
        are <emphasis>read from</emphasis> that connection and those documents form the output that
          <emphasis>is written</emphasis> to the output port. In other words, placing a
          <tag>p:document</tag> inside a <tag>p:output</tag> causes the processor to <emphasis>read
          that document</emphasis> and provide it on the output port. It <emphasis>does
          not</emphasis> cause the processor to <emphasis>write</emphasis> the output to that
        document.</para></section>
    <!-- ============================================================ -->
    <section xml:id="p.log"><title>p:log</title><para>A <tag>p:log</tag> element is a debugging aid.
        It associates a URI with a specific output port on a step:</para>
      <e:rng-pattern name="Log"/>
      <para>The semantics of <tag>p:log</tag> are that it writes to the specified IRI whatever
        document or documents appear on the specified port. <impl>If the <tag class="attribute"
            >href</tag> attribute is not specified, the location of the log file or files is
            <glossterm>implementation-defined</glossterm>.</impl></para>
<para><impl>How each
          document or sequence of documents is represented in a <tag>p:log</tag> is
            <glossterm>implementation-defined</glossterm>.</impl> Pipelines are not expected to be
        able to consume their own logging output. <impl>The ability of a step to read the
            <tag>p:log</tag> output of some former step is
            <glossterm>implementation-dependent</glossterm>. </impl>
      </para>
<para><error code="S0026">It is a <glossterm>static error</glossterm> if the port
          specified on the <tag>p:log</tag> is not the name of an output port on the step in which
          it appears or if more than one <tag>p:log</tag> element is applied to the same
          port.</error></para>
<para>Implementations may, at user option, ignore all <tag>p:log</tag>
        elements.</para><note>
        <para>This element represents a potential security risk: running unexamined 3rd-party
          pipelines could result in vital system resources being overwritten.</para>
      </note></section>
    <!-- ============================================================ -->
    <section xml:id="p.serialization"><title>p:serialization</title><para>The
          <tag>p:serialization</tag> element allows the user to request serialization properties on
        a <tag>p:pipeline</tag> output. </para>
      <e:rng-pattern name="Serialization"/>
      <para>If the pipeline processor serializes the output on the specified port, it
          <rfc2119>must</rfc2119> use the serialization options specified. If the processor is not
        serializing (if, for example, the pipeline has been called from another pipeline), then the
          <tag>p:serialization</tag>
        <rfc2119>must</rfc2119> be ignored. The processor <rfc2119>may</rfc2119> reject statically a
        pipeline that requests serialization options that it cannot provide.</para>
<para><impl>The
          default value of any serialization options not specified on a particular
            <tag>p:serialization</tag> element is
          <glossterm>implementation-defined</glossterm>.</impl> The allowed options are defined by
          <biblioref linkend="xml-serialization"/>. <error code="D0020">It is a <glossterm>dynamic
            error</glossterm> if the combination of serialization options specified or defaulted is
          not allowed.</error> Implementations <rfc2119>must</rfc2119> check that all of the
        specified serialization options are allowed if they serialize the specified output. If the
        specified output is not being serialized (because it is being returned as the result of a
        call from within another pipeline, for example) implementations <rfc2119>may</rfc2119> but
        are not required to check that the specified options are allowed.</para>
<para>The semantics
        of the attributes on a <tag>p:serialization</tag> are described in <xref
          linkend="serialization-options"/>.</para>
<para><error code="S0039">It is a
            <glossterm>static error</glossterm> if the port specified on the
            <tag>p:serialization</tag> is not the name of an output port on the pipeline in which it
          appears or if more than one <tag>p:serialization</tag> element is applied to the same
          port.</error></para></section>
    <!-- ============================================================ -->
    <section xml:id="variables-options-parameters">
      <title>Variables, Options, and Parameters</title>
      <para>Variables, options, and parameters provide a mechanism for pipeline authors to construct
        temporary results and hold onto them for reuse.</para>
      <para>Variables are created in compound steps and, like XSLT variables, are single assignment,
        though they may be shadowed by subsequent declarations of other variables with the same
        name.</para>
      <para>Options can be declared on atomic or compound steps. The value of an option can be
        specified by the caller invoking the step. Any value specified by the caller takes
        precedence over any default value specified in the declaration.</para>
      <para>Parameters, unlike options and variables, have names that can be computed at runtime.
        The most common use of parameters is to pass parameter values to XSLT stylesheets.</para>
      <section xml:id="p.variable"><title>p:variable</title><para>A <tag>p:variable</tag> declares a
          variable and associates a value with it.</para>
<para>The name of the variable
            <rfc2119>must</rfc2119> be a QName. If it does not contain a prefix then it is in no
          namespace. <error code="S0028">It is a <glossterm>static error</glossterm> to declare an
            option or variable in the XProc namespace.</error>
        </para>
<para>The variable's value is specified with a <tag class="attribute">select</tag>
          attribute. The <tag class="attribute">select</tag> attribute <rfc2119>must</rfc2119> be
          specified. The content of the <tag class="attribute">select</tag> attribute is an XPath
          expression which will be evaluated to provide the value of the variable.</para>
        <e:rng-pattern name="VariableSelect"/>
        <para>If a <tag class="attribute">select</tag> expression is given, it is evaluated as an
          XPath expression using the appropriate context as described in <xref
            linkend="xpath-context"/>, for the enclosing <glossterm>container</glossterm>, with the
          addition of bindings for all preceding-sibling <tag>p:variable</tag> and
            <tag>p:option</tag> elements. Regardless of the implicit type of the expression, when
          XPath 1.0 is being used, the string value of the expression becomes the value of the
          variable; when XPath 2.0 is being used, the type is treated as an
            <type>xs:untypedAtomic</type>.</para>
<para>Since all <glossterm>in-scope
            bindings</glossterm> are present in the Processor XPath Context as variable bindings,
            <tag class="attribute">select</tag> expressions may refer to the value of
            <glossterm>in-scope bindings</glossterm> by variable reference. If a variable reference
          uses a QName that is not the name of an <glossterm baseform="in-scope bindings">in-scope
            binding</glossterm>, an XPath evaluation error will occur.</para>
<para>If a <tag
            class="attribute">select</tag> expression is given, the <glossterm>readable
            ports</glossterm> available for document connections are the <glossterm>readable
            ports</glossterm> in the environment inherited by the first step in the surrounding
            <glossterm>container</glossterm>'s <glossterm>contained steps</glossterm>. However, in
          order to avoid ordering paradoxes, <error code="S0019">it is a <glossterm>static
              error</glossterm> for a variable's document connection to refer to the output port of
            any step in the surrounding <glossterm>container</glossterm>'s <glossterm>contained
              steps</glossterm></error>.</para>

<para>If a <tag class="attribute">select</tag> expression is given but
no document connection is provided, the implicit connection is to the
<glossterm>default readable port</glossterm> in the environment
inherited by the first step in the surrounding
<glossterm>container</glossterm>'s <glossterm>contained
steps</glossterm>.
If there is no default
readable port, the connection is treated as if <tag>p:empty</tag> was
specified.</para>

<para><error code="D0008">It is a <glossterm>dynamic error</glossterm>
if a sequence of more than one document appears on the connection for a
<tag>p:variable</tag>.</error> In an XPath 1.0 implementation, if
<tag>p:empty</tag> is given or implied as the document connection, an
<link linkend="empty-xpath-context">empty document node</link> is used as
the context node. In an XPath 2.0 implementation, the context item is
undefined.
<error code="D0026">It is a <glossterm>dynamic error</glossterm> if
the <tag class="attribute">select</tag> expression makes reference to
the context node, size, or position when the context item is
undefined.</error>
</para>


</section>

<!-- ============================================================ -->

<section xml:id="p.option">
<title>p:option</title>

<para>A <tag>p:option</tag> declares an option and may associate a
default value with it. The <tag>p:option</tag> tag can only be used in
a <tag>p:declare-step</tag> or a <tag>p:pipeline</tag> (which is a
syntactic abbreviation for a step declaration).</para>

<para>The name of the option <rfc2119>must</rfc2119> be a QName. If it
does not contain a prefix then it is in no namespace. <error
code="S0028">It is a <glossterm>static error</glossterm> to declare an
option or variable in the XProc namespace.</error></para>

<para><error code="S0004">It is a <glossterm>static error</glossterm>
to declare two or more options on the same step with the same
name.</error></para>

<e:rng-pattern name="OptionDeclaration"/>

<para>An option may be declared as <tag
class="attribute">required</tag>. <error code="S0018">If an option is
required, it is a <glossterm>static error</glossterm> to invoke the
step without specifying a value for that option.</error></para>

<para>If an option is not declared to be required, it
<rfc2119>may</rfc2119> be given a default value. The value is
specified with a <tag class="attribute">select</tag> attribute.</para>

<e:rng-pattern name="OptionSelect"/>

<para>If a <tag class="attribute">select</tag> attribute is specified,
its content is an XPath expression which will be evaluated to provide
the value of the option, which may differ from one instance of the
step type to another.</para>

<para>The <tag class="attribute">select</tag> expression is only
evaluated when its actual value is needed by an instance of the step
type being declared. In this case, it is evaluated as described in
<xref linkend="p.with-option"/> except that</para>

<itemizedlist>
          <listitem>
            <para>In an XPath 1.0 implementation, an <link linkend="empty-xpath-context">empty
                document node</link> is used as the context. In an XPath 2.0 implementation, the
              context item is undefined.</para>
          </listitem>
          <listitem>
            <para>the variable bindings consist only of bindings for options whose declaration
              precedes the <tag>p:option</tag> itself in the surrounding step
                <glossterm>signature</glossterm>;</para>
          </listitem>
          <listitem>
            <para>the in-scope namespaces are the in-scope namespaces of the <tag>p:option</tag>
              itself.</para>
          </listitem>
</itemizedlist>

<para><error code="S0017">It is a <glossterm>static error</glossterm>
to specify that an option is both <tag
class="attribute">required</tag> <emphasis>and</emphasis> has a
default value.</error></para>

<para><error code="D0026">It is a <glossterm>dynamic error</glossterm> if
the <tag class="attribute">select</tag> expression makes reference to
the context node, size, or position.</error></para>

<para>Regardless of the implicit type of the expression, when XPath
1.0 is being used, the string value of the expression becomes the
value of the option; when XPath 2.0 is being used, the value is an
<type>xs:untypedAtomic</type>.</para>
</section>

<!-- ============================================================ -->

<section xml:id="p.with-option">
<title>p:with-option</title>

<para>A <tag>p:with-option</tag> provides an actual value for an
option when a step is invoked.</para>

<para>The name of the option <rfc2119>must</rfc2119> be a QName. If it
does not contain a prefix then it is in no namespace.
<error code="S0031">It is a <glossterm>static error</glossterm> to use an
option name in <tag>p:with-option</tag> if the step type being invoked
has not declared an option with that name.</error>
(This error does not apply for steps in the XProc namespace when the processor
is operating in
<link linkend="vers-forwcomp">forwards-compatible mode</link>.)</para>

<para><error code="S0004">It is a <glossterm>static error</glossterm>
to include more than one <tag>p:with-option</tag> with the same option
name as part of the same step invocation.</error></para>

<para>The actual value is specified with a <tag
class="attribute">select</tag> attribute. The <tag
class="attribute">select</tag> attribute <rfc2119>must</rfc2119> be
specified. The value of the <tag class="attribute">select</tag>
attribute is an XPath expression which will be evaluated to provide
the value of the variable.</para>

<e:rng-pattern name="WithOptionSelect"/>

<para>Regardless of the implicit type of the expression, when XPath
1.0 is being used, the string value of the expression becomes the
value of the option; when XPath 2.0 is being used, the value is an
<type>xs:untypedAtomic</type>.</para>

<para>All <glossterm>in-scope bindings</glossterm> for the step
instance itself are present in the Processor XPath Context as variable
bindings, so <tag class="attribute">select</tag> expressions may refer
to any option or variable bound in those <glossterm>in-scope
bindings</glossterm> by variable reference. If a variable reference
uses a QName that is not the name of an <glossterm
baseform="in-scope-bindings">in-scope binding</glossterm> or preceding
sibling option, an XPath evaluation error will occur.</para>

<para>If a <tag class="attribute">select</tag> expression is used but
no document connection is provided, the implicit connection is to the
<glossterm>default readable port</glossterm>. If there is no default
readable port, the connection is treated as if <tag>p:empty</tag> was
specified.</para>

<para><error code="D0008">It is a <glossterm>dynamic error</glossterm>
if a sequence of more than one document appears on the connection for a
<tag>p:with-option</tag>. </error> In an XPath 1.0 implementation, if
<tag>p:empty</tag> is given or implied as the document connection, an
<link linkend="empty-xpath-context">empty document node</link> is used as
the context node. In an XPath 2.0 implementation, the context item is
undefined.
<error code="D0026">It is a <glossterm>dynamic error</glossterm> if
the <tag class="attribute">select</tag> expression makes reference to
the context node, size, or position when the context item is
undefined.</error>
</para>

</section>


<!-- ============================================================ -->

<section xml:id="p.with-param">
<title>p:with-param</title>

<para>The <tag>p:with-param</tag> element is used to establish the
value of a parameter. The parameter <rfc2119>must</rfc2119> be given a
value when it is used. (Parameter names aren't known in advance;
there's no provision for declaring them.)</para>

<para>The name of the parameter <rfc2119>must</rfc2119> be a QName. If
it does not contain a prefix then it is in no namespace. <error
code="D0031">It is a <glossterm>dynamic error</glossterm> to use the
XProc namespace in the name of a parameter.</error></para>

<para>The value is specified with a <tag
class="attribute">select</tag> attribute. The <tag class="attribute"
>select</tag> attribute <rfc2119>must</rfc2119> be specified. The
content of the <tag class="attribute">select</tag> attribute is an
XPath expression which will be evaluated to provide the value of the
variable.</para>

<e:rng-pattern name="WithParamSelect"/>

<para>The values of parameters for a step <rfc2119>must</rfc2119> be
computed after all the options in the step's
<glossterm>signature</glossterm> have had their values computed. If a
<tag class="attribute">select</tag> expression is given on a
<tag>p:with-param</tag>, it is evaluated as an XPath expression using
the appropriate context as described in <xref
linkend="xpath-context"/>, for the containing step, with the addition
of variable bindings for all options declared in the containing step's
<glossterm>signature</glossterm>.</para>

<para>Regardless of the implicit type of the expression, when XPath
1.0 is being used, the string value of the expression becomes the
value of the parameter; when XPath 2.0 is being used, the value is an
<type>xs:untypedAtomic</type>.</para>

<para>All <glossterm>in-scope bindings</glossterm> for the step
instance itself are present in the Processor XPath Context as variable
bindings, so <tag class="attribute">select</tag> expressions may refer
to any option or variable bound in those <glossterm>in-scope
bindings</glossterm>, as well as to any option declared in the step
signature, by variable reference. If a variable reference uses a QName
that is not the name of an <glossterm
baseform="in-scope-bindings">in-scope binding</glossterm> or declared
option, an XPath evaluation error will occur.</para>

<para>If a <tag class="attribute">select</tag> expression is used but
no document connection is provided, the implicit connection is to the
<glossterm>default readable port</glossterm>. If there is no default
readable port, the connection is treated as if <tag>p:empty</tag> was
specified.</para>

<para><error code="D0008">It is a <glossterm>dynamic error</glossterm>
if a sequence of more than one document appears on the connection for a
<tag>p:with-param</tag>. </error> In an XPath 1.0 implementation, if
<tag>p:empty</tag> is given or implied as the document connection, an
<link linkend="empty-xpath-context">empty document node</link> is used as
the context node. In an XPath 2.0 implementation, the context item is
undefined.
<error code="D0026">It is a <glossterm>dynamic error</glossterm> if
the <tag class="attribute">select</tag> expression makes reference to
the context node, size, or position when the context item is
undefined.</error>
</para>

<para>If the optional <tag class="attribute">port</tag> attribute is
specified, then the parameter appears on the named port, otherwise the
parameter appears on the step's <glossterm>primary parameter input
port</glossterm>. <error code="S0034">It is a <glossterm>static
error</glossterm> if the specified port is not a parameter input port
or if no port is specified and the step does not have a primary
parameter input port.</error>
</para>
</section>

<section xml:id="opt-param-bindings"><title>Namespaces on variables, options, and
          parameters</title><para>Variable, option and parameter values carry with them not only
          their literal or computed string value but also a set of namespaces. To see why this is
          necessary, consider the following
          step:</para><programlisting><xi:include href="examples/opns-1.xml" parse="text"/></programlisting><para>The
            <tag>p:delete</tag> step will delete elements that match the expression
            “<literal>html:div</literal>”, but that expression can only be correctly interpreted if
          there's a namespace binding for the prefix “<literal>html</literal>” so that binding has
          to travel with the option.</para>
<para>The default namespace bindings associated with a
          variable, option or parameter value are computed as follows:</para><orderedlist>
          <listitem>
            <para>If the <tag class="attribute">select</tag> attribute was used to specify the value
              and it consisted of a single <literal>VariableReference</literal> (per <biblioref
                linkend="xpath"/> or <biblioref linkend="xpath2"/>, as appropriate), then the
              namespace bindings from the referenced option or variable are used.</para>
          </listitem>
          <listitem>
            <para>If the <tag class="attribute">select</tag> attribute was used to specify the value
              and it evaluated to a node-set, then the in-scope namespaces from the first node in
              the selected node-set (or, if it's not an element, its parent) are used.</para>
            <para>The expression is evaluated in the appropriate context, See <xref
                linkend="xpath-context"/>.</para>
          </listitem>
          <listitem>
            <para>Otherwise, the in-scope namespaces from the element providing the value are used.
              (For options specified using <link linkend="option-shortcut">syntactic
                shortcuts</link>, the step element itself is providing the value.)</para>
          </listitem>
        </orderedlist><para>The default namespace is never included in the namespace bindings for a
          variable, option or parameter value. Unqualified names are always in
          no-namespace.</para>
<para>Unfortunately, in more complex situations, there may be no
          single variable, option or parameter that can reliably be expected to have the correct set
          of namespace bindings. Consider this
          pipeline:</para><programlisting><xi:include href="examples/opns-2.xml" parse="text"/></programlisting><para>It
          defines an atomic step (“<literal>ex:delete-in-div</literal>”) that deletes elements that
          occur inside of XHTML div elements. It might be used as
          follows:</para><programlisting><xi:include href="examples/opns-3.xml" parse="text"/></programlisting><para>In
          this case, the <varname>match</varname> option passed to the <tag>p:delete</tag> step
          needs <emphasis>both</emphasis> the namespace binding of “<literal>h</literal>” specified
          in the <tag>ex:delete-in-div</tag> pipeline definition <emphasis>and</emphasis> the
          namespace binding of “<literal>html</literal>” specified in the
            <varname>divchild</varname> option on the call of that pipeline. It's not sufficient to
          provide just one of the sets of bindings.</para><para xml:id="p.namespaces">The
            <tag>p:namespaces</tag> element can be used as a child of <tag>p:variable</tag>,
            <tag>p:with-option</tag> or <tag>p:with-param</tag> to provide explicit bindings.</para>
        <e:rng-pattern name="Namespaces"/>
        <para>The namespace bindings specified by a <tag>p:namespaces</tag> element are determined
          as follows:</para><orderedlist>
          <listitem>
            <para>If the <tag class="attribute">binding</tag> attribute is specified, it
                <rfc2119>must</rfc2119> contain the name of a single <glossterm
                baseform="in-scope-bindings">in-scope binding</glossterm>. The namespace bindings
              associated with that binding are used. <error code="S0020">It is a <glossterm>static
                  error</glossterm> if the <tag class="attribute">binding</tag> attribute on
                  <tag>p:namespaces</tag> is specified and its value is not the name of an
                  <glossterm baseform="in-scope-bindings">in-scope binding</glossterm>.</error>
            </para>
          </listitem>
          <listitem>
            <para>If the <tag class="attribute">element</tag> attribute is specified, it
                <rfc2119>must</rfc2119> contain an XPath expression which identifies a single
              element node (the input connection for this expression is the same as the connection
              for the <tag>p:option</tag> or <tag>p:with-param</tag> which contains it). The
              in-scope namespaces of that node are used.</para>
            <para>The expression is evaluated in the appropriate context, See <xref
                linkend="xpath-context"/>.</para>
            <para><error code="D0009">It is a <glossterm>dynamic error</glossterm> if the <tag
                  class="attribute">element</tag> attribute on <tag>p:namespaces</tag> is specified
                and it does not identify a single element node.</error>
            </para>
          </listitem>
          <listitem>
            <para>If neither <tag class="attribute">binding</tag> nor <tag class="attribute"
                >element</tag> is specified, the in-scope namespaces on the <tag>p:namespaces</tag>
              element itself are used.</para>
          </listitem>
        </orderedlist><para>Irrespective of how the set of namespaces are determined, the <tag
            class="attribute">except-prefixes</tag> attribute can be used to exclude one or more
          namespaces. The value of the except-prefixes attribute <rfc2119>must</rfc2119> be a
          sequence of tokens, each of which <rfc2119>must</rfc2119> be a prefix bound to a namespace
          in the in-scope namespaces of the <tag>p:namespaces</tag> element. All bindings of
          prefixes to each of the namespaces thus identified are excluded. <error code="S0051">It is
            a <glossterm>static error</glossterm> if the <tag class="attribute"
              >except-prefixes</tag> attribute on <tag>p:namespaces</tag> does not contain a list of
            tokens or if any of those tokens is not a prefix bound to a namespace in the in-scope
            namespaces of the <tag>p:namespaces</tag> element.</error>
        </para>
<para><error code="S0041">It is a <glossterm>static error</glossterm> to specify both
              <tag class="attribute">binding</tag> and <tag class="attribute">element</tag> on the
            same <tag>p:namespaces</tag> element.</error>
        </para>
<para>If a <tag>p:variable</tag>, <tag>p:with-option</tag> or <tag>p:with-param</tag>
          includes one or more <tag>p:namespaces</tag> elements, then the union of all the
          namespaces specified on those elements are used as the bindings for the variable, option
          or parameter value. In this case, the in-scope namespaces on the <tag>p:variable</tag>,
            <tag>p:with-option</tag> or <tag>p:with-param</tag> are ignored. <error code="D0013">It
            is a <glossterm>dynamic error</glossterm> if the specified namespace bindings are
            inconsistent; that is, if the same prefix is bound to two different namespace
            names.</error></para>
<para>For example, this would allow the preceding example to
          work:</para><programlisting><xi:include href="examples/opns-4.xml" parse="text"/></programlisting><para>The
            <tag>p:namespaces</tag> element provides namespace bindings for both of the prefixes
          necessary to correctly interpret the expression ultimately passed to the
            <tag>p:delete</tag> step (the binding for <literal>html:</literal> is explicitly
          provided and the binding for <literal>h:</literal> is in-scope). </para><note>
          <para>The use of <tag>p:namespaces</tag> here, when all of the bindings are provided with
            explicit namespace declarations, is unnecessary. The bindings could simply be placed on
            the parent <tag>p:with-option</tag> element. We use <tag>p:namespaces</tag> here only to
            make the example parallel to the one which follows.</para>
        </note><para>The preceding solution has the weakness that it depends on knowing the bindings
          that will be used by the caller. A more flexible solution would use the <tag
            class="attribute">binding</tag> attribute to copy the bindings from the caller's option
          value.</para><programlisting><xi:include href="examples/opns-5.xml" parse="text"/></programlisting><para>This
          example will succeed as long as the caller-specified option does not bind the
            “<literal>h</literal>” prefix to something other than the XHTML namespace.
        </para></section>
    </section>
    <!-- ============================================================ -->
    <section xml:id="p.declare-step"><title>p:declare-step</title><para>A <tag>p:declare-step</tag>
        provides the type and <glossterm>signature</glossterm> of an <glossterm>atomic
          step</glossterm> or pipeline. It declares the inputs, outputs, and options for all steps
        of that type.</para>
      <e:rng-pattern name="DeclareStep"/>
      <para>The value of the <tag class="attribute">type</tag> can be from any namespace provided
        that the expanded-QName of the value has a non-null namespace URI. <error code="S0025">It is
          a <glossterm>static error</glossterm> if the expanded-QName value of the <tag
            class="attribute">type</tag> attribute is in no namespace or in the XProc
          namespace.</error> Except as described in <xref linkend="versioning-considerations"/>, the
        XProc namespace <rfc2119>must not</rfc2119> be used in the type of steps. Neither users nor
        implementers may define additional steps in the XProc namespace.</para>
<para>Irrespective of
        the context in which the <tag>p:declare-step</tag> occurs, there are initially no option or
        variable names in-scope inside a <tag>p:declare-step</tag>. That is, <tag>p:option</tag> and
          <tag>p:variable</tag> elements can refer to values declared by their preceding siblings,
        but not by any of their ancestors.</para>

<para><impl>When a declared step is evaluated directly by the XProc
processor (as opposed to occurring as an atomic step in some
<glossterm>container</glossterm>), how the input and output ports are
connected to documents is
<glossterm>implementation-defined</glossterm>.</impl></para>

<para>A step declaration is not a <link
linkend="step-concept">step</link> in its own right. Sibling steps
cannot refer to the inputs or outputs of a <tag>p:declare-step</tag>
using <tag>p:pipe</tag>; only instances of the type can be
referenced.</para>

<para>The <tag class="attribute">version</tag> attribute identifies the version
of XProc for which this step declaration was authored. If the
<tag>p:declare-step</tag>
has no ancestors in the XProc namespace, then it <rfc2119>must</rfc2119>
have a <tag class="attribute">version</tag> attribute. 
See <xref linkend="versioning-considerations"/>.</para>

<para>For a description of <tag class="attribute">psvi-required</tag>,
see <xref linkend="psvi-support" />. For <tag
class="attribute">xpath-version</tag>, see <xref
linkend="xpath-context"/>. For <tag
class="attribute">exclude-inline-prefixes</tag>, see
<tag>p:inline</tag>.</para>

<section xml:id="declare-atomic-steps">
        <title>Declaring atomic steps</title>
        <para>When declaring an atomic step, the subpipeline in the declaration
            <rfc2119>must</rfc2119> be empty. And, conversely, if the subpipeline in a declaration
          is empty, the declaration <rfc2119>must</rfc2119> be for an atomic step.</para>
        <para><impl>Implementations may use <glossterm baseform="extension
attribute">extension
              attributes</glossterm> to provide <glossterm>implementation-dependent</glossterm>
            information about a declared step.</impl> For example, such an attribute might identify
          the code which implements steps of this type.</para>
        <para>It is not an error for a pipeline to include declarations for steps that a particular
          processor does not know how to implement. It is, of course, an error to attempt to
          evaluate such steps.</para>
        <para>If <tag>p:log</tag> or <tag>p:serialization</tag> elements appear in the declaration
          of an atomic step, they will only be used if the atomic step is directly evaluated by the
          processor. They have no effect if the step appears in a
          <glossterm>subpipeline</glossterm>; only the serialization options of the “top level” step
          or pipeline are used because that is the only step which the processor is required to
          serialize.</para>
      </section><section xml:id="declare-pipelines">
        <title>Declaring pipelines</title>
        <para>When a <tag>p:declare-step</tag> declares a pipeline, that pipeline encapsulates the
          behavior of the specified <glossterm>subpipeline</glossterm>. Its children declare inputs,
          outputs, and options that the pipeline exposes and identify the steps in its subpipeline. </para>
        <para><impl>The subpipeline may include declarations of additional steps (e.g., other
            pipelines or other step types that are provided by a particular implementation or in
            some <glossterm>implementation-defined</glossterm> way) and import other
            pipelines.</impl> If a pipeline has been imported, it may be invoked as a step within
          the subpipeline that imported it.</para>
        <para>The environment inherited by the <glossterm>subpipeline</glossterm> is the
            <glossterm>empty environment</glossterm> with these modifications:</para>
        <itemizedlist>
          <listitem>
            <para>All of the declared inputs are added to the <glossterm>readable ports</glossterm>
              in the environment.</para>
          </listitem>
          <listitem>
            <para>If a <glossterm>primary input port</glossterm> is declared, that port is the
                <glossterm>default readable port</glossterm>, otherwise the default readable port is
              undefined.</para>
          </listitem>
        </itemizedlist>
        <para>If a <glossterm>primary output port</glossterm> is declared and that port has no
            <glossterm>connection</glossterm>, then it is connected to the <glossterm>primary output
            port</glossterm> of the <glossterm>last step</glossterm> in the
            <glossterm>subpipeline</glossterm>. <error code="S0006">It is a <glossterm>static
              error</glossterm> if the primary output port is unconnected and the <glossterm>last
              step</glossterm> in the subpipeline does not have a primary output
          port.</error></para>
        <para>The requested <tag class="attribute">xpath-version</tag>
          <rfc2119>must</rfc2119> be used to evaluate XPath expressions subject to the constraints
          outlined in <xref linkend="xpath-context"/>.</para>
        <para>The <tag class="attribute">psvi-required</tag> attribute allows the author to declare
          that a step relies on the processor's ability to pass PSVI annotations between steps, see
            <xref linkend="psvi-support"/>. If the attribute is not specified, the value
            “<literal>false</literal>” is assumed. </para>
      </section></section>
    <!-- ============================================================ -->

<section xml:id="p.library"><title>p:library</title><para>A <tag>p:library</tag> is a collection
        of step declarations and/or pipeline definitions.</para>
      <e:rng-pattern name="Library"/>

<para>The <tag class="attribute">version</tag> attribute identifies the version
of XProc for which this library was authored. If the
<tag>p:library</tag>
has no ancestors in the XProc namespace, then it <rfc2119>must</rfc2119>
have a <tag class="attribute">version</tag> attribute. 
See <xref linkend="versioning-considerations"/>.</para>

      <para>For a description of <tag class="attribute">psvi-required</tag>, see <xref
          linkend="psvi-support"/>; for <tag class="attribute">xpath-version</tag>, see <xref
          linkend="xpath-context"/>; for <tag class="attribute">exclude-inline-prefixes</tag>, see
          <tag>p:inline</tag>.</para><note>
        <para>The steps declared in a pipeline library are referred to by their type. It is not an
          error to put a <tag>p:pipeline</tag> or <tag>p:declare-step</tag> without a <tag
            class="attribute">type</tag> in a <tag>p:library</tag>, but there is no standard
          mechanism for instantiating it or referring to it. It is effectively invisible.</para>
      </note><para>Libraries can import pipelines and/or other libraries. 
See also <xref linkend="handling-imports"
      />.</para></section>
    <!-- ============================================================ -->
    <section xml:id="p.import"><title>p:import</title><para>An <tag>p:import</tag> loads a pipeline
        or pipeline library, making it available in the pipeline or library which contains the
          <tag>p:import</tag>.</para>
      <e:rng-pattern name="Import"/>
      <para>An import statement loads the specified IRI and makes any pipelines declared within it
        available to the current pipeline. </para>
<para><error code="S0052">It is a
            <glossterm>static error</glossterm> if the URI of a <tag>p:import</tag> cannot be
          retrieved or if, once retrieved, it does not point to a <tag>p:library</tag>,
            <tag>p:declare-step</tag>, or <tag>p:pipeline</tag>.</error>
        <error code="S0053">It is a <glossterm>static error</glossterm> to import a single pipeline
          if that pipeline does not have a <tag class="attribute">type</tag>.</error>
      </para>
<para>Attempts to retrieve the library identified by the URI value may be redirected at
        the parser level (for example, in an entity resolver) or below (at the protocol level, for
        example, via an HTTP Location: header). In the absence of additional information outside the
        scope of this specification within the resource, the base URI of the library is always the
        URI of the actual resource returned. In other words, it is the URI of the resource retrieved
        after all redirection has occurred.</para>
<para>As imports are processed, a processor may
        encounter new <tag>p:import</tag> elements whose library URI is the same as one it has
        already processed in some other context. This may happen as a consequence of resolving the
        URI. If the actual base URI is the same as one that has already been processed, the
        implementation must recognize it as the same library and should not need to process the
        resource. Also, a duplicate, circular chain of imports, or a re-entrant import is not an
        error and implementations must take the necessary steps to avoid infinite loops and/or
        incorrect notification of duplicate step definitions. It is not an error for a library to
        import itself. An example of such steps is listed in <xref linkend="handling-imports"
        />.</para>
<para>A library is considered the same library if the URI of the resource
        retrieved is the same. If a pipeline or library author uses two different URI values that
        resolve to the same resource, they must not be considered the same imported
        library.</para>

</section>
    <!-- ============================================================ -->
    <section xml:id="p.pipe"><title>p:pipe</title><para>A <tag>p:pipe</tag> connects an input to a
        port on another step.</para>
      <e:rng-pattern name="Pipe"/>
      <para>The <tag>p:pipe</tag> element connects to a readable port of another step. It identifies
        the readable port to which it connects with the name of the step in the <tag
          class="attribute">step</tag> attribute and the name of the port on that step in the <tag
          class="attribute">port</tag> attribute.</para>
<para><error code="S0022">In all cases
          except the <tag>p:output</tag> of a <glossterm>compound step</glossterm>, it is a
            <glossterm>static error</glossterm> if the port identified by a <tag>p:pipe</tag> is not
          in the <glossterm>readable ports</glossterm> of the step that contains the
            <tag>p:pipe</tag>.</error></para>
<para>A <tag>p:pipe</tag> that is a
          <glossterm>connection</glossterm> for an <tag>p:output</tag> of a <glossterm>compound
          step</glossterm> may connect to one of the readable ports of the compound step or to an
        output port on one of the compound step's <glossterm>contained steps</glossterm>. In other
        words, the output of a compound step can simply be a copy of one of the available inputs or
        it can be the output of one of its children.</para></section>
    <section xml:id="p.inline"><title>p:inline</title><para>A <tag>p:inline</tag> provides a
        document inline.</para>
      <e:rng-pattern name="Inline"/>
      <para>The content of the <tag>p:inline</tag> element is wrapped in a document node and passed
        as input. The base URI of the document is the base URI of the <tag>p:inline</tag> element.
          <error code="S0024">It is a <glossterm>static error</glossterm> if the content of the
            <tag>p:inline</tag> element does not consist of exactly one element, optionally preceded
          and/or followed by any number of processing instructions, comments or whitespace
          characters.</error></para>
<para>The in-scope namespaces of the inline document differ from
        the in-scope namespace of the content of the <tag>p:inline</tag> element in that bindings
        for all its <emphasis>excluded namespaces</emphasis>, as defined below, are removed:</para><itemizedlist>
        <listitem>
          <para>The XProc namespace itself (<uri>http://www.w3.org/ns/xproc</uri>) is
            excluded.</para>
        </listitem>
        <listitem>
          <para>A namespace URI designated by using an <tag class="attribute"
              >exclude-inline-prefixes</tag> attribute on the enclosing <tag>p:inline</tag> is
            excluded.</para>
        </listitem>
        <listitem>
          <para>A namespace URI designated by using an <tag class="attribute"
              >exclude-inline-prefixes</tag> attribute on any ancestor <tag>p:declare-step</tag>,
              <tag>p:pipeline</tag>, or <tag>p:library</tag> is also excluded. (In other words, the
            effect of several <tag class="attribute">exclude-inline-prefixes</tag> attributes among
            the ancestors of <tag>p:inline</tag> is cumulative.)</para>
        </listitem>
      </itemizedlist><para>The value of each <tag class="attribute">exclude-inline-prefixes</tag>
        attribute is interpreted as follows:</para>
<para>The value of the attribute is either
          <literal>#all</literal>, or a whitespace-separated list of tokens, each of which is either
        a namespace prefix or <literal>#default</literal>. The namespace bound to each of the
        prefixes is designated as an excluded namespace. <error code="S0057">It is a
            <glossterm>static error</glossterm> if the <tag class="attribute"
            >exclude-inline-prefixes</tag> attribute does not contain a list of tokens or if any of
          those tokens (except <literal>#all</literal> or <literal>#default</literal>) is not a
          prefix bound to a namespace in the in-scope namespaces of the element on which it
          occurs.</error></para>
<para>The default namespace of the element on which <tag
          class="attribute">exclude-inline-prefixes</tag> occurs may be designated as an excluded
        namespace by including <literal>#default</literal> in the list of namespace prefixes. <error
          code="S0058">It is a <glossterm>static error</glossterm> if the value
            <literal>#default</literal> is used within the <tag class="attribute"
            >exclude-inline-prefixes</tag> attribute and there is no default namespace in
          scope.</error>
      </para>

<para>The value <literal>#all</literal> indicates that all namespaces
that are in scope for the element on which <tag
class="attribute">exclude-inline-prefixes</tag> occurs are designated
as excluded namespaces.</para>

<para>The XProc processor <rfc2119>must</rfc2119> include all in-scope
prefixes that are not explicitly excluded. If the namespace associated with
an excluded prefix is used in the expanded-QName of a descendant
element or attribute,
the processor <rfc2119>may</rfc2119> include that prefix anyway, or it may
generate a new prefix.</para>

<para>Consider this example:</para>

<programlisting><xi:include href="examples/exclude-pfx.txt" parse="text"/></programlisting>

<para>which might produce a result like this:</para>

<programlisting><![CDATA[<doc xmlns:c="http://example.com/c">
   <b:part xmlns:b="http://example.com/b"/>
 </doc>]]></programlisting>

<para>The declaration for “<literal>c</literal>” must
be present because it was not excluded. The “<literal>part</literal>” element
uses the namespace bound to “<literal>b</literal>”, so <emphasis>some</emphasis>
binding must be present. In this example, the original
prefix has been preserved, but it would be equally correct if a different
prefix had been used.</para>

</section>
<section xml:id="p.document">
<title>p:document</title>

<para>A <tag>p:document</tag> reads an XML
        document from a URI.</para>
      <e:rng-pattern name="Document"/>
      <para>The document identified by the URI in the <tag class="attribute">href</tag> attribute is
        loaded and returned. If the URI protocol supports redirection, then redirects
          <rfc2119>must</rfc2119> be followed.</para>
<para><error code="D0011">It is a
            <glossterm>dynamic error</glossterm> if the resource referenced by a
            <tag>p:document</tag> element does not exist, cannot be accessed, or is not a
          well-formed XML document.</error>
</para>

<para>The parser which the <tag>p:document</tag> element employs
<rfc2119>must</rfc2119> process the external subset; all general and
external parsed entities <rfc2119>must</rfc2119> be fully expanded. It
<rfc2119>may</rfc2119> perform <tag class="attribute">xml:id</tag>
processing, but it <rfc2119>must not</rfc2119> perform any other
processing, such as expanding XIncludes. The parser
<rfc2119>must</rfc2119> be conformant to <citetitle>Namespaces in
XML</citetitle>. Loading the document <rfc2119>must not</rfc2119>
fail due to validation
errors.</para>

<para>Use the <tag>p:load</tag> step if you need to perform DTD-based
validation.
</para>

<note>
        <para>A <tag>p:document</tag> always <emphasis>reads</emphasis> from the specified IRI. In
          the context of a <tag>p:input</tag>, this seems perfectly natural. In the context of a
            <tag>p:output</tag>, this may seem a little asymmetrical. Putting a
            <tag>p:document</tag> in a <tag>p:output</tag> causes the pipeline to
            <emphasis>read</emphasis> from the specified IRI and provide that document <emphasis>as
            an output</emphasis> on that port. </para>
        <para>Use <tag>p:store</tag> to store the results that appear on a
          <tag>p:output</tag>.</para>
      </note></section>

<section xml:id="p.data">
<title>p:data</title>

<para>A <tag>p:data</tag> reads an arbitrary resource from a
URI.</para>

<e:rng-pattern name="Data"/>

<para>The resource identified by the URI in the <tag
class="attribute">href</tag> attribute is loaded, encoded, wrapped in
the wrapper element, and returned as a document. If the URI protocol
supports redirection, then redirects <rfc2119>must</rfc2119> be
followed.</para>

<para>The value of the <tag class="attribute">wrapper</tag> attribute
<rfc2119>must</rfc2119> be a <type>QName</type>. If the lexical value
does not contain a colon, then the <tag class="attribute">wrapper-namespace</tag>
may be used to specify the namespace of the wrapper. In that case, the
<tag class="attribute">wrapper-prefix</tag> may be specified to suggest a
prefix for the wrapper element.
<error code="D0034">It is a <glossterm>dynamic error</glossterm>
to specify a new namespace or prefix if the lexical value of the specified
name contains a colon (or if no <tag class="attribute">wrapper</tag> is
explicitly specified).</error></para>

<para>In other words, these two <tag>p:data</tag> elements produce
equivalent wrappers:</para>

<programlisting><![CDATA[<p:data href="..."
        xmlns:x="http://example.com/ns/"
        wrapper="x:wrap"/>
<p:data href="..."
        wrapper="wrap" wrapper-prefix="x"
        wrapper-namespace="http://example.com/ns/"/>]]></programlisting>

<para>but this <tag>p:data</tag> element will raise an error:</para>

<programlisting><![CDATA[<p:data href="..."
        xmlns:x="http://example.com/ns/"
        wrapper="x:wrap" wrapper-prefix="x"
        wrapper-namespace="http://example.com/ns/"/>]]></programlisting>

<para>If no wrapper element is specified, the default is
<tag>c:data</tag>:</para>

<e:rng-pattern name="VocabData"/>

<para><error code="D0029">It is a <glossterm>dynamic error</glossterm>
if the document referenced by a <tag>p:data</tag> element does not
exist, cannot be accessed, or cannot be encoded as specified.</error>
</para>

<para>Exactly how the data is encoded depends on the media type of the
resource. If the resource has a content type associated with it (e.g.,
if the resource was retrieved with HTTP), then that content type
<rfc2119>must</rfc2119> be used, otherwise, if the user specified a
<tag class="attribute">content-type</tag> on the <tag>p:data</tag>,
then that content type should be assumed. <impl>If no content type was
specified or is associated with the resource, the inferred content
type is <glossterm>implementation-dependent</glossterm>.</impl>
</para>

<itemizedlist>
  <listitem>
    <para>If the media type of the response is an XML media type or
    text type with a <literal>charset</literal> parameter that is a
    Unicode character encoding (per <biblioref
    linkend="unicodetr17"/>) or is recognized as a non-XML media type
    whose contents are encoded as a sequence of Unicode characters
    (e.g. it has a <literal>charset</literal> parameter or the
    definition of the media type is such that it requires Unicode),
    the data <rfc2119>must</rfc2119> be encoded as Unicode character
    sequence.</para>
  </listitem>
  <listitem>
    <para>If the media type is not an appropriate text type, or if the
    processor does not recognize the media type, the content is
    base64-encoded.</para>
  </listitem>
  </itemizedlist>

<para>The resulting data is wrapped in an element with the name
specified in the <tag class="attribute">wrapper</tag> attribute (or
<tag>c:data</tag> if no <tag class="attribute">wrapper</tag> is
specified).</para>

<para>Implementations <rfc2119>should</rfc2119> add a
<tag class="attribute">content-type</tag> attribute to
the wrapper element which indicates the
specified or inferred media type of the resource (including any
parameters). If the content was base64-encoded, the wrapper
<rfc2119>must</rfc2119> have an <tag class="attribute" >encoding</tag>
attribute which specifies “<literal>base64</literal>”.</para>

<para>If an <tag class="attribute">encoding</tag> is specified, a <tag
class="attribute">charset</tag> may also be specified. The character
set may be specified as a parameter on the
<tag class="attribute">content-type</tag> or via the
separate <tag class="attribute">charset</tag> option.
If it is specified in both places, the values <rfc2119>must</rfc2119>
be consistent.</para>

<para>If <tag class="attribute">content-type</tag>,
<tag class="attribute">encoding</tag>, or <tag class="attribute">charset</tag>
attributes are specified on a
<tag>c:data</tag> wrapper, they <rfc2119>must not</rfc2119> be in a
namespace; if the user-specified wrapper is not <tag>c:data</tag>,
then the attributes <rfc2119>must</rfc2119> be in the
<uri type="xmlnamespace" >http://www.w3.org/ns/xproc-step</uri>
namespace.</para>

<para>Implementations may record additional details in <link
linkend="extension-attributes">extension attributes</link>.</para>

<para>For example, this <tag>p:identity</tag> step:</para>

<programlisting><xi:include href="examples/file.txt" parse="text"/></programlisting>

<para>might produce output like this:</para>

<programlisting>&lt;c:data xmlns:c="http://www.w3.org/2007/03/xproc-step"
        content-type="text/plain"&gt;
AL,Alabama
AK,Alaska
AZ,Arizona
…
&lt;/c:data&gt;</programlisting>

<para>Whereas this pipeline fragment:</para>

<programlisting><xi:include href="examples/filebin.txt" parse="text"/></programlisting>

<para>produces a single <tag>img</tag> element with an inline graphic
(represented using a <literal>data:</literal> URI):</para>

<programlisting>&lt;img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1QsEDycHOWjhgQAAAB10RVh0Q29tbWVudABDcmVhdGVk
IHdpdGggVGhlIEdJTVDvZCVuAAABjklEQVQ4y42Tv0tbcRTFz3t5kuQFwUVFEYIGU6q4mU0RlCDR
qYO2g4gdghUyKSFDwD/AwS2IoIMSHOLgpOLg4CIOWdy76GBoqQUJLlr66aCW6LuoF+7wvefcc3/w
vZLgpbe0wOoqn/Ro5TKRVIpLi6tkkpoFpFJUj48JSVI2y4LnBTm+D1paYqa5OQiGw5DN8nV7m1hv
L99f4o4Dk5Mc6Pwcd2yMXauL/n5+FAqsWdXjca5LJbokSXt7fOzu5toSaWsLxpqaIJcjr0ZbXGQh
HDaWZPjQEGc7O3jPBC4u8EZHOXkruaODPxsbDMuylRWSra3cviYwO0upMcdtfNRqGq/X5esVu7nR
BxMol4knEtTfGsH3+bu8zLdnydUqXjrN/nsWKEEiwdXmJp3/BYpFctFokOi6EIsF444DU1McSZLW
1+nq6eGnVWlkhNrcHBXXNUe5z+f5rEyGA8cxD+pufp7BYtH+yhL09fFbkYjd4vQ0W08jFgp8se7l
wY3gwAC/KhXanwROTwlNTHBocf8BTQe7F9dc2bMAAAAASUVORK5CYII="/&gt;</programlisting>

<para>Some steps, such as <tag>p:xquery</tag> and
<tag>p:validate-with-relax-ng</tag>, are designed to process non-XML
inputs. If a base64-encoded input occurs in such a context, it
<rfc2119>should</rfc2119> be decoded before processing. In this way,
for example, an XQuery document can be read with <tag>p:data</tag> and
passed to the <tag>p:xquery</tag> step without regard to how the data
was encoded.</para>

</section>


    <section xml:id="p.empty"><title>p:empty</title><para>A <tag>p:empty</tag> connects to an
          <glossterm>empty sequence</glossterm> of documents.</para>
      <e:rng-pattern name="Empty"/>
    </section>
    <section xml:id="p.documentation"><title>p:documentation</title><para>A
          <tag>p:documentation</tag> contains human-readable documentation.</para>
      <e:rng-pattern name="Documentation"/>
      <para>There are no constraints on the content of the <tag>p:documentation</tag> element.
        Documentation is ignored by pipeline processors. See <xref linkend="documentation"/>.
      </para></section>
    <section xml:id="p.pipeinfo"><title>p:pipeinfo</title><para>A <tag>p:pipeinfo</tag> contains
        ancillary information for steps in the pipeline.</para>
      <e:rng-pattern name="PipeInfo"/>
      <para>There are no constraints on the content of the <tag>p:pipeinfo</tag> element, see <link
          linkend="annotations"/>.</para></section>
  </section>
  <section xml:id="errors">
    <title>Errors</title>
    <para>Errors in a pipeline can be divided into two classes: static errors and dynamic
      errors.</para>
    <section xml:id="static-errors">
      <title>Static Errors</title>
      <para><termdef xml:id="dt-static-error">A <firstterm>static error</firstterm> is one which can
          be detected before pipeline evaluation is even attempted.</termdef> Examples of static
        errors include cycles and incorrect specification of inputs and outputs. </para>
      <para>Static errors are fatal and must be detected before any steps are evaluated.</para>
      <para>For a complete list of static errors, see <xref linkend="app.static-errors"/>.</para>
    </section>
    <section xml:id="dynamic-errors">
      <title>Dynamic Errors</title>
      <para>A <termdef xml:id="dt-dynamic-error">A <firstterm>dynamic error</firstterm> is one which
          occurs while a pipeline is being evaluated.</termdef> Examples of dynamic errors include
        references to URIs that cannot be resolved, steps which fail, and pipelines that exhaust the
        capacity of an implementation (such as memory or disk space).</para>
      <para>If a step fails due to a dynamic error, failure propagates upwards until either a
          <tag>p:try</tag> is encountered or the entire pipeline fails. In other words, outside of a
          <tag>p:try</tag>, step failure causes the entire pipeline to fail.</para>
      <para>For a complete list of dynamic errors, see <xref linkend="app.dynamic-errors"/>.</para>
    </section>
    <section xml:id="step-errors">
      <title>Step Errors</title>
      <para>Several of the steps in the standard and option step library can generate dynamic
        errors.</para>
      <para>For a complete list of the dynamic errors raised by builtin pipeline steps, see <xref
          linkend="app.step-errors"/>.</para>
    </section>
  </section>
  <xi:include href="standard-components.xml"/>
  <xi:include href="conformance.xml"/>
  <xi:include href="references.xml"/>
  <xi:include href="glossary.xml"/>
  <xi:include href="language-summary.xml"/>
  <xi:include href="error-codes.xml"/>
  <xi:include href="namespace-fixup.xml"/>
  <appendix xml:id="handling-imports">
    <title>Handling Circular and Re-entrant Library Imports (Non-Normative)</title>
    <para>When handling imports, an implementation needs to be able to detect the following
      situations, and distinguish them from cases where multiple import chains produce genuinely
      conflicting step definitions:</para>
    <orderedlist>
      <listitem>
        <para>Circular imports: A imports B, B imports A.</para>
      </listitem>
      <listitem>
        <para>Re-entrant imports: A imports B and C, B imports D, C imports D.</para>
      </listitem>
    </orderedlist>
    <para>One way to achieve this is as follows:</para>
    <para><termdef xml:id="dt-step-type-exports">The <firstterm>step type exports</firstterm> of an
        XProc element, against the background of a set of URIs of resources already visited (call
        this set <emphasis>Visited</emphasis>), are defined by cases.</termdef></para>
    <para>The <link linkend="dt-step-type-exports">step type exports</link> of an XProc element are
      as follows:</para>
    <variablelist>
      <varlistentry>
        <term>p:pipeline, p:declare-step</term>
        <listitem>
          <para>A singleton bag containing the <code>type</code> of the element</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>p:library</term>
        <listitem>
          <para>The <glossterm>bag-merger</glossterm> of the <glossterm>step type
              exports</glossterm> of all the element's children</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>p:import</term>
        <listitem>
          <para>Let <emphasis>RU</emphasis> be the actual resolved URI of the resource identified by
            the <code>href</code> of the element. If <emphasis>RU</emphasis> is a member of
              <emphasis>Visited</emphasis>, then an empty bag, otherwise update
              <emphasis>Visited</emphasis> by adding <emphasis>RU</emphasis> to it, and return the
              <glossterm>step type exports</glossterm> of the document element of the retrieved
            representation</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>all other elements</term>
        <listitem>
          <para>An empty bag</para>
        </listitem>
      </varlistentry>
    </variablelist>
    <para>The changes to <emphasis>Visited</emphasis> mandated by the <code>p:import</code> case
      above are persistent, not scoped. That is, not only the recursive processing of the imported
      resource but also subsequent processing of siblings and ancestors must be against the
      background of the updated value. In practice this means either using a side-effected global
      variable, or not only passing <emphasis>Visited</emphasis> as an argument to any recursive or
      iterative processing, but also <emphasis>returning</emphasis> its updated value for subsequent
      use, along with the bag of step types.</para>
    <para>Given a pipeline library document with actual resolved URI <emphasis>DU</emphasis>, <error
        code="S0036">it is a <glossterm>static error</glossterm> if the <glossterm>step type
          exports</glossterm> of the document element of the retrieved representation, against the
        background of a singleton set containing <emphasis>DU</emphasis> as the initial
          <emphasis>Visited</emphasis> set, contains any duplicates.</error></para>
    <para>Given a top-level pipeline document with actual resolved URI <emphasis>DU</emphasis>,
        <error code="S0036">it is a <glossterm>static error</glossterm> if the
          <glossterm>bag-merger</glossterm> of the <glossterm>step type exports</glossterm> of the
        document element of the retrieved representation with the <glossterm>step type
          exports</glossterm> of its children, against the background of a singleton set containing
          <emphasis>DU</emphasis> as the initial <emphasis>Visited</emphasis> set, contains any
        duplicates.</error></para>
    <para>Given a non-top-level <code>p:pipeline</code> or <code>p:declare-step</code> element,
        <error code="S0036">it is a <glossterm>static error</glossterm> if the
          <glossterm>bag-merger</glossterm> of the <glossterm>step type exports</glossterm> of its
        parent with the <glossterm>step type exports</glossterm> of its children, against the
        background of a copy of the <emphasis>Visited</emphasis> set of its parent as the initial
          <emphasis>Visited</emphasis> set, contains any duplicates.</error></para>
    <para>The phrase "a copy of the <emphasis>Visited</emphasis> set" in the preceding paragraph is
      meant to indicate that checking of non-top-level <code>p:pipeline</code> or
        <code>p:declare-step</code> elements does <emphasis>not</emphasis> have a persistent impact
      on the checking of its parent. The contrast is that whereas changes to
        <emphasis>Visited</emphasis> pass both up <emphasis>and</emphasis> down through
        <code>p:import</code>, they pass only <emphasis>down</emphasis> through
        <emphasis>p:pipeline</emphasis> and <emphasis>p:declare-step</emphasis>.</para>
    <para><termdef xml:id="dt-bag-merger">The <firstterm>bag-merger</firstterm> of two or more bags
        (where a bag is an unordered list or, equivalently, something like a set except that it may
        contain duplicates) is a bag constructed by starting with an empty bag and adding each
        member of each of the input bags in turn to it. It follows that the cardinality of the
        result is the sum of the cardinality of all the input bags.</termdef></para>
  </appendix>
  <xi:include href="parallel.xml"/>
  <xi:include href="mediatype.xml"/>
</specification>
