<?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?>
-->
<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="wd" version="5.0-extension w3c-xproc">
<info>
<title>XProc: An XML Pipeline Language</title>
<w3c-shortname>xproc</w3c-shortname>
<pubdate>2007-07-06</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/2007/WD-xproc-20070405/"/>
<bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2006/WD-xproc-20061117/"/>
<bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2006/WD-xproc-20060928/"/>

<authorgroup>
  <author>
    <personname>Norman Walsh</personname>
    <affiliation>
      <orgname>Sun Microsystems, Inc.</orgname>
    </affiliation>
    <email>Norman.Walsh@Sun.COM</email>
  </author>
  <author>
    <personname>Alex Milowski</personname>
    <affiliation>
      <orgname>Invited expert</orgname>
    </affiliation>
    <email>alex@milowski.org</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 one or more XML documents. Pipelines generally accept one
or more XML documents as input and producing one or more XML documents
as output, though they are not required to do so. Some pipelines are
entirely self-contained, starting with input derived inside the
pipeline and producing no XML output.</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 document was produced by the
<link xlink:href="http://www.w3.org/XML/Processing/">XML Processing Model Working Group</link>
which is part of the
<link xlink:href="http://www.w3.org/XML/Activity">XML Activity</link>.
Publication as a Working Draft 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 is a public Working Draft. This draft addresses many, but
not all, of the design questions that were incomplete in previous
drafts. The library of standard steps, both required and optional, is
still being reviewed and considered. The Working Group continues to
encourage feedback from potential users. A revision marks draft, with
respect to the 5 April 2007 specification, has been provided, though
it is not obviously of great value due to editorial reorganization of
the material.</para>

<para>The most significant changes in this draft are: a new mechanism
for dealing with parameters, new defaulting rules for primary input and
output ports, and revisions to the standard step library.</para>

<para>Please send comments about this document to
<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 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 pipeline consists of steps. Like
pipelines, steps take zero or more XML documents as their input
and produce zero or more XML documents as their output. The inputs to
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 two kinds of steps: atomic steps and compound
steps. Atomic steps carry out single operations and have no
substructure as far as the pipeline is concerned, whereas compound steps
include a subpipeline of steps within themselves.</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. The pipeline itself has two inputs, “Document” and “Schema”.
How these inputs are connected to XML documents outside the pipeline
is <glossterm>implementation-defined</glossterm>.
The XInclude step reads the pipeline input “Document” and produces a result
document. The Validate step reads the pipeline input “Schema” and
the output from the XInclude step and produces a
result document. The result of the validation, “Result Document”,
is the result of the pipeline.
How pipeline outputs are connected to XML documents outside the pipeline is
<glossterm>implementation-defined</glossterm>.</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>&lt;p:pipeline name="fig1" xmlns:p="http://www.w3.org/2007/03/xproc"&gt;
  &lt;p:input port="source" primary="yes"/&gt;
  &lt;p:input port="schemaDoc" sequence="yes" primary="no"/&gt;
  &lt;p:output port="result"/&gt;

  &lt;p:xinclude/&gt;

  &lt;p:validate-xml-schema&gt;
    &lt;p:input port="schema"&gt;
      &lt;p:pipe step="fig1" port="schemaDoc"/&gt;
    &lt;/p:input&gt;
  &lt;/p:validate-xml-schema&gt;
&lt;/p:pipeline&gt;
</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>&lt;p:pipeline xmlns:p="http://www.w3.org/2007/03/xproc"&gt;

  &lt;p:documentation xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;div&gt;
      &lt;p&gt;This is documentation&lt;/p&gt;
    &lt;/div&gt;
  &lt;/p:documentation&gt;

  &lt;p:choose&gt;
    &lt;p:when test="/*[@version &amp;lt; 2.0]"&gt;
      &lt;p:validate-xml-schema name="val1"&gt;
	&lt;p:input port="schema"&gt;
	  &lt;p:document href="v1schema.xsd"/&gt;
	&lt;/p:input&gt;
      &lt;/p:validate-xml-schema&gt;
    &lt;/p:when&gt;

    &lt;p:otherwise&gt;
      &lt;p:validate-xml-schema name="val2"&gt;
	&lt;p:input port="schema"&gt;
	  &lt;p:document href="v2schema.xsd"/&gt;
	&lt;/p:input&gt;
      &lt;/p:validate-xml-schema&gt;
    &lt;/p:otherwise&gt;
  &lt;/p:choose&gt;

  &lt;p:xslt name="xform"&gt;
    &lt;p:input port="stylesheet"&gt;
      &lt;p:document href="stylesheet.xsl"/&gt;
    &lt;/p:input&gt;
  &lt;/p:xslt&gt;
&lt;/p:pipeline&gt;
</programlisting>
</example>

</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, outputs flowing into inputs, without any loops (no step can
read its own output, directly or indirectly).</termdef>
A pipeline is itself a
<glossterm>step</glossterm> and must satisfy the constraints on
steps.</para>

<para>The result of evaluating a pipeline is the result of evaluating
the steps that it contains, in the order determined by the connections
between them. A pipeline must behave as if it
evaluated each step each time it occurs. Unless otherwise
indicated, implementations <rfc2119>must not</rfc2119> assume that
steps are functional (that is, that their outputs depend only on
their explicit inputs, options, and parameters) or side-effect free.</para>

<section xml:id="stages">
<title>Steps</title>

<para><termdef xml:id="dt-step">A <firstterm>step</firstterm> is the
basic computational unit of a pipeline. Steps are either atomic or
compound.</termdef> <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 subpipeline.</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;
an XML Schema Validation step validates one input with respect to some
set of XML Schemas, etc.</para>

<para>There are many types of atomic steps. The standard library of
atomic steps is described in <xref linkend="std-components"/>, but
implementations may provide others as well. 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 additional steps. 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.</termdef></para>

<para>Every compound step contains one or more steps.
<termdef xml:id="dt-contained-steps">The steps that occur
directly inside a compound step
are called <firstterm>contained steps</firstterm>.</termdef>
<termdef xml:id="dt-container">A compound step which immediately
contains another step is called its <firstterm>container</firstterm>.</termdef>
</para>

<para><termdef xml:id="dt-subpipeline">The steps (and the
connections between them) within a compound step form a
<firstterm>subpipeline</firstterm>.</termdef>
<termdef xml:id="dt-last-step">The <firstterm>last step</firstterm> in a
subpipeline is the last step in document order within its container.
</termdef></para>

<para>A compound step can contain one or more subpipelines and it
determines how and which of its subpipelines are evaluated.</para>

<para>Steps have “ports” into which inputs and outputs are connected
or “bound”. Each step has a number of input ports and a number of
output ports, all with unique names. 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.)
</para>

<para>Steps have any number of options, all with unique names.
A step can have zero options.</para>

<para>Steps may have access to any number of parameters, all with
unique names. A step can have zero parameters.</para>
</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. Each XML document (or document in a sequence) must conceptually be
an <biblioref linkend="xml-infoset-rec"/> with a <emphasis>Document
Information Item</emphasis> at its root. The inputs and outputs can be
implemented as sequences of characters, events, or object models, or any other
representation the implementation chooses.</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>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 file cannot arrive
on an input port to a step.</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 atomic step 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 defines the input ports, output ports,
and options of all steps of that type. For example, every
<tag>p:xslt</tag> step has two inputs, named
“<literal>source</literal>” and “<literal>stylesheet</literal>”, and
one output named “<literal>result</literal>” and the same set of options.
</para>

<para>The situation is slightly more complicated for compound steps
because they don't have separate declarations; each instance of a
compound step serves as its own declaration. Compound steps don't have
declared inputs, but they do have declared outputs, and unlike atomic
steps, on 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 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, connections
are made to all of its inputs and outputs.
</para>

<para>When a step is used, all of the <glossterm>declared
inputs</glossterm> of the step must be connected. Each input may 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 the top-level <tag>p:pipeline</tag> step.
</para>
</listitem>
</itemizedlist>

<para>When an input accepts a sequence of documents, it may have one
or more bindings to any of those locations.</para>

<para>All of the <glossterm>declared outputs</glossterm> of a step
must be connected. Outputs may be connected to:</para>

<itemizedlist>
<listitem>
<para>The input port of some other step.</para>
</listitem>
<listitem>
<para>One of the outputs declared on the top-level <tag>p:pipeline</tag> step.
</para>
</listitem>
</itemizedlist>

<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 compound step itself, they are inputs into which
something must 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>Each input and output 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><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> Each
atomic step (e.g. XSLT or XInclude) has a fixed signature, declared
globally or built-in, which all its instances share, whereas each
compound step has its own implicit signature.</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 appear on a special “error output” port defined
(only)
in the catch clause of a <link linkend="p.try">try/catch</link>.
Outside of a <link linkend="p.try">try/catch</link>, the disposition of error
messages is <glossterm>implementation-dependent</glossterm>.
</para>
</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 exactly
one input port, or if one of its input ports is explicitly designated
as the primary, 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 designated as
<emphasis>not</emphasis> being the primary input port, or if a step has more than
one input port and none is explicitly designated the primary, then the
primary input port of that step is undefined.</para>

<para><termdef xml:id="dt-primary-output-port">If a step has exactly
one output port, or if one of its output ports is explicitly
designated as the primary, 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 designated as
<emphasis>not</emphasis> being the primary, or if a step has more than
one output port and none is explicitly designated the primary, then the
primary output port of that step is undefined.</para>

<para>The special significance of primary input and output ports is
that they are connected automatically by the processor if no
explicit binding 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 <glossterm>compound step</glossterm> has no
declared inputs and the first step in its subpipeline has an unbound
primary input, then an implicit (and unnamed) primary input port will
be added to the compound step. If a compound step has no declared
outputs and the last step in its subpipeline has an unbound primary
output, then an implicit (and also unnamed) primary output port will
be added to the compound step.</para>

<para>The practical consequence of these rules is that
straightforward, linear pipelines are much simpler to read, write, and
understand. The following pipeline has a single input which is
transformed by the XSLT step; the result of that XSLT step is the
result of the pipeline:</para>

<programlisting>&lt;p:pipeline xmlns:p="http://www.w3.org/2007/03/xproc"&gt;
&lt;p:xslt&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:document href="docbook.xsl"/&gt;
  &lt;/p:input&gt;
&lt;/p:xslt&gt;
&lt;/p:pipeline&gt;
</programlisting>

<para>It is semantically equivalent to this pipeline:</para>

<programlisting>&lt;p:pipeline name="main" xmlns:p="http://www.w3.org/2007/03/xproc"&gt;
&lt;p:input port="source"/&gt;
&lt;p:input port="result"&gt;
  &lt;p:pipe step="transform" port="result"/&gt;
&lt;/p:input&gt;

&lt;p:xslt name="transform"&gt;
  &lt;p:input port="source"&gt;
    &lt;p:pipe step="main" port="source"/&gt;
  &lt;/p:input&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:document href="docbook.xsl"/&gt;
  &lt;/p:input&gt;
&lt;/p:xslt&gt;

&lt;/p:pipeline&gt;
</programlisting>
</section>

<section xml:id="options">
<title>Options</title>

<para>Some steps accept options. Options are name/value pairs.</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.</termdef>
If a document, node, or other value is given, its
<biblioref linkend="xpath"/> string value
is computed and that string is used.
</para>

<para><termdef xml:id="dt-declared-options">The options declared on a
step are its <firstterm>declared options</firstterm>.</termdef>
All of the options specified on an atomic step must have been declared.
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:option</tag> element specifies
a value or because the declaration included a default value,
are its <firstterm>specified options</firstterm>.</termdef>
</para>
</section>

<section xml:id="parameters">
<title>Parameters</title>

<para>Some steps accept parameters. Parameters are name/value pairs.</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.</termdef>
If a document, node, or other value is given, its
<biblioref linkend="xpath"/> string value
is computed and that string is used.
</para>

<para>Unlike 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 with
<link linkend="parameter-inputs">parameter inputs</link>.</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>

<section xml:id="environment">
<title>Environment</title>

<para><termdef xml:id="dt-environment">The
<firstterm>environment</firstterm> of a step is the static information
available to each instance of a step in a pipeline.</termdef></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 the step name/output
port name pairs that are visible to the step.</termdef>
Inputs and outputs can only be connected to
readable ports.</para>
</listitem>
<listitem>
<para>A set of in-scope options.
<termdef xml:id="dt-in-scope-options">The
<firstterm>in-scope options</firstterm> are the set of options that
are visible to a step.</termdef> All of the in-scope options are
available to the processor for computing option and parameter values.
The actual options passed to a step are those that are declared for a
step of its type and that have values either provided explicitly with
<tag>p:option</tag> elements on the step or as defaults in the
declaration of the step.</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 ignored namespaces.
<termdef xml:id="dt-ignored-namespaces">The set of <firstterm>ignored
namespaces</firstterm> are the namespaces which do not identify steps.</termdef>
</para>
</listitem>
-->
</orderedlist>

<para><termdef xml:id="dt-empty-environment">The
<firstterm>empty environment</firstterm> contains no readable ports,
no in-scope options, and an undefined default readable port.
<!--, and an
empty set of ignored namespaces.--></termdef>
</para>

<para>Unless otherwise specified, the environment of a contained step 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>

<itemizedlist>
<listitem>
<para>All of the <glossterm>specified options</glossterm> of the
<glossterm>container</glossterm> are added to the
<glossterm>in-scope options</glossterm>. The value of any option
in the environment with the same name as one of the options specified on
the container is
shadowed by the new value.</para>
<para>In other words, steps can access the most recently specified value of
all of the options specified on
any ancestor step.</para>
</listitem>
<listitem>
<para>The union of all the declared outputs of all of the step's sibling
<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,
the <glossterm>default readable port</glossterm> is unchanged.</para>
</listitem>
</itemizedlist>

<para>A step with no parent inherits the <glossterm>empty environment</glossterm>.
</para>

<!--
<para>Unless otherwise specified, the
<phrase xml:id="dt-inherited-environment">inherited environment</phrase> for
the <link linkend="dt-contained-steps">contained steps</link> of a
compound step is the
<phrase xml:id="dt-standard-inheritance">standard inheritance</phrase>, which
is the environment of that <glossterm>compound step</glossterm>,
with the following modification:</para>

<itemizedlist>
<listitem>
<para>The union of all the declared outputs of the
<glossterm>contained steps</glossterm> are added to the
<glossterm>readable ports</glossterm> in the environment.</para>
</listitem>
</itemizedlist>

<para>In other words, sibling steps can see each other's outputs
in addition to the outputs of their ancestors.</para>
-->
</section>

<section xml:id="xpath-extension-functions">
<title>XProc Extension Functions for XProc</title>

<para>The XProc processor must support a few additional functions in XPath
expressions evaluated by the processor.</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. Four aspects of the processor
are exposed through the <function>p:system-property</function> function
in the pipeline namespace:</para>

<para>Function: <type>String</type> <function>p:system-property</function>(<type>String</type> <varname>property</varname>)</para>

<para>The <varname>property</varname> string must 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: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.</para>
<para>The unique identifier must consist of ASCII alphanumeric characters and must
start with an alphabetic character. Thus, the string is syntactically an XML
name.</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 of XProc implemented by the processor; for processors 
implementing the version of XProc specified by this document, the number is “1.0”.</para>
<para>The value will always be a string in the lexical space of the decimal data
type defined in <biblioref linkend="xmlschema-2"/>. This allows the value to be
converted to a number for the purpose of magnitude comparisons.</para>
</listitem>
</varlistentry>
</variablelist>
</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>

<para>Function: <type>Boolean</type> <function>p:step-available</function>(<type>String</type> <varname>step-type</varname>)</para>

<para>The <varname>step-type</varname> string must 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.iteration-count">
<title>Iteration Count</title>

<para>In the context of a <tag>p:for-each</tag> or a <tag>p:viewport</tag>,
the <function>p:iteration-count</function> function reports the number of
iterations that have occurred. In the context of other standard XProc
compound steps, it returns 1.</para>

<para>Function: <type>Integer</type> <function>p:iteration-count</function>()</para>

<para>In the context of an extension compound step, the value is
<glossterm>implementation-defined</glossterm>.</para>

</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.
</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,</simpara>
</listitem>
<listitem>
<simpara>Output ports,</simpara>
</listitem>
<listitem>
<simpara>Options, and</simpara>
</listitem>
<listitem>
<simpara>Parameters</simpara>
</listitem>
</orderedlist>

<section xml:id="namespaces">
<title>XProc Namespaces</title>

<para>The XML syntax for XProc uses three namespaces:</para>

<variablelist>
<varlistentry>
<term><uri type="xmlnamespace">http://www.w3.org/2007/03/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/2007/03/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/2007/03/xproc-error</uri></term>
<listitem>
<para>The namespace used for error reporting. When a step fails inside a
<tag>p:try</tag>, it may produce error messages that can be inspected in the
<tag>p:catch</tag>. The error namespace is used for those messages.
The conventional
prefix “<literal>err:</literal>” is used for this namespace.</para>
</listitem>
</varlistentry>
</variablelist>
</section>

<section xml:id="scoping">
<title>Scoping of Names</title>

<para>The scope of the names of step types is the pipeline. Each pipeline
processor has some number of built in step types and may declare
(directly, or by reference to an external library) additional step types.
</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 its ancestor's siblings are all in the same scope.
<error code="S0002">All in-scope steps <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 names is essentially the same as the scope
of step names, with the following caveat: whereas step names
must be unique, option names may be repeated. An option specified on a
step shadows any specification that may already be in-scope.</para>

<para>Parameter names are not scoped; they are distinct on each step.</para>
</section>

<section xml:id="global-attributes">
<title>Global Attributes</title>

<para>The following attributes <rfc2119>may</rfc2119> appear on any element
in a pipeline:</para>

<itemizedlist>
<listitem>
<para>The attribute <tag>xml:id</tag> with the semantics outlined in
<biblioref linkend="xml-id"/>.</para>
</listitem>
<listitem>
<para>The attribute <tag>xml:base</tag> with the semantics outlined in
<biblioref linkend="xml-base"/>.</para>
</listitem>
</itemizedlist>

<!--
<para>The following attributes <rfc2119>may</rfc2119> appear on any step
element:</para>

<itemizedlist>
<listitem>
<para>The attribute <tag>p:ignore-prefixes</tag> with the semantics outlined
in <xref linkend="p.ignore-prefixes"/>.</para>
</listitem>
</itemizedlist>
-->
</section>

<section xml:id="syntax-docs-ports">
<title>Associating Documents with Ports</title>

<para><termdef xml:id="dt-binding">A <firstterm>binding</firstterm> associates an input
or output port with some data source.</termdef>
A document or a sequence of documents can be bound to a port in
four ways: by source, by URI, by providing it inline, or by making it explicitly empty.
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> 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>&lt;p:identity name="otherstep"&gt;
  &lt;p:input port="source"&gt;
    &lt;p:document href="http://example.com/input.xml"/&gt;
  &lt;/p:input&gt;
&lt;/p:identity&gt;
</programlisting>

<para><error code="D0002">It is a <glossterm>dynamic error</glossterm> if the processor
attempts to retrieve the URI specified on a <tag>p:document</tag>
and fails.</error> (For example, if the
resource does not exist or is not accessible with the user's
authentication credentials.)</para>
</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>document</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>&lt;p:xinclude name="expand"&gt;
  &lt;p:input port="source"&gt;
    &lt;p:pipe step="otherstep" port="result"/&gt;
  &lt;/p:input&gt;
&lt;/p:xinclude&gt;
</programlisting>

<para>When a <tag>p:pipe</tag> is used, the specified port must be
in the <glossterm>readable ports</glossterm> of the current environment.
<error code="S0003">It is a <glossterm>static error</glossterm> if the port specified by a
<tag>p:pipe</tag> is not in the <glossterm>readable ports</glossterm> of the
environment.</error></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 that binds it.</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>&lt;p:xslt name="xform"&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:inline&gt;
      &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                      version="1.0"&gt;
        ...
      &lt;/xsl:stylesheet&gt;
    &lt;/p:inline&gt;
  &lt;/p:input&gt;
&lt;/p:xslt&gt;
</programlisting>

<para>Inline documents are considered “quoted”, they are not
interpolated or available to the pipeline processor in any way except
as documents flowing through the pipeline.</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>&lt;p:xslt2 name="generate"&gt;
  &lt;p:input port="source"&gt;
    &lt;p:empty/&gt;
  &lt;/p:input&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:inline&gt;
      &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                      version="2.0"&gt;
        ...
      &lt;/xsl:stylesheet&gt;
    &lt;/p:inline&gt;
  &lt;/p:input&gt;
  &lt;p:option name="template-name" value="someName"/&gt;
&lt;/p:xslt2&gt;
</programlisting>

<para>If you omit the binding on a primary input port, a binding to the
<glossterm>default readable port</glossterm> will be assumed. Making the
binding explicitly empty guarantees that the binding will be to an empty
sequence of documents.</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>,
or <tag>p:inline</tag>
element. If more than one <glossterm>binding</glossterm> is provided, then the 
specified sequence of documents is made available on that port in the same
order as the bindings.</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.)</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 <link linkend="extension-elements">extension elements</link>.
</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> The presence of
an extension attribute must not cause the connections between steps
to differ from the connections that any other
conformant XProc processor would produce. They must not cause the
processor to fail to signal an error that a conformant processor is
required to signal. This means that an extension attribute must not
change the effect of any XProc element except to the extent that the
effect is <glossterm>implementation-defined</glossterm> or <glossterm>implementation-dependent</glossterm>.</para>

<para>A processor which encounters an extension attribute that it does not
recognize <rfc2119>must</rfc2119> behave as if the attribute was not present.</para>

</section>

<section xml:id="extension-elements">
<title>Extension elements</title>

<para>The presence of an extension element must not cause the
connections between steps to differ from the connections that any
other conformant XProc processor would produce. They must not cause
the processor to fail to signal an error that a conformant processor
is required to signal. This means that an extension element must not
change the effect of any XProc element except to the extent that the
effect is <glossterm>implementation-defined</glossterm> or <glossterm>implementation-dependent</glossterm>.</para>

<para>There are three contexts in which an extension element might
occur:</para>

<orderedlist>
<listitem>
<para>In an <glossterm>inline
document</glossterm>. All elements in an inline document are
considered quoted; no extension element can occur.
</para>
</listitem>
<listitem>
<para>In a <glossterm>subpipeline</glossterm>. In a subpipeline, any
element in a namespace that is in the set of
<link linkend="p.ignore-prefixes">ignored namespaces</link> is an
extension element. Every other element identifies a step.</para>
</listitem>
<listitem>
<para>In any other context, any element that is not in the pipeline
namespace is an error.</para>
</listitem>
</orderedlist>
</section>

<section xml:id="p.ignore-prefixes">
<title>Ignored namespaces</title>

<para>The element children of a <tag>p:pipeline</tag> can come from many different
namespaces. Some of the children identify steps in the subpipeline, others may
be <link linkend="extension-elements">extension elements</link>.
In order to determine which elements are extension elements and which
are expected to identify steps, the pipeline may specify a set of
“ignored namespaces”
</para>

<para>The ignored namespaces are a set of namespaces which do not
identify steps. They are ignored by the processor unless the processor
happens to recognize one or more of them as
<link linkend="extension-elements">extension elements</link>.</para>

<para>Syntactically, a pipeline author can specify the set
of ignored namespaces with the
<tag class="attribute">ignore-prefixes</tag> attribute. This attribute
can appear on the <tag>p:pipeline</tag> and <tag>p:pipeline-library</tag>
elements.
<error code="S0004">It is a <glossterm>static error</glossterm> if the
<tag class="attribute">ignore-prefixes</tag>
attribute appears on any other element in the pipeline namespace.</error></para>

<para>The value of the <tag class="attribute">ignore-prefixes</tag> attribute
is a sequence of tokens, each of which must be the prefix of
an in-scope namespace.
<error code="S0005">It is a <glossterm>static error</glossterm> if any token
specified in the <tag class="attribute">ignore-prefixes</tag> attribute is not
the prefix of an in-scope namespace.</error></para>

<para>Elements in an ignored namespace are only ignored when they appear
as the direct children of the <tag>p:pipeline</tag> or
<tag>p:pipeline-library</tag> which specifies the ignored namespaces.</para>

<para>Any ignored namespaces that are specified in a pipeline library
are not inherited by pipelines either within that library or that
import that library, they only apply to the elements that appear as
children of the <tag>p:pipeline-library</tag> element on which they
are specified.</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>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>The <tag>p:documentation</tag> element is not shown, but it is allowed anywhere.</para>
</listitem>
<listitem>
<para>Attributes that are <link linkend="option-shortcut">syntactic shortcuts
for option values</link> are not shown.</para>
</listitem>
</itemizedlist>
</section>
</section>

<section xml:id="steps">
<title>Steps</title>

<para>This section describes the core steps of XProc.
</para>

<para>Every compound step in a pipeline has several parts: a set of inputs, a
set of outputs, a set of options, a set of <glossterm>contained
steps</glossterm>, and an environment.</para>

<note role="editorial" xml:id="allow-any-order">
<para>In previous drafts, inputs, outputs, and options occurred in
a fixed order. In this draft, they may appear in any order (but before the
contained steps). Is that problematic?
</para>
</note>

<para>Except where otherwise noted, a compound step can have an arbitrary
number of outputs, options, and contained steps.
</para>

<para><error code="S0027">It is a <glossterm>static error</glossterm> if a
compound step has no <glossterm>contained steps</glossterm>.</error>
</para>

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

<para>A pipeline is specified by the <tag>p:pipeline</tag> element. It
encapsulates the behavior of a <glossterm>subpipeline</glossterm>. Its
children declare the inputs, outputs, and options that the pipeline
exposes and identify the steps in its subpipeline.
</para>

<para>A pipeline can declare additional steps (e.g., ones that are
provided by a particular implementation or in some
<glossterm>implementation-defined</glossterm> way) and import other pipelines. If a pipeline
has been imported, it may be invoked as a step within the pipeline
that imported it.</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 <glossterm>environment</glossterm> of a <tag>p:pipeline</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:pipeline</tag> is the <glossterm>empty
environment</glossterm> with these modifications:</para>

<itemizedlist>
<listitem>
<para>All of the declared inputs of the pipeline are added to the
<glossterm>readable ports</glossterm> in the environment.</para>
</listitem>
<listitem>
<para>If the pipeline has a <glossterm>primary input port</glossterm>, that input is
the <glossterm>default readable port</glossterm>, otherwise the default
readable port is undefined.</para>
</listitem>
<listitem>
<para>All of the <glossterm>declared options</glossterm> of the
pipeline are added to the
<glossterm>in-scope options</glossterm> in the environment.</para>
</listitem>
<!--
<listitem>
<para>If any ignored namespaces are specified, those
namespaces are added to the set of
<glossterm>ignored namespaces</glossterm> in the
environment.</para>
</listitem>
-->
</itemizedlist>

<para>If the <tag>p:pipeline</tag> has a <glossterm>primary output port</glossterm>
and that port has no <glossterm>binding</glossterm>, then it is
bound 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 binding and the last step in the subpipeline does
not have a primary output port.</error></para>

<para>There are two additional constraints on pipelines:</para>

<itemizedlist>
<listitem><para>A <tag>p:pipeline</tag> <rfc2119>must not</rfc2119> itself be
a <glossterm baseform="contained steps">contained step</glossterm>.
</para></listitem>
<listitem><para>If a <tag>p:pipeline</tag> is part of a
<tag>p:pipeline-library</tag> or if it is imported directly with
<tag>p:import</tag>, then it <rfc2119>must</rfc2119> have a
<tag class="attribute">name</tag> or a <tag class="attribute">type</tag>
or both.</para>
</listitem>
</itemizedlist>

<para>If the pipeline initially invoked by the processor has inputs or
outputs, those ports are bound to documents outside of the pipeline in
an <glossterm>implementation-defined</glossterm> manner.</para>

<para>If a pipeline has a <tag class="attribute">type</tag> then that
type may be used as the name of a step to invoke the pipeline. This
most often occurs when the it has been imported into another pipeline,
but pipelines may also invoke themselves recursively.
If it does not have a <tag class="attribute">type</tag>, then
its <tag class="attribute">name</tag> is used to invoke it as a step.</para>

<para>For pipelines that are part of a <tag>p:pipeline-library</tag>, see
<xref linkend="p.pipeline-library"/> for more details on how
<tag>p:pipeline</tag> names are used to compute step names.</para>

<section xml:id="example-pipeline" role="tocsuppress">
<title>Examples</title>

<para>A pipeline might accept a document and a stylesheet as input;
perform XInclude, validation, and transformation; and produce the
formatted document as its output.</para>

<example xml:id="ex.p.pipeline">
<title>A Sample Pipeline Document</title>
<programlisting>&lt;p:pipeline name="pipeline" xmlns:p="http://www.w3.org/2007/03/xproc"&gt;
&lt;p:input port="document" primary="yes"/&gt;
&lt;p:input port="stylesheet"/&gt;
&lt;p:output port="result" primary="yes"/&gt;

&lt;p:xinclude/&gt;

&lt;p:validate-xml-schema&gt;
  &lt;p:input port="schema"&gt;
    &lt;p:document href="http://example.com/path/to/schema.xsd"/&gt;
  &lt;/p:input&gt;
&lt;/p:validate-xml-schema&gt;

&lt;p:xslt&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:pipe step="pipeline" port="stylesheet"/&gt;
  &lt;/p:input&gt;
&lt;/p:xslt&gt;

&lt;/p:pipeline&gt;
</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
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 step that only accepts a single document, the <tag>p:for-each</tag>
construct can be used as a wrapper around the step that accepts
only a single document. The <tag>p:for-each</tag> will apply that step 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 subpipeline is connected to one or more output ports
on the <tag>p:for-each</tag>, 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.</para>

<para>The <tag>p:iteration-source</tag> is an anonymous input:
its <glossterm>binding</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>A portion of each input document can be selected using the <tag class="attribute">select</tag> attribute. If no selection is
specified, the document node of each document is
selected.</para>

<para>Each subtree selected by the <tag>p:for-each</tag> from each
of the inputs that appear on the iteration source is wrapped in a document
node and provided to the <glossterm>subpipeline</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
<code>current</code>.</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 “<code>current</code>” on the <tag>p:for-each</tag> is
added to the <glossterm>readable ports</glossterm>.</para>
</listitem>
<listitem>
<para>The port named “<code>current</code>” 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>
and that port has no <glossterm>binding</glossterm>, then it is
bound 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 binding and the last step in the subpipeline does
not have a primary output port.</error></para>

<section xml:id="example-for-each" role="tocsuppress">
<title>Examples</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>&lt;p:for-each name="chapters"&gt;
  &lt;p:iteration-source select="//chapter"/&gt;
  &lt;p:output port="html-results"&gt;
    &lt;p:pipe step="make-html" port="result"/&gt;
  &lt;/p:output&gt;
  &lt;p:output port="fo-results"&gt;
    &lt;p:pipe step="make-fo" port="result"/&gt;
  &lt;/p:output&gt;

  &lt;p:xslt name="make-html"&gt;
    &lt;p:input port="stylesheet"&gt;
      &lt;p:document href="http://example.com/xsl/html.xsl"/&gt;
    &lt;/p:input&gt;
  &lt;/p:xslt&gt;

  &lt;p:xslt name="make-fo"&gt;
    &lt;p:input port="source"&gt;
      &lt;p:pipe step="chapters" port="current"/&gt;
    &lt;/p:input&gt;
    &lt;p:input port="stylesheet"&gt;
      &lt;p:document href="http://example.com/xsl/fo.xsl"/&gt;
    &lt;/p:input&gt;
  &lt;/p:xslt&gt;
&lt;/p:for-each&gt;
</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
processes a single document, applying its
<glossterm>subpipeline</glossterm> to one or more subsections 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 with the selected subsections replaced by the results of
applying the subpipeline to them.</para>

<para>The <tag>p:viewport-source</tag> is an anonymous input:
its <glossterm>binding</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>.</para>

<para>The <tag class="attribute">match</tag> attribute specifies an
<biblioref linkend="xpath"/>
expression that is a
<link xlink:href="http://www.w3.org/TR/xslt#NT-Pattern">Pattern</link>
in <biblioref linkend="xslt10"/>. Each matching node in the source document
is wrapped in a document node and provided to the viewport's
<glossterm>subpipeline</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:viewport</tag> on a port named
<code>current</code>.</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.</para>

<para><error code="D0003">It is a <glossterm>dynamic error</glossterm>
if the viewport source does not provide exactly one document.
</error></para>

<!--
<para>The <glossterm>environment</glossterm> of a <tag>p:viewport</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:viewport</tag> is the <glossterm>inherited environment</glossterm>
with these modifications:</para>

<itemizedlist>
<listitem>
<para>The port named “<code>current</code>” on the <tag>p:viewport</tag> is
added to the <glossterm>readable ports</glossterm>.</para>
</listitem>
<listitem>
<para>The port named “<code>current</code>” on the <tag>p:viewport</tag> is
made the <glossterm>default readable port</glossterm>.</para>
</listitem>
</itemizedlist>

<para>If the <tag>p:viewport</tag> has a <glossterm>primary output port</glossterm>
and that port has no <glossterm>binding</glossterm>, then it is
bound 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 binding and the last step in the subpipeline does
not have a primary output port.</error></para>

<section xml:id="example-viewport" role="tocsuppress">
<title>Examples</title>

<para>A <tag>p:viewport</tag> might accept an XHTML document as its input,
add an <tag>hr</tag> element before 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>&lt;p:viewport match="h:div[@class='chapter']"
            xmlns:h="http://www.w3.org/1999/xhtml"&gt;
  &lt;p:insert at-start="true"&gt;
    &lt;p:input port="insertion"&gt;
      &lt;p:inline&gt;
        &lt;hr xmlns="http://www.w3.org/1999/xhtml"/&gt;
      &lt;/p:inline&gt;
    &lt;/p:input&gt;
  &lt;/p:insert&gt;
&lt;/p:viewport&gt;

&lt;/p:pipeline&gt;
</programlisting>
</example>

<para>The nodes which match <code>h:div[@class='chapter']</code> (according to the
rules of <biblioref linkend="xslt10"/>) 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
selects exactly one of a list of alternative
<glossterm baseform="subpipeline">subpipelines</glossterm> based on the
evaluation of <biblioref linkend="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 result of the <tag>p:choose</tag>
is the result of the selected <glossterm>subpipeline</glossterm>.</para>

<para>In order to ensure that the result of the <tag>p:choose</tag> is
consistent irrespective of the <glossterm>subpipeline</glossterm> chosen,
each <glossterm>subpipeline</glossterm> must
declare the same number 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><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
<biblioref linkend="xpath"/>
expressions that occur on each branch are evaluated. The context
node is specified as a
<glossterm>binding</glossterm> for the
<tag>xpath-context</tag>. If no binding is provided, the default
<tag>xpath-context</tag> is the document on the
<glossterm>default readable port</glossterm>.
<error code="S0032">It is a <glossterm>static error</glossterm> if no binding
is provided and the <glossterm>default readable port</glossterm> is undefined.</error>
</para>

<para><error code="D0005">It is a <glossterm>dynamic error</glossterm>
if the <tag>xpath-context</tag> is bound to a sequence of
documents.</error></para>

<!--
<para>The <glossterm>environment</glossterm> of a <tag>p:choose</tag> is its
inherited environment
with the <link linkend="dt-standard-modifications">standard modifications</link>.</para>
-->

<para>Each conditional <glossterm>subpipeline</glossterm> is represented by a 
<tag xml:id="p.when">p:when</tag> element.</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
<biblioref linkend="xpath"/>
expression. That XPath expression's effective boolean value is the
guard expression 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>binding</glossterm>
for the <tag>xpath-context</tag>.
If no context is specified on the <tag>p:when</tag>, the context
of the <tag>p:choose</tag> is used. <error code="S0008">It is a
<glossterm>static error</glossterm> if no context is specified in
either the <tag>p:choose</tag> or the <tag>p:when</tag>
and the <glossterm>default readable port</glossterm> is
undefined.</error></para>

<para>The default branch is represented by a
<tag xml:id="p.otherwise">p:otherwise</tag> element.</para>

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

<!--
<para>The <glossterm>environment</glossterm> of the selected subpipeline is the
inherited environment
with the <link linkend="dt-standard-modifications">standard modifications</link>.</para>

<para>The environment inherited by its <glossterm>contained steps</glossterm>
is the <link linkend="dt-standard-inheritance">standard inheritance</link>.
</para>
-->

<!--
<para>If there is no <glossterm>binding</glossterm> for
the <glossterm>primary output port</glossterm> of the selected subpipeline,
then it is bound to the <glossterm>primary output port</glossterm> of
the <glossterm>last step</glossterm> in the selected subpipeline.
<error code="S0006">It is a <glossterm>static error</glossterm> if the
primary output port has no binding and the last step in the selected subpipeline does
not have a primary output port.</error></para>
-->

<section xml:id="example-choose" role="tocsuppress">
<title>Examples</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>&lt;p:choose name="version"&gt;
  &lt;p:when test="/*[@version = 2]"&gt;
    &lt;p:validate-xml-schema&gt;
      &lt;p:input port="schema"&gt;
	&lt;p:document href="v2schema.xsd"/&gt;
      &lt;/p:input&gt;
    &lt;/p:validate-xml-schema&gt;
  &lt;/p:when&gt;

  &lt;p:when test="/*[@version = 1]"&gt;
    &lt;p:validate-xml-schema&gt;
      &lt;p:input port="schema"&gt;
	&lt;p:document href="v1schema.xsd"/&gt;
      &lt;/p:input&gt;
    &lt;/p:validate-xml-schema&gt;
  &lt;/p:when&gt;

  &lt;p:when test="/*[@version]"&gt;
    &lt;p:identity/&gt;
  &lt;/p:when&gt;

  &lt;p:otherwise&gt;
    &lt;p:error code="NOVERSION"
	     description="Required version attribute missing."/&gt;
  &lt;/p:otherwise&gt;
&lt;/p:choose&gt;
</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. It
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.
The result of a <tag>p:group</tag> is the result of its subpipeline.</para>

<!--
<para>The <glossterm>environment</glossterm> of a <tag>p:group</tag> is its
inherited environment with the <link linkend="dt-standard-modifications">standard
modifications</link>.</para>

<para>The environment inherited by its <glossterm>contained steps</glossterm>
is the <link linkend="dt-standard-inheritance">standard inheritance</link>.
</para>
-->

<!--
<para>If there is no <glossterm>binding</glossterm> for
the <glossterm>primary output port</glossterm> of the <tag>p:group</tag>,
then it is bound 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 binding and the last step in the subpipeline does
not have a primary output port.</error></para>
-->

<section xml:id="example-group" role="tocsuppress">
<title>Examples</title>

<example xml:id="ex.p.group">
<title>An Example Group</title>
<programlisting>&lt;p:group&gt;
  &lt;p:option name="db-key" value="some-long-string-of-nearly-random-characters"/&gt;

  &lt;p:choose&gt;
    &lt;p:when test="/config/output = 'fo'"&gt;
      &lt;p:xslt&gt;
	&lt;p:parameter name="key" select="$db-key"/&gt;
	&lt;p:input port="stylesheet"&gt;
	  &lt;p:document href="fo.xsl"/&gt;
	&lt;/p:input&gt;
      &lt;/p:xslt&gt;
    &lt;/p:when&gt;
    &lt;p:when test="/config/output = 'svg'"&gt;
      &lt;p:xslt&gt;
	&lt;p:parameter name="key" select="$db-key"/&gt;
	&lt;p:input port="stylesheet"&gt;
	  &lt;p:document href="svg.xsl"/&gt;
	&lt;/p:input&gt;
      &lt;/p:xslt&gt;
    &lt;/p:when&gt;
    &lt;p:otherwise&gt;
      &lt;p:xslt&gt;
	&lt;p:parameter name="key" select="$db-key"/&gt;
	&lt;p:input port="stylesheet"&gt;
	  &lt;p:document href="html.xsl"/&gt;
	&lt;/p:input&gt;
      &lt;/p:xslt&gt;
    &lt;/p:otherwise&gt;
  &lt;/p:choose&gt;
&lt;/p:group&gt;
</programlisting>
</example>
</section>
</section>

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

<para>A try/catch is specified by the <tag>p:try</tag> element. It
isolates a <glossterm>subpipeline</glossterm>, preventing any 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 results of that
pipeline are the results of the step. However, if any errors
occur, it 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 results of the
recovery subpipeline are the results 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>In order to ensure that the result 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>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 “<code>error</code>” on the <tag>p:catch</tag> is
added to the <glossterm>readable ports</glossterm>.</para>
</listitem>
</itemizedlist>

<note role="editorial" xml:id="default-to-error">
<para>Should the error port be made the default readable port?</para>
</note>

<!--
<para>If there is no <glossterm>binding</glossterm> for
the <glossterm>primary output port</glossterm> of the <tag>p:catch</tag>,
then it is bound 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 binding and the last step in the subpipeline does
not have a primary output port.</error></para>
-->

<section xml:id="example-try" role="tocsuppress">
<title>Examples</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>&lt;p:try&gt;
  &lt;p:group&gt;
    &lt;p:http-request&gt;
      &lt;p:input port="source"&gt;
	&lt;p:inline&gt;
	  &lt;c:http-request method="post" href="http://example.com/form-action"&gt;
	    &lt;c:entity-body content-type="application/x-www-form-urlencoded"&gt;
	      &lt;c:body&gt;name=W3C&amp;amp;spec=XProc&lt;/c:body&gt;
	    &lt;/c:entity-body&gt;
	  &lt;/c:http-request&gt;
	&lt;/p:inline&gt;
      &lt;/p:input&gt;
    &lt;/p:http-request&gt;
  &lt;/p:group&gt;
  &lt;p:catch&gt;
    &lt;p:identity&gt;
      &lt;p:input port="source"&gt;
	&lt;p:inline&gt;
	  &lt;c:error&gt;HTTP Request Failed&lt;/c:error&gt;
	&lt;/p:inline&gt;
      &lt;/p:input&gt;
    &lt;/p:identity&gt;
  &lt;/p:catch&gt;
&lt;/p:try&gt;
</programlisting>
</example>

</section>
</section>

<section xml:id="p.other">
<title>Other Steps</title>

<para>Other steps are specified by elements that occur as
<glossterm>contained steps</glossterm> and are not in any of the the ignored
namespaces.</para>

<para>Other steps can be atomic:</para>

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

<para>Or compound:</para>

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

<para>Each atomic step must be the name of a <tag>p:pipeline</tag>
type or must have been declared with a <tag>p:declare-step</tag> that
appears in the pipeline, or an imported library, before it is used.
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>If the step element name is the same as the type of a step
declared with <tag>p:declare-step</tag>, then that step invokes the
declared step.</para>

<para>If the step element name is the same as the type or name of a
<tag>p:pipeline</tag>, then that step runs the pipeline identified by
that type or name.</para>

<!--
<para>If the <glossterm>primary input port</glossterm> of a step is not
specified, it will be bound to the <glossterm>default readable port</glossterm>.
<error code="S0031">It is a <glossterm>static error</glossterm> to leave
unspecified any input port that is not the primary.</error></para>

<note role="editorial" xml:id="specified-undefined">
<para>The term “specified” isn't defined anywhere, does it need to be or
is it clear what is meant?</para>
</note>

<para><error code="S0032">It is a <glossterm>static error</glossterm>
to leave the <glossterm>primary output port</glossterm> unbound. Any
non-primary, unbound output ports must be treated as if they were bound
to an instance of the <tag>p:sink</tag> step.</error></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>The <glossterm>environment</glossterm> of such a step is its
inherited environment with the <link
linkend="dt-standard-modifications">standard
modifications</link>.</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>

<note role="editorial" xml:id="default-params">
<para>A pipeline author can make the set of parameters passed to a step explicit
with a parameter input. If the step <emphasis>does not</emphasis> make
an explicit binding for a parameter input, the default could be either to pass
no parameters to the step or to behave as if the parameter input was bound
to the pipeline parameters.</para>
<para>The working group is divided on this issue and this draft does not
provide an answer to that question. Reader feedback is encouraged.</para>
</note>

<section xml:id="option-shortcut">
<title>Syntactic Shortcut for Option Values</title>

<para>Namespace qualified attributes on a step are
<link linkend="extension-attributes">extension attributes</link>.
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:option</tag> syntax:</para>

<programlisting><![CDATA[<ex:stepType>
  <p:option name="option-name" value="5"/>
</ex:stepType>]]></programlisting>

<para>The second step uses the syntactic shortcut:</para>

<programlisting><![CDATA[<ex:stepType option-name="5"/>]]></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
with a <tag class="attribute">select</tag>
expression 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 atomic step that is not declared on steps of that type.</error>
</para>
</section>
</section>
</section>

<section xml:id="other-elements">
<title>Other pipeline elements</title>

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

<para>A <tag>p:input</tag> identifies an input port for a step, declaring it
if necessary. There are two kinds of inputs that may be declared, ordinary
“document” inputs and “parameter” inputs.
<error code="S0033">It is a <glossterm>static error</glossterm> to specify
any kind of input other than “document” or “parameter”.</error>
</para>

<section xml:id="document-inputs">
<title>Document Inputs</title>

<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>
<error code="S0012">It is a <glossterm>static error</glossterm>
if the <tag class="attribute">port</tag> given does not match the name
of an input port specified in the step's declaration.</error></para>

<para>On compound steps and <tag>p:declare-step</tag>, an input
declaration can indicate if a sequence of documents is allowed to
appear on the port and if the port is a <glossterm>primary input port</glossterm>.
</para>

<para>If <tag class="attribute">sequence</tag>
is specified with the value “yes”, then a sequence is allowed.
<error code="D0006">If
<tag class="attribute">sequence</tag> is not specified,
or has the value “no”, then it is a
<glossterm>dynamic error</glossterm> for a sequence of more than one
document to appear on the declared port.</error></para>

<para>An input port is a <glossterm>primary input port</glossterm> if
<tag class="attribute">primary</tag> is specified with the value “yes”
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>On <tag>p:declare-step</tag>, the <tag>p:input</tag> simply declares the
input port. In all other contexts, the declaration <rfc2119>may</rfc2119> be
accompanied by a <glossterm>binding</glossterm>
for the input:</para>

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

<para>If no binding is provided, the input will be bound to the
<glossterm>default readable port</glossterm>.
<error code="S0032">It is a <glossterm>static error</glossterm> if no binding
is provided and the <glossterm>default readable port</glossterm> is undefined.</error>
A <tag class="attribute">select</tag>
expression <rfc2119>may</rfc2119> also be provided. The <tag class="attribute">select</tag> expression, if specified, applies the
specified
<biblioref linkend="xpath"/>
select expression to the document(s) that are read.
Each node that matches is wrapped in a document and provided to the
input port. In other words,</para>

<programlisting>&lt;p:input port="source"&gt;
  &lt;p:document href="http://example.org/input.html"/&gt;
&lt;/p:input&gt;
</programlisting>

<para>provides a single document, but</para>

<programlisting>&lt;p:input port="source" select="//html:div"&gt;
  &lt;p:document href="http://example.org/input.html"/&gt;
&lt;/p:input&gt;
</programlisting>

<para>provides a sequence of zero or more documents, one for each matching
<code>html:div</code> in <uri>http://example.org/input.html</uri>.</para>

<para>A select expression can equally be applied to input read from
another step. This input:</para>

<programlisting>&lt;p:input port="source" select="//html:div"&gt;
  &lt;p:pipe step="origin" port="result"/&gt;
&lt;/p:input&gt;
</programlisting>

<para>provides a sequence of zero or more documents, one for each matching
<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><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 anything other than a possibly empty
set of nodes.</error></para>
</section>

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

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

<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 computed parameters. A
parameter input port must satisfy all the constraints of a normal,
document input.</para>

<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>
<error code="S0012">It is a <glossterm>static error</glossterm>
if the <tag class="attribute">port</tag> given does not match the name
of an input port specified in the step's declaration.</error></para>

<para>When used on a step, parameter input ports always accept a
sequence of documents. If no binding is provided, the parameter input
will be bound to @@<emphasis xlink:href="#default-params">TBD</emphasis>.</para>

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

<para>A step which accepts a parameter input reads all of the documents presented
on that port, using each <tag>c:parameter</tag> (either at the root or inside
the <tag>c:parameter-list</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:parameter</tag> elements, they are
are also considered in document order. In other words, <tag>p:parameter</tag> elements
that appear before the parameter input may be overridden by the
computed parameters; <tag>p:parameter</tag> elements that appear after may override the
computed values.</para> 

<section xml:id="cv.parameter">
<title>The c:parameter element</title>

<para>A <tag>c:parameter</tag> represents a parameter on a parameter input.</para>

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

<para>The <tag class="attribute">name</tag> attribute of the <tag>c:parameter</tag>
must have the lexical form of a QName. If it contains a colon, then its expanded
name is constructed using the namespace declarations in-scope on the <tag>c:parameter</tag>
element. If it does not contain a colon and the <tag class="attribute">namespace</tag>
attribute is specified, then it is an expanded name in the specified namespace.
If the namespace attribute is not specified, its expanded name has no namespace.
<error code="D0013">It is a
<glossterm>dynamic error</glossterm> if the <tag class="attribute">name</tag> attribute
of a <tag>c:parameter</tag> element contains a colon and a
<tag class="attribute">namespace</tag> attribute is specified.</error>
</para>

<para>Any extension attributes that appear on the <tag>c:parameter</tag> element
are ignored.</para>
</section>

<section xml:id="cv.parameter-list">
<title>The c:parameter-list element</title>

<para>A <tag>c:parameter-list</tag> represents a list of parameters on a
parameter input.</para>

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

<para>The <tag>c:parameter-list</tag> contains zero or more <tag>c:parameter</tag>
elements.
<error code="D0018">It is a <glossterm>dynamic error</glossterm>
if the parameter list contains any elements other than
<tag>c:parameter</tag>.</error></para>

<para>Any extension attributes that appear on the <tag>c:parameter-list</tag> element
are ignored.</para>
</section>
</section>
</section>

<section xml:id="p.iteration-source">
<title>p:iteration-source Element</title>

<para>A <code>p:iteration-source</code> 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>binding</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 Element</title>

<para>A <code>p:viewport-source</code> identifies input to a <tag>p:viewport</tag>.</para>

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

<para>Only one <glossterm>binding</glossterm> is allowed and it works
the same way that bindings work on a <tag>p:input</tag>.
<error code="D0006">It is a
<glossterm>dynamic error</glossterm> for a sequence of more than one
document to appear on the <tag>p:viewport-source</tag>.</error>
No <tag class="attribute">select</tag> expression is allowed.</para>
</section>

<section xml:id="p.xpath-context">
<title>p:xpath-context Element</title>

<para>A <code>p:xpath-context</code> identifies a context against which
an
<biblioref linkend="xpath"/>
expression will be evaluated for a <tag>p:when</tag>.
</para>

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

<para>Only one <glossterm>binding</glossterm> is allowed and it works
the same way that bindings work on a <tag>p:input</tag>.
<error code="D0006">It is a
<glossterm>dynamic error</glossterm> for a sequence of more than one
document to appear on the <tag>p:xpath-context</tag>.</error>
No <tag class="attribute">select</tag> expression is allowed.</para>

<para><error code="D0019">It is a <glossterm>dynamic error</glossterm>
if the context is bound to <tag>p:empty</tag> and the test expression
refers to the context node.</error></para>
</section>

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

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

<para>A <tag>p:output</tag> identifies an output port, optionally
declaring 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>
<error code="S0013">It is a <glossterm>static error</glossterm>
if the <tag class="attribute">port</tag> given does not match the name
of an output port specified in the step's declaration.</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 “yes”,
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 “no”, then it is a
<glossterm>dynamic error</glossterm> if the step produces a
sequence of more than one document on the declared port.</error></para>

<para>An output declaration can indicate if it is to be considered the
primary output for the step.
If <tag class="attribute">primary</tag> is specified with the value “yes”,
then the named port will be treated as the primary output port.
<error code="S0014">It is a <glossterm>static error</glossterm> to identify
more than one output ports as primary.</error></para>

<para>On <glossterm baseform="compound step">compound steps</glossterm>,
the declaration <rfc2119>may</rfc2119> be accompanied by a
<glossterm>binding</glossterm> for the output.</para>

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

<para><error code="S0029">It is a <glossterm>static error</glossterm> to
specify a binding for a <tag>p:output</tag> inside a
<tag>p:declare-step</tag>.</error></para>

<para>If a binding is provided for a <tag>p:output</tag>, documents are
<emphasis>read from</emphasis> that binding 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 Element</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
URI whatever document or documents appear on the specified port. How a sequence
of documents is represented is <glossterm>implementation-defined</glossterm>.</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>

</section>

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

<section xml:id="options-parameters">
<title>Options and Parameters</title>

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

<para>The <tag>p:option</tag> element is used both to declare
options and to establish values for them. It can occur in three
contexts:
</para>

<orderedlist>
<listitem>
<para>On <tag>p:declare-step</tag>, it declares
that the step accepts the named option. It may also provide a default value
for the option.
</para>
</listitem>
<listitem>
<para>On a compound step, it provides a value for the option,
simultaneously declaring it.</para>
</listitem>
<listitem>
<para>On an atomic step, it provides a value for the
option, overriding any default specified in the declaration.</para>
</listitem>
</orderedlist>

<section xml:id="option-declaration">
<title>Declaring Options</title>

<para>Options are declared on <tag>p:declare-step</tag> 
with <tag>p:option</tag>:</para>

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

<para>The name of the option must 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 in the XProc namespace.</error>
</para>

<para>An option may be declared as <tag class="attribute">required</tag>
or it may be <link linkend="option-values">given a default
value</link>.
<error code="S0017">It is a <glossterm>static error</glossterm> to specify
that the option is both <tag class="attribute">required</tag>
<emphasis>and</emphasis> has a default value.</error></para>

<para><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>
</section>

<section xml:id="option-use">
<title>Using Options</title>

<para>Options are used on a step with <tag>p:option</tag>.
The name of the option must 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 in the XProc namespace.</error>
</para>

<para>The option <rfc2119>must</rfc2119> be
<link linkend="option-values">given a value</link> when it is used.
<error code="S0031">It is a <glossterm>static error</glossterm> to use an
option on an atomic step that is not declared on steps of that type.</error>
</para>
</section>

<section xml:id="option-values">
<title>Assigning Values to Options</title>

<para>When an option is declared, it <rfc2119>may</rfc2119> be given
a default value. When it is used, it <rfc2119>must</rfc2119> be given
a value.</para>

<para>The value can be specified in two ways: with a
<tag class="attribute">select</tag> or 
<tag class="attribute">value</tag> attribute.</para>

<para>If a <tag class="attribute">select</tag> expression is given, it
is evaluated against the document specified
in the
<glossterm>binding</glossterm>
and the <biblioref linkend="xpath"/>
<emphasis>string value</emphasis> of the expression becomes the
value of the option. <error code="D0008">It is a <glossterm>dynamic error</glossterm>
if a document sequence is specified in the binding for a
<tag>p:option</tag>.</error></para>

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

<para>The <tag class="attribute">select</tag> expression may refer to
the values of other in-scope options by variable reference.
<error code="S0019">It is a
<glossterm>static error</glossterm> if the variable reference uses a
QName that is not the name of an in-scope option.</error></para>

<para>If a <tag class="attribute">select</tag> expression is used but
no binding is provided, the implicit binding is to the
<glossterm>default readable port</glossterm>.
<error code="S0032">It is a <glossterm>static error</glossterm> if no binding
is provided and the <glossterm>default readable port</glossterm> is undefined.</error>
</para>

<para>If a <tag class="attribute">value</tag> attribute is specified,
its content becomes the value of the option.</para>

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

<para>In the case where the value of an option is a constant, its
value may also be specified on the parent step as specified in
<xref linkend="option-shortcut"/>.</para>

<para><error code="S0016">It is a <glossterm>static error</glossterm> if the
value is not specified with either <tag class="attribute">select</tag> or
<tag class="attribute">value</tag>, or if both are specified.</error>
</para>
</section>
</section>

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

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

<para>The <tag>p:parameter</tag> element is used to establish the
value of a parameter. The parameter <rfc2119>must</rfc2119> be given a
value when it is used.</para>

<para>The value can be specified in two ways: with a
<tag class="attribute">select</tag> or 
<tag class="attribute">value</tag> attribute.</para>

<para>If a <tag class="attribute">select</tag> expression is given, it
is evaluated against the document specified
in the
<glossterm>binding</glossterm>
and the <biblioref linkend="xpath"/>
<emphasis>string value</emphasis> of the expression becomes the
value of the parameter.
<error code="D0008">It is a <glossterm>dynamic error</glossterm>
if a document sequence is specified in the binding for a
<tag>p:parameter</tag>.</error></para>

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

<para>The <tag class="attribute">select</tag> expression may refer to
the values of in-scope <emphasis>options</emphasis> by variable reference.
<error code="S0019">It is a
<glossterm>static error</glossterm> if the variable reference uses a
QName that is not the name of an in-scope option.</error></para>

<para>If a <tag class="attribute">select</tag> expression is used but
no binding is provided, the implicit binding is to the
<glossterm>default readable port</glossterm>.
<error code="S0032">It is a <glossterm>static error</glossterm> if no binding
is provided and the <glossterm>default readable port</glossterm> is undefined.</error>
</para>

<para>If a <tag class="attribute">value</tag> attribute is specified,
its content becomes the value of the parameter.</para>

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

<para><error code="S0016">It is a <glossterm>static error</glossterm> if the
value is not specified with either <tag class="attribute">select</tag> or
<tag class="attribute">value</tag>, or if both are specified.</error>
</para>
</section>

<section xml:id="opt-param-bindings">
<title>Option and Parameter Namespace Bindings</title>

<para>Option and parameter values carry with them not only their literal
or computed string value but also the set of namespaces that were in-scope
on the element which defined them.</para>

<para>This is necessary because QName values in options or parameters
may subsequently need to be expanded by the steps which accept them.</para>

<para>When values are computed from several sources, the union of the
sets of namespaces must be carried with the new value. The results of computing
the union in the presence of conflicting declarations for a particular prefix
are <glossterm>implementation-dependent</glossterm>.</para>
</section>
</section>

<!-- ============================================================ -->
<!--
<section xml:id="p.use-parameter-set">
<title>p:use-parameter-set Element</title>

<para>The <tag>p:use-parameter-set</tag> element is used to refer to a set
of parameters. Such a reference on a step makes those parameters available to
the step; on a <tag>p:parameter-set</tag>, it adds those parameters to the
set being defined.</para>

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

<para><error code="D0015">It is a
<glossterm>dynamic error</glossterm> if no parameter set with the specified
name has been defined in the current pipeline.</error></para>

<para>The special name “<literal>#pipeline-parameters</literal>” can be used
to refer to the set of parameters passed to the containing pipeline. Such
parameters may have been provided through some <glossterm>implementation-defined</glossterm> mechanism
when the pipeline was executed, or passed explicitly in the
case of a pipeline being called as a step.</para>

</section>
-->
<!-- ============================================================ -->

<section xml:id="p.declare-step">
<title>p:declare-step Element</title>

<para>A <tag>p:declare-step</tag> provides the type and
<glossterm>signature</glossterm> of an atomic step. It declares the
inputs, outputs, and options for all steps of that type.</para>

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

<para>Implementations may use
<link linkend="extension-attributes">extension attributes</link> to
provide <glossterm>implementation-dependent</glossterm> information about a declared step.
For example, such an attribute might identify the code which
implements steps of this type.</para>

<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 <tag class="attribute">type</tag> attribute is in no namespace.</error>
If the namespace URI of the type is the
XProc namespace, then the declaration must be exactly as defined in
this specification. Neither users nor implementors may define additional
steps in the XProc namespace.</para>

<!--
<para>Exactly one input declaration of a
<tag>p:declare-step</tag> <rfc2119>may</rfc2119> use the
<tag class="attribute">name</tag> “<literal>*</literal>” to indicate
that the step accepts an arbitrary number of inputs.
</para>

<para>Exactly one output declaration of a
<tag>p:declare-step</tag> <rfc2119>may</rfc2119> use the
<tag class="attribute">name</tag> “<literal>*</literal>” to indicate
that the step can produce an arbitrary number of outputs.
</para>
-->

</section>

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

<section xml:id="p.pipeline-library">
<title>p:pipeline-library Element</title>

<para>A <tag>p:pipeline-library</tag> is a collection of step
declarations and/or pipeline definitions.
</para>

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

<para>Libraries can import pipelines and/or other libraries.
<error code="S0021">It is a <glossterm>static error</glossterm> if the import
references in a pipeline or pipeline library are
circular.</error></para>

<para>If the <tag>p:pipeline-library</tag> specifies a namespace with
the <tag class="attribute">namespace</tag> attribute, then all of the
untyped pipelines that occur in the library are in that
namespace.</para>

<para>For example, given the following pipeline library:</para>

<programlisting>&lt;p:pipeline-library xmlns:p="http://www.w3.org/2007/03/xproc"
		    namespace="http://example.com/ns/pipelines"&gt;

&lt;p:import href="ancillary-library.xml"/&gt;
&lt;p:import href="other-pipeline.xml"/&gt;

&lt;p:pipeline name="validate"&gt;
  &lt;!-- definition of validate pipeline --&gt;
&lt;/p:pipeline&gt;

&lt;p:pipeline name="format" type="my:format"
	    xmlns:my="http://example.com/vanity/mine"&gt;
  &lt;!-- definition of format pipeline --&gt;
&lt;/p:pipeline&gt;

&lt;/p:pipeline-library&gt;
</programlisting>

<para>The pipeline named “<literal>validate</literal>” 
is in the namespace
<uri type="xmlnamespace">http://example.com/ns/pipelines</uri>. That means
that it must be invoked from the importing pipeline with
a qualified name of the form:</para>

<programlisting><![CDATA[<ex:validate>
  …
</ex:validate>]]></programlisting>

<para>(Assuming that the “<literal>ex</literal>” prefix is bound to
<uri>http://example.com/ns/pipelines</uri>.)</para>

<para>The pipeline named “<literal>format</literal>” has an explicit type so
it must be invoked with a qualified name of the form:</para>

<programlisting><![CDATA[<my:format>
  …
</my:format>]]></programlisting>

<para>(Assuming that the “<literal>my</literal>” prefix is bound to
<uri>http://example.com/vanity/mine</uri>.)</para>

<para>The pipeline library namespace applies only to pipelines that are
defined directly in the library; it does not apply to pipeline libraries
that are imported or pipelines that are directly imported.</para>

</section>

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

<section xml:id="p.import">
<title>p:import Element</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 URI and makes any
pipelines declared within it available to the current pipeline.
An imported pipeline has an implicit signature that consists of the
inputs, outputs, and options declared on it.
</para>

<para><error code="D0009">It is a <glossterm>dynamic 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:pipeline-library</tag> or <tag>p:pipeline</tag>.</error>
<error code="D0010">It is a <glossterm>dynamic error</glossterm> to import
a single pipeline if that pipeline does not have a
<tag class="attribute">name</tag> or a <tag class="attribute">type</tag>.</error> 
<error code="D0012">It is a <glossterm>dynamic error</glossterm> to import
more than one pipeline with the same name or type (either directly or within a
library).</error>
</para>
</section>

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

<para>A <tag>p:pipe</tag> reads from the output port of another step.</para>

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

<para>The <tag>p:pipe</tag> element connects to the output port of another step.
It identifies the output port too 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
<glossterm>environment</glossterm> of the step that contains the
<tag>p:pipe</tag>.</error></para>

<para><error code="S0023">It is a <glossterm>static error</glossterm>
if the port identified by a <tag>p:pipe</tag> in the
<tag>p:output</tag> of a compound step is not
in the <glossterm>readable ports</glossterm> of the environment
inherited by the <glossterm>contained steps</glossterm> of the
compound step.</error></para>

<para>In other words, the output of a compound step must be bound to
the output of one of its <glossterm>contained steps</glossterm>. All
other bindings must be to ports that are already readable in the
current environment.</para>

</section>

<section xml:id="p.inline">
<title>p:inline Element</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.</para>

<note>
<para>The nodes inside a <tag>p:inline</tag> element naturally inherit
the namespaces that are in-scope at the point where they occur in the
pipeline document. Implementations must assure that those namespaces
remain in-scope in the resulting document.</para>
</note>

<para><error code="S0024">It is a <glossterm>static error</glossterm>
if the content of the <tag>p:inline</tag> element is not a well-formed
XML document.</error></para>

</section>

<section xml:id="p.document">
<title>p:document Element</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.</para>

<para><error code="D0011">It is a <glossterm>dynamic error</glossterm> if the document
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> be
conformant to <citetitle>Namespaces in XML</citetitle>.
It <rfc2119>must not</rfc2119> perform validation.
It <rfc2119>must not</rfc2119> perform any other processing, such as
expanding XIncludes.</para>

<para>Use the <tag>p:load</tag> step if you need to perform DTD-based
validation or wish to perform other processing on the document before it is
used by a step.</para>
</section>

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

<para>A <tag>p:empty</tag> binds to an empty sequence of documents.</para>

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

</section>

<section xml:id="p.documentation">
<title>p:documentation Element</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.
</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,
incorrect specification of inputs and outputs, and reference to unknown
steps.</para>

<para>Static errors are fatal and must be detected before any steps
are evaluated.</para>

<?static-error-list?>

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

<?dynamic-error-list?>

</section>
</section>

<appendix xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:p="http://www.w3.org/2007/03/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" version="5.0-extension w3c-xproc" xml:id="std-components">

<title>Standard Step Library</title>

<para>This appendix describes the standard XProc steps. A machine-readable
description of these steps may be found in
<link xlink:href="pipeline-library.xml">pipeline-library.xml</link>.</para>

<para>Some steps in this appendix consume or produce an XML vocabulary
defined in this section. In all cases, the namespace for that
vocabulary is <uri type="xmlnamespace">http://www.w3.org/2007/03/xproc-step</uri> and is
represented by the prefix 'c:' in this appendix.</para>

<para xml:id="cv.result">Also, in this section, several steps use this empty element for
result information:</para>

<!--
<e:element-syntax name="result">
  <e:in-category name="step-vocabulary"/>
  <e:attribute name="value">
    <e:data-type name="NCName"/>
  </e:attribute>
  <e:attribute name="href">
    <e:data-type name="anyURI"/>
  </e:attribute>
  <e:empty/>
</e:element-syntax>
-->

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

<note>
<para>The steps described in this draft are intended mainly as a
starting point for discussion and to present a flavor for the sorts of
steps envisioned. The WG has not yet discussed them in detail.</para>
</note>

<section xml:id="std-required">
<title>Required Steps</title>

<para>This section describes standard steps that must be supported
by any conforming processor.</para>

<!-- ************************************************************************-->

<section xml:id="c.count">
<title>Count</title>

<para>The Count step counts the number of documents in the <code>source</code> input sequence and returns a single document on <code>result</code> containing that number.  The generated document contains a single <tag>c:result</tag> element whose <code>value</code> attribute is the string representation of the number of documents in the sequence.</para>

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

</section>

<!-- ************************************************************************-->

<section xml:id="c.delete">
<title>Delete</title>

<para>The Delete step deletes the matching items from the <code>source</code> input document and produces the resulting document with the deletions on the <code>result</code> port.  The matching items are specified by the match pattern in the <option>match</option> option.  The match pattern may match multiple items to be deleted but nested matches are not considered as their ancestors would already be deleted.</para>

<p:declare-step type="p:delete">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="match" required="yes"/>
</p:declare-step>

</section>

<!-- ************************************************************************-->

<section xml:id="c.equal">
<title>Equal</title>

<para>The Equal step accepts two, single documents and returns “1” if
they are <function>fn:deep-equal</function> (as defined in
<biblioref linkend="xpath-functions"/>) to each other, “0”
otherwise. The return value is expressed using a <tag>c:result</tag>
document.</para>

<p:declare-step type="p:equal">
   <p:input port="source" primary="yes"/>
   <p:input port="alternate"/>
   <p:output port="result"/>
   <p:option name="fail-if-not-equal" value="no"/>
</p:declare-step>

</section>

<!-- ************************************************************************-->

<section xml:id="c.error">
<title>Error</title>

<para>The Error step generates an error using the options specified on the step. The error generated can be caught
by a try/catch language construct like any other dynamic error.</para>

<p:declare-step type="p:error">
   <p:option name="code" required="yes"/>
   <p:option name="description" required="yes"/>
</p:declare-step>

<para>Note that this step has no inputs and no outputs.  The containing language construct (e.g. a choose construct)
controls whether the error is generated.  Since the step generates an error upon invocation, there is no direct output.  Instead, the error generates an instance of the err:errors element on the error port just like any other dynamic error.</para>

<para>For example, give the following invocation:</para>
<programlisting>
<![CDATA[
<p:error name="bad-document">
   <p:option name="code" value="12">
   <p:option name="description" value="The document element is unknown."/>
</p:error>
]]>
</programlisting>

<para>The error vocabulary element (and document) generated on the error output port is:</para>
<programlisting>
<![CDATA[
<err:errors name="bad-document" type="p:error">
<err:error code="12">
The document element is unknown
</err:errors>
</err:errors>
]]>
</programlisting>

</section>

<!-- ************************************************************************-->

<section xml:id="c.escape-markup">
<title>Escape Markup</title>

<para>The Escape Markup step applies XML serialization to the
children of the document element and replaces those children with their
serialization. The outcome is a single element with text content that
represents the "escaped" syntax of the children if they were
serialized.</para>

<p:declare-step type="p:escape-markup">
  <p:input port="source"/>
  <p:output port="result"/>
</p:declare-step>

<para>For example, the input:</para>
<programlisting>&lt;description&gt;
&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;p&gt;This is a chunk of XHTML.&lt;/p&gt;
&lt;/div&gt;
&lt;/description&gt;
</programlisting>
<para>and produces:</para>
<programlisting>&lt;description&gt;
&amp;lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;
&amp;lt;p&gt;This is a chunk of XHTML.&amp;lt;/p&gt;
&amp;lt;/div&gt;
&lt;/description&gt;
</programlisting>

</section>

<!-- ************************************************************************-->

<!--
<section xml:id="c.head">
<title>Head</title>
<para>Given the value of the <option>count</option> option treated as an integer <code>N</code>, the Head step accepts a sequence of documents and produces subsequence consisting of up to the first <code>N</code> number of documents.  If the input sequence has less than N documents, all the documents are passed to the output.</para>

<para>Any input document passed to the output is untouched by this step.  That is, for those matching documents in the input sequence, a verbatim copy is produced in the output sequence.</para>

<p:declare-step type="p:head">
  <p:input port="source" sequence="yes"/>
  <p:output port="result" sequence="yes"/>
  <p:option name="count" required="yes" value="1"/>
</p:declare-step>

</section>
-->

<!-- ************************************************************************-->

<!-- ************************************************************************-->

<section xml:id="c.identity">
<title>Identity</title>

<para>The identity step makes a verbatim copy of its input
available on its output.</para>

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

<!-- ************************************************************************-->

<section xml:id="c.insert">
<title>Insert</title>

<para>The Insert step inserts the <code>insertion</code> port's document as a child of matching elements in the <code>source</code> port's document.  The insertion copies the document element of the <code>insertion</code>
document into the position specified by the options on the step.  In some cases, multiple insertions may be performed by this step.</para>

<p:declare-step type="p:insert">
   <p:input port="source" primary="yes"/>
   <p:input port="insertion"/>
   <p:output port="result"/>
   <p:option name="match"/>
   <p:option name="at-start"/>
</p:declare-step>

<para>The matching nodes in the source document are specified as a match pattern in the <option>match</option> option that must target an element.  If no match pattern is supplied, the document element is the only match.</para>

<para>If the <option>at-start</option> option has a value 'yes', the
<code>insertion</code> document will be inserted as the first child(ren) of the element,
otherwise it will be inserted as the last child. If the <option>at-start</option> option
is not specified, a value of 'yes' is assumed.</para>

<para>As the inserted elements are part of the output of the step they are not considered in determining matching elements.</para>

</section>

<!-- ************************************************************************-->

<section xml:id="c.label-elements">
<title>Label Elements</title>

<para>The Label Elements step labels each element with a unique
<tag class="attribute">xml:id</tag>
value. If the element already has an
<tag class="attribute">xml:id</tag> value, that value is
preserved. A user may specify the <option>prefix</option> and/or
<option>suffix</option> options for prefixing or suffixing the
generated value of the
<tag class="attribute">xml:id</tag> attribute. These prefixes or suffixes do
not affect existing <tag class="attribute">xml:id</tag> values.</para>

<para>If a <option>select</option> option is specified, only elements which match
that XPath 1.0 select expression are modified.</para>

<para>If an existing <tag class="attribute">xml:id</tag> value conflicts with a previously
generated value, the step fails.</para>

<para><error code="D0013">It is a <glossterm>dynamic error</glossterm> if
an existing <tag class="attribute">xml:id</tag> value conflicts with a
previously generated value and the step fails.</error></para>

<p:declare-step type="p:label-elements">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="select"/>
   <p:option name="prefix"/>
   <p:option name="suffix"/>
</p:declare-step>

</section>

<!-- ************************************************************************-->

<section xml:id="c.load">
<title>Load</title>

<para>The Load step has no inputs but takes a option that
specifies a URI of an XML resource that should be loaded and provided as
the result.</para>

<p:declare-step type="p:load">
  <p:output port="result"/>
  <p:option name="href" required="yes"/>
  <p:option name="validate"/>
</p:declare-step>

<para>Load attempts to read an XML document from the specified URI. If the
document does not exist, or is not well-formed, the step fails. Otherwise,
the document read is produced on the <literal>result</literal> port.</para>

<para>If the value of the <option>validate</option> option is 'yes', the XML
processor is invoked as a validating XML processor and
DTD validation is performed.  If the document is not valid or the step
doesn't support validating processors, the step fails.</para>

</section>

<!-- ************************************************************************-->

<section xml:id="c.namespace-rename">
<title>Namespace Rename</title>

<para>The Namespace Rename step renames any namespace declaration or
use of a namespace in a document to a new URI value. The source
namespaces is identified by the <option>from</option> option and the
target namespace is identified by the <option>to</option>
option.</para>

<para>If the <option>from</option> option is the empty string, or is
not specified, then elements and attributes in no namespace are
renamed. If the <option>to</option> option is the empty string, or is
not specified, then elements and attributes in the specified
<option>from</option> namespace are renamed into no namespace.</para>

<para>If the XML namespace
(<uri>http://www.w3.org/XML/1998/namespace</uri>) or the XMLNS namespace
(<uri>http://www.w3.org/2000/xmlns/</uri>) is used in either the
<option>from</option> or <option>to</option> options, the step fails.</para>

<p:declare-step type="p:namespace-rename">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="from"/>
   <p:option name="to"/>
</p:declare-step>

<para>It is not an error to specify the same namespace in the
<option>from</option> and <option>to</option> options, but it will
have no observable effect.</para>

</section>

<!-- ************************************************************************-->

<section xml:id="c.parameters">
<title>Parameters</title>

<para>The Parameters step exposes a set of parameters as a sequence of
<tag>c:parameter</tag> documents.</para>

<p:declare-step type="p:parameters">
   <p:input port="parameters" kind="parameter" primary="no"/>
   <p:output port="result" sequence="yes" primary="no"/>
</p:declare-step>

<para>Each parameter passed to the step is converted into a
<tag>c:parameter</tag> element and written to the
<literal>result</literal> port as a document. The step resolves
duplicate parameters in the normal way; the order in which the
parameters are written is implementation dependent.</para>

<para>For consistency and user convenience, if any of the parameters
have names that are in a namespace, the
<tag class="attribute">namespace</tag> attribute on the
<tag>c:parameter</tag> element <rfc2119>must</rfc2119> be used. Each
<tag class="attribute">name</tag> will be an NCName.</para>
</section>

<!-- ************************************************************************-->

<section xml:id="c.rename">
<title>Rename</title