<?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?>
-->
<?xml-stylesheet type="text/css" href="specification.css"?>
<?oxygen RNGSchema="../schema/dbspec.rnc" type="compact"?>
<?xml-stylesheet type="text/xsl" href="../style/dbspec.xsl"?>
<!DOCTYPE specification [
<!ENTITY qn "<glossterm>QName</glossterm>">
<!ENTITY must "<rfc2119>must</rfc2119>">
<!ENTITY xml "<glossterm>XML</glossterm>">
]>
<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-11-29</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-20070920/"/>
<bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2007/WD-xproc-20070706/"/>
<bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2007/WD-xproc-20070405/"/>
<!--
<bibliorelation type="replaces"
		xlink:href="http://www.w3.org/TR/2006/WD-xproc-20061117/"/>
-->

<authorgroup>
  <author>
    <personname>Norman Walsh</personname>
    <affiliation>
      <orgname>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>
  <author>
    <personname>Henry S. Thompson</personname>
    <affiliation>
      <orgname>University of Edinburgh</orgname>
    </affiliation>
    <email>ht@inf.ed.ac.uk</email>
  </author>
</authorgroup>

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

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

<legalnotice role="status">

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

<para>This 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 Last Call Working Draft. The Working Group considers
this specification complete and finished. The review period for this document
ends on 24 October 2007.</para>
-->

<para>In response to comments made on the previous draft, the Working
Group decided to make significant changes to the way XPath and XSLT
are supported in XProc. In particular, the requirement to support
XPath 1.0 as XProc's expression language has been relaxed and the
two XSLT steps have been combined into a single step.</para>

<para>The Working Group has not finished addressing all of the
outstanding comments on its previous draft but feels that the XPath
change in particular has such a pervasive impact on the language that
it has decided to publish a new draft immediately in order to expose
this decision. User and implementor feedback on this decision would be
most valuable.</para>

<para>The
following changes are reflected in this draft:</para>

<itemizedlist>
<listitem>
<para>Attempt to support both XPath 1.0 and XPath 2.0; there's more to
be done, but see <xref linkend="xpath-context"/>.
</para>
</listitem>
<listitem>
<para>Support both XSLT 1.0 and XSLT 2.0 in a single
<tag>p:xslt</tag> step.
</para>
</listitem>
<listitem>
<para>Removed implicit pipeline inputs and outputs, see
<xref linkend="primary-input-output"/>.</para>
</listitem>
<listitem>
<para>Added <tag>p:hash</tag>, <tag>p:uuid</tag>,
<tag>p:www-form-urldecode</tag>, and <tag>p:www-form-urlencode</tag>.
</para>
</listitem>
<listitem>
<para>Attempt to support default bindings on
<tag>p:input</tag>.
</para>
</listitem>
<listitem>
<para>Added <xref linkend="security-considerations"/>.</para>
</listitem>
<listitem>
<para>Added a <literal>p:language</literal> system property.</para>
</listitem>
<listitem>
<para>Added <option>fixup-xml-base</option> and <option>fixup-xml-lang</option>
options to <tag>p:xinclude</tag>.</para>
</listitem>
<listitem>
<para>Renamed <literal>c:http-request</literal> to <tag>c:request</tag> and
<literal>c:http-response</literal> to <tag>c:response</tag>.</para>
</listitem>
</itemizedlist>

<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 <glossterm>pipeline</glossterm> consists of steps. Like pipelines, steps take zero or
more XML documents as their inputs and produce zero or more XML
documents as their outputs. The inputs 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
control the execution of other steps, which they include in the form
of one or more subpipelines.</para>

<para>This specification defines a standard library,
<xref linkend="std-components"/>, of steps.
Pipeline implementations <rfc2119>may</rfc2119> support additional types of
steps as well.
</para>

<para><xref linkend="fig-xival"/> is a graphical representation of a
simple pipeline that performs XInclude processing and validation on a
document.</para>

<figure xml:id="fig-xival">
<title>A simple, linear XInclude/Validate pipeline</title>
<mediaobject>
<alt>A simple, linear XInclude/Validate pipeline</alt>
<imageobject>
<imagedata fileref="graphics/sch-xinclude-validate-pipeline.png"/>
</imageobject>
</mediaobject>
</figure>

<para>This is a pipeline that consists of two atomic steps, XInclude and
Validate. The pipeline itself has two inputs, “source” (a source document)
and “schemas” (a list of W3C XML Schemas).
<impl>How inputs are connected to XML documents outside the pipeline
is <glossterm>implementation-defined</glossterm>.</impl>
The XInclude step reads the pipeline input “source” and produces a result
document. The Validate step reads the pipeline input “schemas” and
the output from the XInclude step and produces a
result document. The result of the validation, “result”,
is the result of the pipeline.
<impl>How pipeline outputs are connected to XML documents outside the pipeline is
<glossterm>implementation-defined</glossterm>.</impl></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="pipeline" xmlns:p="http://www.w3.org/ns/xproc"&gt;
  &lt;p:input port="source" primary="true"/&gt;
  &lt;p:input port="schemas" sequence="true"/&gt;
  &lt;p:output port="result"&gt;
    &lt;p:pipe step="validated" port="result"/&gt;
  &lt;/p:output&gt;

  &lt;p:xinclude name="included"&gt;
    &lt;p:input port="source"&gt;
      &lt;p:pipe step="pipeline" port="source"/&gt;
    &lt;/p:input&gt;
  &lt;/p:xinclude&gt;

  &lt;p:validate-with-xml-schema name="validated"&gt;
    &lt;p:input port="source"&gt;
      &lt;p:pipe step="included" port="result"/&gt;
    &lt;/p:input&gt;
    &lt;p:input port="schema"&gt;
      &lt;p:pipe step="pipeline" port="schemas"/&gt;
    &lt;/p:input&gt;
  &lt;/p:validate-with-xml-schema&gt;
&lt;/p:pipeline&gt;
</programlisting>
</example>

<para>The example in <xref linkend="ex1"/> is very verbose. It makes
all of the connections seen in the figure explicit. In practice,
pipelines do not have to be this verbose. XProc supports defaults for
many common cases. The same pipeline, using XProc defaults, is shown in
<xref linkend="ex1-abbr"/>.</para>

<example xml:id="ex1-abbr">
<title>A simple, linear XInclude/Validate pipeline (simplified)</title>
<programlisting>&lt;p:pipeline name="pipeline" xmlns:p="http://www.w3.org/ns/xproc"&gt;
  &lt;p:input port="source" primary="true"/&gt;
  &lt;p:input port="schemas" sequence="true"/&gt;
  &lt;p:output port="result"/&gt;

  &lt;p:xinclude/&gt;

  &lt;p:validate-with-xml-schema&gt;
    &lt;p:input port="schema"&gt;
      &lt;p:pipe step="pipeline" port="schemas"/&gt;
    &lt;/p:input&gt;
  &lt;/p:validate-with-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/ns/xproc"&gt;
&lt;p:input port="source"/&gt;
&lt;p:output port="result"/&gt;

  &lt;p:choose&gt;
    &lt;p:when test="/*[@version &amp;lt; 2.0]"&gt;
      &lt;p:validate-with-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-with-xml-schema&gt;
    &lt;/p:when&gt;

    &lt;p:otherwise&gt;
      &lt;p:validate-with-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-with-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>

<para>This example, like the preceding, relies on XProc defaults for simplicity.
It is always valid to write the fully explicit form if you prefer.</para>

</section>

<section xml:id="pipeline-concepts">
<title>Pipeline Concepts</title>

<para><termdef xml:id="dt-pipeline">A <firstterm>pipeline</firstterm>
is a set of connected steps, with outputs of one step flowing
into inputs of another.</termdef>
A pipeline is itself a
<glossterm>step</glossterm> and must satisfy the constraints on
steps.</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,
<glossterm baseform="option">options</glossterm>, and
<glossterm baseform="parameter">parameters</glossterm>)
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.</termdef> All steps have a
name; if the pipeline author does not provide a name for a step, a
default name is <link linkend="step-names">manufactured
automatically</link>.</para>

<para>Steps are either atomic or compound.
<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 <emphasis>types</emphasis> of atomic steps. The
standard library of atomic steps is described in
<xref linkend="std-components"/>, but implementations may provide others as
well. <impl>What additional step types, if any, are provided is
<glossterm>implementation-defined</glossterm>.</impl>
Each use, or instance, of an atomic step invokes the processing
defined by that type of step. A pipeline may contain instances of many
types of steps and many instances of the same type of step.</para>

<para>Compound steps, on the other hand, control and organize the flow of
documents through a pipeline, reconstructing familiar programming
language functionality such as conditionals, iterators and exception
handling. They contain other steps, whose evaluation
they control.</para>

<para><termdef xml:id="dt-compound-step">A <firstterm>compound
step</firstterm> is a step that contains one or more <glossterm baseform="subpipeline">subpipelines</glossterm>. 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> Every
compound step contains one or more subpipelines. <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 role="element-syntax element-syntax-language-construct">
<code>subpipeline</code> = (<tag>p:for-each</tag>|<tag>p:viewport</tag>|<tag>p:choose</tag>|<tag>p:group</tag>|<tag>p:try</tag>|<code xlink:href="#p.other">pfx:other-step</code>|<tag>p:documentation</tag>|<code xlink:href="#p.ignore-prefixes">ipfx:ignored</code>)*
</para>

<para>The simple distinction between atomic and compound steps is
occasionally stretched. The immediate children of some compound steps,
e.g. <tag>p:choose</tag> and <tag>p:try</tag>, are special. In the
case of <tag>p:choose</tag>, the <tag>p:when</tag> and
<tag>p:otherwise</tag> elements serve as wrappers around different
pipelines at most one of which will be processed. In the case of
<tag>p:try</tag>, the <tag>p:catch</tag> element is a wrapper around a
subpipeline that will only be processed if the initial
<tag>p:group</tag> fails. Acknowledging this slight irregularity, we
nevertheless treat all compound steps as if they directly contained
one or more subpipelines.</para>

<note xml:id="pipeline-compound-or-atomic">
<para>A <tag>p:pipeline</tag>, because it defines a subpipeline that can be called
from other pipelines, has a somewhat dual nature with respect to
the atomic vs. compound distinction. A <tag>p:pipeline</tag> is a
compound step. When it is invoked by name from some other pipeline,
its invocation is an <glossterm>atomic step</glossterm>. The “type” of the atomic step is
determined by the <tag>p:pipeline</tag> that defines it.</para>
</note>

<para>Steps have “ports” into which inputs and outputs are connected
or “<glossterm baseform="binding">bound</glossterm>”. Each step has a
number of input ports and a number of output ports; a step can have
zero input ports and/or zero output ports. (All steps have an implicit
output port for reporting errors that <rfc2119>must not</rfc2119> be
declared.) The names of all ports on each step must be unique on that
step (you can't have two input ports named “source”, nor can you have
an input port named “schema” and an output port named “schema”).
</para>

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

<para>Steps have parameter input ports, on which parameters can be
passed. The parameters passed on a particular <glossterm>parameter input port</glossterm>
must be uniquely named. If multiple parameters with the same name are
used, only one of the values will actually be available to the step.
A step can have zero, one, or many parameter input ports, and each
parameter port can have zero or more parameters passed on it.
</para>

<section xml:id="step-names">
<title>Step names</title>

<para>The <tag class="attribute">name</tag> attribute on any step can be
used to give it a name. The name must be unique within its scope,
see <xref linkend="scoping"/>.</para>

<para>If the pipeline author does not provide an explicit name, the processor
manufactures a default name. All default names are of the form
“<literal>!</literal><replaceable>n</replaceable>” where
“<replaceable>n</replaceable>” is the ordinal number of the step, considering
all steps in document order. For example, consider the pipeline in
<xref linkend="ex2"/>. The <tag>p:pipeline</tag> step has no name,
so it gets the default name “<literal>!1</literal>”; the
<tag>p:choose</tag> gets the name “<literal>!2</literal>”; the first
<tag>p:when</tag> gets the name “<literal>!3</literal>”, etc.
If the <tag>p:choose</tag> had had a name, it would not have received a default
name, but it would still have been counted and its first
<tag>p:when</tag> would still have been “<literal>!3</literal>”.</para>

<para>Providing every step in the pipeline with an interoperable name has
several benefits:</para>

<orderedlist>
<listitem><para>It provides a simple mechanism for identifying all steps
from outside the pipeline, see <xref linkend="app.mimetype"/>.</para></listitem>
<listitem><para>It allows implementors to refer to all steps in an interoperable
fashion, for example, in error messages.</para></listitem>
<listitem><para>Pragmatically, we say that <glossterm>readable ports</glossterm> are
identified by a step name/port name pair. By manufacturing names for otherwise
anonymous steps, we include implicit bindings without changing our
model.</para></listitem>
</orderedlist>

<para>In a valid pipeline that runs successfully to completion, the manufactured
names aren't visible (except perhaps in debugging or logging output).</para>

<note xml:id="def-name-ncname">
<para>The format for defaulted names does not conform to the
requirements of an
<link xlink:href="http://www.w3.org/TR/xml-names/#NT-NCName">NCName</link>.
This is an explicit design decision; it prevents pipelines from using
the defaulted names on <tag>p:pipe</tag> elements. If an explicit connection
is required, the pipeline author must provide an explicit name for the
step.</para>
</note>
</section>
</section>

<section xml:id="input-output">
<title>Inputs and Outputs</title>

<para>Although some steps can read and write non-XML resources, what
flows <emphasis>between</emphasis> steps through input ports and
output ports are exclusively XML documents or sequences of XML
documents.</para>

<para>For the purposes of this specification, an XML document is an
<biblioref linkend="xml-infoset-rec"/>. Implementations are free to
transmit infosets as sequences of characters, sequences of events,
object models, or any other representation that preserves the
necessary infoset properties (see <xref linkend="infoset-conformance"/>).</para>

<para>Most steps in this specification manipulate XML documents, or
portions of XML documents. In these cases, we speak of changing
elements, attributes, or nodes without prejudice to the actual
representation used by an implementation.</para>

<para>An implementation <rfc2119>may</rfc2119> make it possible for a
step to produce non-XML output (through channels other than a named
output port)—for example, writing a PDF document to a URI—but that
output cannot flow through the pipeline. Similarly, one can imagine a
step that takes no pipeline inputs, reads a non-XML file from a URI,
and produces an XML output. But the non-XML data cannot arrive on an
input port to a step.</para>

<para><error code="D0001">It is a <glossterm>dynamic error</glossterm>
if a non-XML resource is produced on a step output or arrives on a
step input.</error></para>

<para>The common case is that each step has one or more inputs and
one or more outputs. <xref linkend="fig-atomic-step"/> illustrates symbolically
an <glossterm>atomic step</glossterm> with two inputs and one output.</para>

<figure xml:id="fig-atomic-step">
<title>An atomic step</title>
<mediaobject>
<alt>An atomic step with two inputs and one output</alt>
<imageobject>
<imagedata fileref="graphics/atomic-step.png"/>
</imageobject>
</mediaobject>
</figure>

<para>All atomic steps are defined by a <tag>p:declare-step</tag>. The
declaration of an atomic step 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 subpipeline and one output. As you can see from the
diagram, the output from the compound step comes from one of the outputs
of the subpipeline within the step.</para>

<figure xml:id="fig-compound-step">
<title>A compound step</title>
<mediaobject>
<alt>A compound step with two inputs and one output</alt>
<imageobject>
<imagedata fileref="graphics/compound-step.png"/>
</imageobject>
</mediaobject>
</figure>

<para><termdef xml:id="dt-declared-inputs">The input ports declared on
a step are its <firstterm>declared inputs</firstterm>.</termdef>
<termdef xml:id="dt-declared-outputs">The output ports declared on a
step are its <firstterm>declared outputs</firstterm>.</termdef>
When a step is used in a pipeline, it is connected to other steps through
its inputs and outputs.
</para>

<para>When a step is used, all of the <glossterm>declared
inputs</glossterm> of the step <rfc2119>must</rfc2119> be connected. Each input can be
connected to:</para>

<itemizedlist>
<listitem>
<para>The output port of some other step.</para>
</listitem>
<listitem>
<para>A fixed, inline document or sequence of documents.</para>
</listitem>
<listitem>
<para>A document read from a URI.</para>
</listitem>
<listitem>
<para>One of the inputs declared on one of its ancestors.</para>
</listitem>
<listitem>
<para>A special port provided by an ancestor compound step, for example,
“<literal>current</literal>” in a <tag>p:for-each</tag> or <tag>p:viewport</tag>.
</para>
</listitem>
</itemizedlist>

<para>When an input accepts a sequence of documents, the documents can
come from any combination of these locations.</para>

<para>The <glossterm>declared outputs</glossterm> of a step 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 its container.
</para>
</listitem>
</itemizedlist>

<para>The <glossterm>primary output port</glossterm> of a step
<rfc2119>must</rfc2119> be connected, but other outputs can remain
unconnected. Any documents produced on an unconnected output port are
discarded. </para>

<para>Output ports on compound steps have a dual nature: from the
perspective of the compound step's siblings, its outputs are just
ordinary outputs and must be connected as described above. From the
perspective of the 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
<glossterm>atomic step</glossterm> (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. The error
output port is only bound to an input
in the catch clause of a <link linkend="p.try">try/catch</link>.
<impl>Outside of a <link linkend="p.try">try/catch</link>, the disposition of error
messages is <glossterm>implementation-dependent</glossterm></impl>.
</para>

<section xml:id="external-docs">
<title>External Documents</title>

<para>It's common for some of the documents used in processing a pipeline
to be read from URIs. Sometimes this occurs directly, for example with a
<tag>p:document</tag> element. Sometimes it occurs indirectly, for
example if an implementation allows the URI of a pipeline input to be
specified on the command line or if an <tag>p:xslt</tag> step
encounters an <tag>xsl:import</tag> in the stylesheet that it is processing.
It's also common for some of the documents produced in processing a
pipeline to be written to locations which have, or at least could have, a URI.
</para>

<para>The process of dereferencing a URI to retrieve a document is
often more interesting than it seems at first. On the web, it may
involve caches, proxies, and various forms of indirection.
<impl>Resolving a URI locally
may involve resolvers of various sorts and possibly appeal to
<glossterm>implementation-dependent</glossterm> mechanisms such as
catalog files.</impl></para>

<para>In XProc, the situation is made even more interesting by the
fact that many intermediate results produced by steps in the pipeline have
base URIs.<impl>Whether or not (and when and how) the
intermediate results that pass between steps are ever written to a filesystem is
<glossterm>implementation-dependent</glossterm>.</impl></para>

<para><impl>In Version 1.0 of XProc, how (or if) implementers provide local
resolution mechanisms and how (or if) they provide access to intermediate
results by URI is <glossterm>implementation-defined</glossterm>.</impl>
</para>

<note>
<para>On the one hand, this is a somewhat unsatisfying state of
affairs because it leaves room for interoperability problems. On the other,
it is not expected to cause such problems very often in practice.
</para>

<para>If these problems arise in practice, implementers are encouraged
to use the existing extension mechanisms to give users the control
needed to circumvent them. Should such mechanisms become widespread, a
standard mechanism could be added in some future version of the
language.</para>
</note>
</section>
</section>

<section xml:id="primary-input-output">
<title>Primary Inputs and Outputs</title>

<para>As a convenience for pipeline authors, each step may have one
input port designated as the primary input port and one output port
designated as the primary output port.</para>

<para><termdef xml:id="dt-primary-input-port">If a step has a document input
port which is explicitly marked “<code>primary='true'</code>”, or if it has
exactly one document input port and that port is <emphasis>not</emphasis>
explicitly marked “<code>primary='false'</code>”, then that input port
is the <firstterm>primary input port</firstterm> of the step.</termdef>
If a step has a single input port and that port is explicitly marked
“<code>primary='false'</code>”, or if a step has more than one input
port and none is explicitly marked as the primary, then the primary
input port of that step is undefined.</para>

<para><termdef xml:id="dt-primary-output-port">If a step has a document output
port which is explicitly marked “<code>primary='true'</code>”, or if it has
exactly one document output port and that port is <emphasis>not</emphasis>
explicitly marked “<code>primary='false'</code>”, then that output port
is the <firstterm>primary output port</firstterm> of the step.</termdef>
If a step has a single output port and that port is explicitly marked
“<code>primary='false'</code>”, or if a step has more than one output
port and none is explicitly marked as the primary, then the primary
output port of that step is undefined.</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 compound step has no declared outputs and the
<glossterm>last step</glossterm> in its subpipeline has an unbound
primary output, then an implicit primary output port (named
“<literal>result</literal>”) will be added to the compound step (and
consequently the last step's primary output will be bound to
it). This rule does not apply to <tag>p:pipeline</tag> steps; all of the
inputs and outputs of a <tag>p:pipeline</tag> must be explicitly declared.</para>

<!--
<para>Additionally, if a <tag>p:pipeline</tag> has no declared inputs
and the first step in its subpipeline has an unbound primary input,
then an implicit primary input port (named
“<literal>source</literal>”) will be added to the
<tag>p:pipeline</tag> (and consequently bound to the first step's
primary input port). If a compound step has no declared outputs and
the <glossterm>last step</glossterm> in its subpipeline has an unbound
primary output, then an implicit primary output port (named
“<literal>result</literal>”) will be added to the compound step (and
consequently the last step's primary output will be bound to
it).</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><xi:include href="examples/simple-default.txt"
parse="text"/></programlisting>

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

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

<para>(<glossterm baseform="parameter input port">Parameter input ports</glossterm>
are a special case discussed in <xref linkend="parameters"/>.)</para>
-->
</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 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 <glossterm>atomic step</glossterm> 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 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 on
parameter input ports.</para>

<para><termdef xml:id="dt-parameter-input-port">A
<firstterm>parameter input port</firstterm> is a distinguished kind of
input port which accepts (only) dynamically constructed parameter name/value
pairs.</termdef> See <xref linkend="parameter-inputs"/>.</para>

<para>Analogous to
<glossterm baseform="primary input port">primary input ports</glossterm>, steps
that have parameter inputs may designate at most one parameter input
port as a primary parameter input port.</para>

<para><termdef xml:id="dt-primary-parameter-input-port">If a step has
a parameter input port which is explicitly marked “<code>primary='true'</code>”,
or if it has exactly one parameter input port and that port is
<emphasis>not</emphasis> explicitly marked “<code>primary='false'</code>”, then
that parameter input port is the <firstterm>primary parameter input port</firstterm>
of the step.</termdef>
If a step has a single parameter input port and that port is
explicitly marked “<code>primary='false'</code>”, or if a step has
more than one parameter input port and none is explicitly marked as
the primary, then the primary parameter input port of that step is
undefined.</para>

<para>Additionally, if a <tag>p:pipeline</tag> does not declare any
parameter input ports, but contains a step which has a primary parameter input port,
then an implicit primary parameter input port (named “<literal>parameters</literal>”)
will be added to the pipeline. (If the pipeline declares an ordinary input named
“<literal>parameters</literal>”, the implicit primary parameter input port will
be named “<literal>parameters1</literal>”. If that's not available, then
“<literal>parameters2</literal>”, etc. until an available name is found.)</para>

<para><impl>How an implementation maps parameters specified to the application, or through
some API, to parameters accepted by the <tag>p:pipeline</tag> is
<glossterm>implementation-defined</glossterm>.</impl></para>

</section>

<section xml:id="connections">
<title>Connections</title>

<para>Steps are connected together by their input ports and output
ports. <error code="S0001">It is a <glossterm>static error</glossterm>
if there are any loops in the connections between steps: no step can
be connected to itself nor can there be any sequence of connections
through other steps that leads back to itself.</error></para>

<section xml:id="namespace-fixup">
<title>Namespace Fixup on Outputs</title>

<para>XProc processors are expected, and sometimes required, to
perform <glossterm>namespace fixup</glossterm>. Unless the semantics
of a step explicitly says otherwise:</para>

<itemizedlist>
<listitem>
<para>The in-scope namespaces associated with a node (even those that
are inherited from namespace bindings that appear among its ancestors
in the document in which it appears initially) are assumed to travel
with it.</para>
</listitem>
<listitem>
<para>Changes to one part of a tree (wrapping or unwrapping a node or
renaming an element, for example) do not change the in-scope
namespaces associated with the descendants of the node so changed.</para>
</listitem>
</itemizedlist>

<para>As a result, some steps can produce XML documents which have no
direct serialization (because they include nodes with conflicting or
missing namespace declarations, for example).
<termdef xml:id="dt-namespace-fixup">To produce a serializable
<glossterm>XML</glossterm> document, the XProc processor must
sometimes add additional namespace nodes, perhaps even renaming
prefixes, to satisfy the constraints of <glossterm>Namespaces in
XML</glossterm>. This process is referred to as <firstterm>namespace
fixup</firstterm>.</termdef>
</para>

<para>Implementors are encouraged to perform <glossterm>namespace
fixup</glossterm> before passing documents between steps, but they are
not required to do so. Conversely, an implementation which
<emphasis>does</emphasis> serialize between steps and therefore must
perform such fixups, or reject documents that cannot be serialized, is
also conformant.</para>

<para>Except where the semantics of a step explicitly require changes,
processors are required to preserve the information in the
documents and fragments they manipulate. In
particular, the information corresponding to the
<biblioref linkend="xml-infoset-rec"/>
properties
<literal role="infoset-property">attributes</literal>,
<literal role="infoset-property">base URI</literal>,
<literal role="infoset-property">children</literal>,
<literal role="infoset-property">local name</literal>,
<literal role="infoset-property">namespace name</literal>,
<literal role="infoset-property">normalized value</literal>,
<literal role="infoset-property">owner</literal>, and
<literal role="infoset-property">parent</literal>
<rfc2119>must</rfc2119> be preserved.</para>

<para>The information corresponding to
<literal role="infoset-property">prefix</literal>,
<literal role="infoset-property">in-scope namespaces</literal>,
<literal role="infoset-property">namespace attributes</literal>, and
<literal role="infoset-property">attribute type</literal>
<rfc2119>should</rfc2119> be preserved, with changes to the first three only as
required for <glossterm>namespace fixup</glossterm>. In particular,
processors are encouraged to take account of prefix information in
creating new namespace bindings, to minimize negative impact on
prefixed names in content.</para>

<para><impl>Except for cases which are specifically called out in <xref linkend="std-components"/>, the extent to which namespace fixup, and
other checks for outputs which cannot be serialized,
are performed on intermediate outputs is
<glossterm>implementation-defined</glossterm>.</impl></para>

<para>Whenever an implementation serializes pipeline contents, for
example for pipeline outputs, logging, or as part of steps such as
<tag>p:store</tag> or <tag>p:http-request</tag>,
it is a
<link xlink:href="#err.D0001">dynamic error</link> if that
serialization could not be done so as to produce a document which is
both well-formed and namespace-well-formed, as specified in
<glossterm>XML</glossterm> and
<glossterm>Namespaces in XML</glossterm>,
regardless of what serialization method, if any, is called for.</para>
</section>
</section>

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

<para><termdef xml:id="dt-environment">The
<firstterm>environment</firstterm> of a step is the information
available to each instance of a step in a pipeline.</termdef>
Most of the information in the environment is static and can be computed
before evaluation of the pipeline begins. The values of the in-scope options
have to be calculated when the pipeline is being evaluated.
</para>

<para>The environment consists of:</para>

<orderedlist>
<listitem>
<para>A set of readable ports.
<termdef xml:id="dt-readable-ports">The
<firstterm>readable ports</firstterm> are the step name/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 type.</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
<glossterm baseform="contained steps">contained step</glossterm> is its
<glossterm>inherited environment</glossterm>.
<termdef xml:id="dt-inherited-environment">The <firstterm>inherited
environment</firstterm> of a
<glossterm baseform="contained steps">contained step</glossterm> is an environment that is the same
as the environment of its <glossterm>container</glossterm> with the
<link linkend="dt-standard-modifications">standard modifications</link>.
</termdef></para>

<para>The
<phrase xml:id="dt-standard-modifications">standard modifications</phrase>
made to an inherited environment are:</para>

<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 declared inputs of the container are added to the
<glossterm>readable ports</glossterm>.</para>
<para>In other words, contained steps can see the inputs to their container.</para>
</listitem>
<listitem>
<para>The union of all the declared outputs of all of the step's
<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 the
<glossterm>primary input port</glossterm> of the container, if it has one, otherwise
the default readable port 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-context">
<title>XPaths in XProc</title>

<para>XProc uses XPath as an expression language.
XPath expressions can occur in several places: on compound steps, in
the expressions used to compute option and parameter values,
and in <emphasis>values</emphasis> passed to atomic steps.</para>

<para>Broadly, these can be divided into two classes: expressions
evaluated by the XProc processor and expressions evaluated by the
implementations of individual steps.</para>

<para>This distinction can be seen in the following example:</para>

<programlisting>&lt;p:option name="home" value="http://example.com/docs"/&gt;

&lt;p:load name="read-from-home"&gt;
  &lt;p:option name="href" select="concat($home,'/document.xml')"/&gt;
&lt;/p:load&gt;

&lt;p:split-sequence name="select-chapters"&gt;
  &lt;p:input port="source" select="//section"/&gt;
  &lt;p:option name="test" value="@role='chapter'"/&gt;
&lt;/p:split-sequence&gt;
</programlisting>

<para>The <option>href</option> option of the <tag>p:load</tag> step
is evaluated by the XProc processor. The actual <literal>href</literal> option
received by the step is
simply the string literal “<uri>http://example.com/docs/document.xml</uri>”.
(The selection on the <literal>source</literal> input of the
<literal>select-chapters</literal> step is also evaluated by the XProc processor.)
</para>

<para>The XPath expression “<literal>@role='chapter'</literal>” is passed
literally to the <literal>test</literal> option on the
<tag>p:split-sequence</tag> step. That's because the nature of the
<tag>p:split-sequence</tag> is that <emphasis>it evaluates</emphasis> the expression.
Only some options on some steps expect XPath expressions.
</para>

<para>The XProc processor evaluates all of the XPath expressions in
<tag class="attribute">select</tag> attributes on steps, options,
parameters, and inputs and in <tag class="attribute">test</tag>
attributes on <tag>p:when</tag> steps. (XPath expressions in <tag class="attribute">value</tag> attributes are passed literally to the
step for evaluation.)</para>

<para>An XProc implementation can use <emphasis>either</emphasis>
<biblioref linkend="xpath"/> or <biblioref linkend="xpath2"/> to
evaluate these expressions. This is a compromise driven entirely by
the timing of XProc development. During the development of this
specification, the community indicated that it was too early to
mandate that all implementations use XPath 2.0 and too late to mandate
that all implementations use XPath 1.0.</para>

<para>Many, many expressions that are likely to be used in XProc pipelines
are the same in both versions (simple element tests, ancestor and descendant
tests, string-based attribute tests, etc.).</para>

<para>As an aid to interoperability, pipeline authors may indicate the
version of XPath that they are using. The attribute
<tag class="attribute">xpath-version</tag> may be used on <tag>p:pipeline</tag>
(or <tag>p:pipeline-library</tag>) to identify the XPath version that
<rfc2119>should</rfc2119> be used to evaluate XPath expressions on
the pipeline(s). This is a purely lexical identifier. If the
<tag class="attribute">xpath-version</tag> is specified
on a pipeline in a library, the version specified on the pipeline is used
for that pipeline; otherwise, the default version is “1.0”.</para>

<para>The following rules determine how the indicated version and the
implementation's actual version interact:</para>

<orderedlist>
<listitem>
<para>If the indicated version and the implementation version are the same,
then that version is used.</para>
</listitem>
<listitem>
<para>If the indicated version is 1.0 and the implementation uses XPath 2.0
(or later), the expression <rfc2119>must</rfc2119> be evaluated in
XPath 1.0 compatibility mode. <error code="S0046">It is a
<glossterm>static error</glossterm> if the processor does not support
XPath 1.0 compatibility mode.</error>
</para>
</listitem>
<listitem>
<para>If the indicated version is 2.0 (or later) and the implementation uses
XPath 1.0, the implementation <rfc2119>must not</rfc2119> evaluate any
expression that it cannot determine will give the same result in XPath 1.0
that it would have given if XPath 2.0 had been used. <error code="S0047">It is a
<glossterm>static error</glossterm> if the processor cannot determine that
the expression would yield the same result.</error>
</para>
</listitem>
</orderedlist>

<section xml:id="xproc-xpath-context">
<title>Processor XPath Context</title>

<para>When the XProc processor evaluates an XPath expression using
XPath 1.0, unless otherwise indicated by a particular step, it does so
with the following context:</para>

<variablelist>
<varlistentry>
<term>context node</term>
<listitem>
<para>The document node of a document. The document is either
specified with a <glossterm>binding</glossterm> or is taken from the
<glossterm>default readable port</glossterm>. <error code="D0008">It
is a <glossterm>dynamic error</glossterm> if a document sequence appears
where a document to be used as the context node is expected.</error>
</para>
<para>If there is no binding and there is no default readable port then
the context node is an empty document node.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>context position and context size</term>
<listitem>
<para>The context position and context size are both “1”.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>variable bindings</term>
<listitem>
<para>The <glossterm>in-scope options</glossterm> are available as variables.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>function library</term>
<listitem>
<para>The <biblioref linkend="xpath"/> core function library and the
<xref linkend="xpath-extension-functions"/>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>in-scope namespaces</term>
<listitem>
<para>The namespace bindings in-scope on the element where the expression occurred.
</para>
</listitem>
</varlistentry>
</variablelist>

<para>When the XProc processor evaluates an XPath expression using
XPath 2.0, unless otherwise indicated by a particular step, it does so
with the following static context:</para>

<variablelist>
<varlistentry>
<term>XPath 1.0 compatibility mode</term>
<listitem>
<para>Is true if the indicated XPath version is 1.0, false otherwise.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Statically known namespaces</term>
<listitem>
<para>The namespace declarations in-scope for the containing element or
made available through <tag>p:namespaces</tag>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Default element/type namespace</term>
<listitem>
<para>The null namespace.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Default function namespace</term>
<listitem>
<para>The <biblioref linkend="xpath2"/> function namespace.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>In-scope schema definitions</term>
<listitem>
<para>None.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>In-scope variables</term>
<listitem>
<para>The names of the <glossterm>in-scope options</glossterm> are available
as variables.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Context item static type</term>
<listitem>
<para>Document.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Function signatures</term>
<listitem>
<para>The signatures of the XPath 2.0 functions and the
<xref linkend="xpath-extension-functions"/>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Statically known collations</term>
<listitem>
<para>Implementation defined but <rfc2119>must</rfc2119> include
the Unicode codepoint collation.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Default collation</term>
<listitem>
<para>Unicode codepoint collation.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Base URI</term>
<listitem>
<para>The base URI of the element on which the expression occurs.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Statically known documents</term>
<listitem>
<para>None.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Statically known collections</term>
<listitem>
<para>None.</para>
</listitem>
</varlistentry>
</variablelist>

<para>And the following dynamic context:</para>

<variablelist>
<varlistentry>
<term>context item</term>
<listitem>
<para>The document node of a document. The document is either
specified with a <glossterm>binding</glossterm> or is taken from the
<glossterm>default readable port</glossterm>. <error code="D0008">It
is a <glossterm>dynamic error</glossterm> if a document sequence appears
where a document to be used as the context node is expected.</error>
</para>
<para>If there is no binding and there is no default readable port then
the context node is an empty document node.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>context position and context size</term>
<listitem>
<para>The context position and context size are both “1”.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Variable values</term>
<listitem>
<para>The values of the <glossterm>in-scope options</glossterm>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Function implementations</term>
<listitem>
<para>The XPath 2.0 functions and the
<xref linkend="xpath-extension-functions"/>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Current dateTime</term>
<listitem>
<para>An implementation defined point in time.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Implicit timezone</term>
<listitem>
<para><impl>The implicit timezone is <glossterm>implementation
defined</glossterm>.</impl></para>
</listitem>
</varlistentry>
<varlistentry>
<term>Available documents</term>
<listitem>
<para><impl>The set of available documents (those that may be retrieved with
a URI) is <glossterm>implementation dependent</glossterm>.</impl></para>
</listitem>
</varlistentry>
<varlistentry>
<term>Available collections</term>
<listitem>
<para>None.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Default collection</term>
<listitem>
<para>None.
</para>
</listitem>
</varlistentry>
</variablelist>
</section>

<section xml:id="step-xpath-context">
<title>Step XPath Context</title>

<para>When <emphasis>a step</emphasis> evaluates an XPath expression using
XPath 1.0, it does
so with the following context:</para>

<variablelist>
<varlistentry>
<term>context node</term>
<listitem>
<para>The document node that appears on the primary input port of the step,
unless otherwise specified by the step.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>context position and context size</term>
<listitem>
<para>The position and size are both “1”, unless otherwise specified by the step.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>variable bindings</term>
<listitem>
<para>None, unless otherwise specified by the step.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>function library</term>
<listitem>
<para>The <biblioref linkend="xpath"/> core function library, unless otherwise
specified by the step.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>in-scope namespaces</term>
<listitem>
<para>The set of namespace bindings provided by the XProc processor. The processor
computes this set of bindings by taking a union of the bindings on the step
element itself as well as the bindings on any of the options and parameters
used in computing values for the step
(see <xref linkend="opt-param-bindings"/>).</para>

<para><impl>The results of computing the union of namespaces in the
presence of conflicting declarations for a particular prefix are
<glossterm>implementation-dependent</glossterm>.</impl></para>
</listitem>
</varlistentry>
</variablelist>

<para>When a step evaluates an XPath expression using XPath 2.0,
unless otherwise indicated by a particular step, it does so
with the following static context:</para>

<variablelist>
<varlistentry>
<term>XPath 1.0 compatibility mode</term>
<listitem>
<para>Is true if the indicated XPath version is 1.0, false otherwise.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Statically known namespaces</term>
<listitem>
<para>The namespace declarations in-scope for the containing element or
made available through <tag>p:namespaces</tag>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Default element/type namespace</term>
<listitem>
<para>The null namespace.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Default function namespace</term>
<listitem>
<para>The <biblioref linkend="xpath2"/> function namespace.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>In-scope schema definitions</term>
<listitem>
<para>None.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>In-scope variables</term>
<listitem>
<para>None, unless otherwise specified by the step.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Context item static type</term>
<listitem>
<para>Document.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Function signatures</term>
<listitem>
<para>The signatures of the XPath 2.0 functions.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Statically known collations</term>
<listitem>
<para>Implementation defined but <rfc2119>must</rfc2119> include
the Unicode codepoint collation.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Default collation</term>
<listitem>
<para>Unicode codepoint collation.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Base URI</term>
<listitem>
<para>The base URI of the element on which the expression occurs.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Statically known documents</term>
<listitem>
<para>None.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Statically known collections</term>
<listitem>
<para>None.</para>
</listitem>
</varlistentry>
</variablelist>

<para>And the following dynamic context:</para>

<variablelist>
<varlistentry>
<term>context item</term>
<listitem>
<para>The document node of the document that appears on the primary
input of the step, unless otherwise specified by the step.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>context position and context size</term>
<listitem>
<para>The context position and context size are both “1”, unless
otherwise specified by the step.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Variable values</term>
<listitem>
<para>None, unless otherwise specified by the step.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Function implementations</term>
<listitem>
<para>The XPath 2.0 functions.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Current dateTime</term>
<listitem>
<para>An implementation defined point in time.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Implicit timezone</term>
<listitem>
<para><impl>The implicit timezone is <glossterm>implementation
defined</glossterm>.</impl></para>
</listitem>
</varlistentry>
<varlistentry>
<term>Available documents</term>
<listitem>
<para><impl>The set of available documents (those that may be retrieved with
a URI) is <glossterm>implementation dependent</glossterm>.</impl></para>
</listitem>
</varlistentry>
<varlistentry>
<term>Available collections</term>
<listitem>
<para>None.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Default collection</term>
<listitem>
<para>None.
</para>
</listitem>
</varlistentry>
</variablelist>
</section>

<section xml:id="xpath-extension-functions">
<title>XPath Extension Functions</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.
Various 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:language</varname></term>
<listitem>
<para>Returns a string which identifies the current language, for example,
for message localization purposes.
<impl>The exact format of the language string is
<glossterm>implementation defined</glossterm>.</impl></para>
</listitem>
</varlistentry>
<varlistentry><term><varname>p:product-name</varname></term>
<listitem>
<para>Returns a string containing the name of the implementation,
as defined by the implementer. This should normally remain constant from one
release of the product to the next. It should also be constant across
platforms in cases where the same source code is used to produce compatible
products for multiple execution platforms.</para>
</listitem>
</varlistentry>
<varlistentry><term><varname>p:product-version</varname></term>
<listitem>
<para>Returns a string identifying the version of the
implementation, as defined by the implementer. This should normally vary
from one release of the product to the next, and at the discretion of the
implementer it may also vary across different execution platforms.
</para>
</listitem>
</varlistentry>
<varlistentry><term><varname>p:vendor</varname></term>
<listitem>
<para>Returns a string which identifies the vendor of the processor.</para>
</listitem>
</varlistentry>
<varlistentry><term><varname>p:vendor-uri</varname></term>
<listitem>
<para>Returns a URI which identifies the vendor of the processor. Often, this is
the URI of the vendor's web site.</para>
</listitem>
</varlistentry>
<varlistentry><term><varname>p:version</varname></term>
<listitem>
<para>Returns the version of XProc implemented by the processor; for processors 
implementing the version of XProc specified by this document, the value is “1.0”.
The value of the version attribute is a token (i.e., an
<literal>xs:token</literal> per <biblioref linkend="xmlschema-2"/>).</para>
</listitem>
</varlistentry>
<varlistentry><term><varname>p:xpath-version</varname></term>
<listitem>
<para>Returns the version of XPath implemented by the processor for evaluating
XPath expressions on XProc elements.</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-position">
<title>Iteration Position</title>

<para>In the context of a <tag>p:for-each</tag> or a
<tag>p:viewport</tag>, the <function>p:iteration-position</function>
function reports the position of the document being processed in the
sequence of documents that will be processed. In the context of other
standard XProc compound steps, it returns 1.</para>

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

<para><impl>In the context of an extension compound step, the value returned by
<function>p:iteration-position</function> is
<glossterm>implementation-defined</glossterm>.</impl></para>

</section>

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

<para>In the context of a <tag>p:for-each</tag> or a
<tag>p:viewport</tag>, the <function>p:iteration-size</function>
function reports the number of documents in the
sequence of documents that will be processed. In the context of other
standard XProc compound steps, it returns 1.</para>

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

<para><impl>In the context of an extension compound step, the value returned by
<function>p:iteration-size</function> is
<glossterm>implementation-defined</glossterm>.</impl></para>
</section>

<section xml:id="other-xpath-extension-functions">
<title>Other XPath Extension Functions</title>

<para><impl>It is <glossterm>implementation defined</glossterm> if the
processor supports any other XPath extension functions.</impl>
</para>
</section>
</section>
</section>

<section xml:id="security-considerations">
<title>Security Considerations</title>

<para>An XProc pipeline may attempt to access arbitrary network
resources: steps such as <tag>p:load</tag> and
<tag>p:http-request</tag> can attempt to read from an arbitrary URI;
steps such as <tag>p:store</tag> can attempt to write to an arbitrary
location.</para>

<para>In some environments, it may be inappropriate to provide the XProc
pipeline with access to these resources. In a server environment, for
example, it may be impractical to allow pipelines to store data. In
environments where the pipeline cannot be trusted, allowing the
pipeline to access arbitrary resources may be a security risk.</para>

<para>A conformant XProc processor may limit the resources available to any
or all steps in a pipeline. A conformant implementation may raise
dynamic errors, or take any other corrective action, for any security
problems that it detects.</para>
</section>
</section>

<section xml:id="syntax">
<title>Syntax Overview</title>

<para>This section describes the normative XML syntax of XProc. This
syntax is sufficient to represent all the aspects of a pipeline, as
set out in the preceding sections.
<termdef xml:id="dt-XML">XProc is intended to work equally
well with <biblioref linkend="xml10"/> and <biblioref linkend="xml11"/>.
Unless otherwise noted, the term “<firstterm>XML</firstterm>”
refers equally to both versions.</termdef>
<termdef xml:id="dt-Namespaces-in-XML">Unless otherwise noted, the term
<firstterm>Namespaces in XML</firstterm> refers equally to
<biblioref linkend="xmlns10"/> and <biblioref linkend="xmlns11"/>.</termdef>
<impl>Support for
pipeline documents written in XML 1.1 and pipeline inputs and outputs
that use XML 1.1 is <glossterm>implementation-defined</glossterm>.</impl>
</para>

<para>Elements in a pipeline document represent the pipeline,
the steps it contains, the connections between those steps, the steps
and connections contained within them, and so on. Each step is represented
by an element; a combination of elements and attributes specify
how the inputs and outputs of each step are connected and how options and parameters
are passed.</para>

<para>Conceptually, we can speak of steps as objects that have
inputs and outputs, that are connected together and which may
contain additional steps. Syntactically, we need a mechanism
for specifying these relationships.</para>

<para><glossterm baseform="container">Containment</glossterm> is
represented naturally using nesting of XML elements. If a particular element
identifies a <glossterm>compound step</glossterm> then the step elements that
are its immediate children form its <glossterm>subpipeline</glossterm>.</para>

<para>The connections
between steps are expressed using names and references to those
names.</para>

<para>Six kinds of things are named in XProc:</para>

<orderedlist spacing="compact">
<listitem>
<simpara>Step types,</simpara>
</listitem>
<listitem>
<simpara>Steps,</simpara>
</listitem>
<listitem>
<simpara>Input ports (both parameter and document),</simpara>
</listitem>
<listitem>
<simpara>Output ports,</simpara>
</listitem>
<listitem>
<simpara>Options, and</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/ns/xproc</uri></term>
<listitem>
<para>The namespace of the XProc XML vocabulary described by this
specification; by convention, the namespace prefix
“<literal>p:</literal>” is used for this namespace.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><uri type="xmlnamespace">http://www.w3.org/ns/xproc-step</uri></term>
<listitem>
<para>The namespace used for documents that are inputs to and outputs
from several standard and optional steps described in this
specification. Some steps, such as <tag>p:http-request</tag> and
<tag>p:store</tag>, have defined input or output vocabularies. We use
this namespace for all of those documents. The conventional prefix
“<literal>c:</literal>” is used for this namespace.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><uri type="xmlnamespace">http://www.w3.org/ns/xproc-error</uri></term>
<listitem>
<para>The namespace used for errors. The conventional prefix
“<literal>err:</literal>” is used for this namespace.
</para>
</listitem>
</varlistentry>
</variablelist>
</section>

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

<para>The scope of the names of the step types is the union of all the
pipelines and pipeline libraries available directly or via
<tag>p:import</tag>.</para>

<para>Step types are:</para>

<itemizedlist>
<listitem><para>Built-in to XProc (e.g., <tag>p:pipeline</tag>, <tag>p:choose</tag>, etc.)
</para></listitem>
<listitem><para>Declared with <tag>p:declare-step</tag> (e.g, <tag>p:xslt</tag>, <tag>p:xinclude</tag>, etc.)
</para></listitem>
<listitem><para>Defined with <tag>p:pipeline</tag>.</para></listitem>
<listitem><para>Or built-in as extensions by a particular processor.</para></listitem>
</itemizedlist>

<para><error code="S0036">All the step types in a pipeline
<rfc2119>must</rfc2119> have unique names: it is a <glossterm>static
error</glossterm> if any step type name is built-in and/or declared or defined
more than once in the
same scope.</error></para>

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

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

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

<para>The scope of option names is the step on which they occur and
the descendants of that step. The names of all of the options
specified on a step must be unique. If a step specifies a value for an
option with the same name as some option specified on one of its
ancestors, the new value shadows the previous value on the current
step and its descendants.</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>
</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: <glossterm>by source</glossterm>, <glossterm>by URI</glossterm>,
by providing an <glossterm>inline document</glossterm>, or by making it
<glossterm baseform="empty-sequence">explicitly empty</glossterm>.
Each of these mechanisms is allowed on the
<tag>p:input</tag>, <tag>p:output</tag>, <tag>p:xpath-context</tag>,
<tag>p:iteration-source</tag>, and <tag>p:viewport-source</tag>
elements.</para>

<variablelist>
<varlistentry>
<term>Specified by URI</term>
<listitem>
<para><termdef xml:id="dt-by-URI">A document is specified
<firstterm>by URI</firstterm> if it is referenced with a URI.</termdef>
The <tag class="attribute">href</tag>
attribute on the <tag>p:document</tag> 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>source</literal>” input to the
<tag>p:xinclude</tag> step named
“<literal>expand</literal>” comes from the “<literal>result</literal>”
port of the step named “<literal>otherstep</literal>”.</para>

<programlisting>&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 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”. The pipeline processor
passes them literally to the port, even if they contain elements from
the XProc namespace or ignored namespaces that would have other
semantics outside of the <tag>p:inline</tag>.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Specified explicitly empty</term>
<listitem>
<para><termdef xml:id="dt-empty-sequence">An
<firstterm>empty sequence</firstterm> of documents is specified with the
<tag>p:empty</tag> element.</termdef>
</para>

<para>In this example, the “<literal>source</literal>”
input to the XSLT 2.0 step named
“<literal>generate</literal>” is explicitly empty:</para>

<programlisting>&lt;p:xslt name="generate" version="2.0"&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 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:xslt&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>

<para xml:id="empty-xpath-context">It is inconsistent with the
<biblioref linkend="xpath"/> specification to specify an empty binding
as the context for evaluating an XPath expression. When an empty
binding is specified for an XPath 1.0 expression, an empty document node
<rfc2119>must</rfc2119> be used instead as the context node.</para>

</listitem>
</varlistentry>
</variablelist>

<para>Note that a <tag>p:input</tag> or <tag>p:output</tag> element
may contain more than one <tag>p:pipe</tag>, <tag>p:document</tag>,
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="p.ignore-prefixes">
<title>Ignored namespaces</title>

<para>In order to facilitate
<glossterm baseform="extension element">extension elements</glossterm>, the
processor can be instructed to ignore elements from selected namespaces.
<termdef xml:id="dt-ignorable-element">Any element in an ignored namespace
is an <firstterm>ignorable element</firstterm>.</termdef></para>

<para><impl>If a processor
encounters an <glossterm>ignorable element</glossterm> as the child of a
<tag>p:pipeline</tag> or <tag>p:pipeline-library</tag> then it behaves in an
<glossterm>implementation-defined</glossterm> manner if it recognizes
the element, otherwise it <rfc2119>must</rfc2119> behave as if the element
(and its content) had not been present.</impl></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.</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 prefix list is not
the prefix of an in-scope namespace.</error></para>

<para>Ignored namespaces specified on a <tag>p:pipeline-library</tag>
are inherited by pipelines that occur within that library.</para>

<para><error code="S0015">It is a <glossterm>static error</glossterm>
to specify as an ignored namespace the XProc namespace,
the namespace of any imported <tag>p:pipeline</tag>,
or any namespace in which an <glossterm>atomic step</glossterm> is
<link linkend="p.declare-step">declared</link>.</error>
</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> Extension attributes
are always allowed and do not have to be declared with
<link linkend="p.ignore-prefixes">ignored namespaces</link>.
</para>

<para>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 role="unwrapped">implementation-defined</glossterm> or
<glossterm role="unwrapped">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><termdef xml:id="dt-extension-element">An <firstterm>extension
element</firstterm> is any element that is not in the XProc namespace
and is not a step.</termdef> 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 role="unwrapped">implementation-defined</glossterm> or
<glossterm role="unwrapped">implementation-dependent</glossterm>.</para>

<para>An element is only an extension element if it is an
<glossterm>ignorable element</glossterm> that occurs as a direct
child of a <tag>p:pipeline</tag> or <tag>p:pipeline-library</tag>.
</para>

<para>In other words, elements in a subpipeline are interpreted as
follows:</para>

<orderedlist spacing="compact">
  <listitem>
    <simpara>In XProc namespace?</simpara>
    <orderedlist spacing="compact">
      <listitem>
	<simpara>Names a built-in compound step? Check against grammar,
interpret per spec.</simpara>
      </listitem>
      <listitem>
	<simpara>Names a built-in atomic step? Check against grammar and
built-in declaration, interpret per spec.</simpara>
      </listitem>
      <listitem>
	<simpara>Otherwise, error.</simpara>
      </listitem>
    </orderedlist>
  </listitem>
  <listitem>
    <simpara>Is in ignorable namespace?</simpara>
    <orderedlist spacing="compact">
      <listitem>
	<simpara>Is a known extension? Process as appropriate.</simpara>
      </listitem>
      <listitem>
	<simpara>Otherwise, ignore.</simpara>
      </listitem>
    </orderedlist>
  </listitem>
  <listitem>
    <simpara>Names a declared step type? Check against grammar and supplied
step declaration, interpret per spec.</simpara>
  </listitem>
  <listitem>
    <simpara>Names a defined pipeline? Check against pipeline definition,
interpret per spec.</simpara>
  </listitem>
  <listitem>
    <simpara>Otherwise, error.</simpara>
  </listitem>
</orderedlist>
</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>

<para>The types given for attributes should be understood as
follows:</para>

<itemizedlist>
<listitem>
<para><type>ID</type>, <type>NCName</type>, <type>NMTOKEN</type>,
<type>NMTOKENS</type>, <type>anyURI</type>, <type>boolean</type>,
<type>integer</type>, <type>string</type>: As per <biblioref linkend="xmlschema-2"/> including whitespace
normalization as appropriate.</para>
</listitem>
<listitem>
<para><type>QName</type>: With whitespace normalization as per
<biblioref linkend="xmlschema-2"/> and according to the following
definition: <termdef xml:id="dt-QName">In the context of XProc, a
<firstterm>QName</firstterm> is almost always a QName in the
<glossterm>Namespaces in XML</glossterm> sense.
Note, however, that <tag>p:option</tag> and
<tag>p:parameter</tag> values can get their namespace declarations in
a non-standard way (with <tag>p:namespaces</tag>) and QNames that have
no prefix are always in no-namespace, irrespective of the default
namespace.</termdef>
</para>
</listitem>
<listitem>
<para><type>PrefixList</type>:
As a list with <literal role="infoset-property">item type</literal>
<type>NMTOKEN</type>,
per <biblioref linkend="xmlschema-2"/>, including whitespace normalization.
</para>
</listitem>
<listitem>
<para><type>XPathExpression</type>, <type>XSLTMatchPattern</type>:
As a string per <biblioref linkend="xmlschema-2"/>, including
whitespace normalization, and the further requirement to be a
conformant Expression per <biblioref linkend="xpath"/> or
<biblioref linkend="xpath2"/>, as appropriate,
or Match pattern per <biblioref linkend="xslt10"/>, respectively.
</para>
</listitem>
</itemizedlist>

<para>A number of errors apply generally:</para>

<itemizedlist>
<listitem>
<para><error code="S0008">It is a <glossterm>static error</glossterm>
if any element in the XProc namespace has attributes not defined by
this specification unless they are <glossterm baseform="extension attribute">extension attributes</glossterm>.</error>
</para>
</listitem>
<listitem>
<para><error code="S0038">It is a <glossterm>static error</glossterm>
if any required attribute is not provided.</error>
</para>
</listitem>
<listitem>
<para><error code="S0043">It is a <glossterm>static error</glossterm>
if any attribute value does not satisfy the type required for that
attribute.</error></para>
</listitem>
<listitem>
<para><error code="S0045">It is a <glossterm>static error</glossterm>
if any string that must be interpreted as a <glossterm>QName</glossterm>
uses a prefix for which there is not a namespace binding.</error>
</para>
</listitem>
<listitem>
<para><error code="S0044">It is a <glossterm>static error</glossterm>
if any element in the XProc namespace or any step has element children
other than those specified for it by this specification.
</error></para>
</listitem>
<listitem>
<para><error code="S0037">It is a <glossterm>static error</glossterm>
if any step contains text nodes that do not consist entirely of
whitespace.</error>
</para>
</listitem>
<listitem>
<para><error code="D0019">It is a <glossterm>dynamic error</glossterm>
if any option value does not satisfy the type required for that
option.</error>
</para>
</listitem>
</itemizedlist>

<para>If an XProc processor can determine statically that a dynamic
error will <emphasis>always</emphasis> occur, it
<rfc2119>may</rfc2119> report that error statically.</para>

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

<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><impl>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.</impl> 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 <glossterm>last step</glossterm> 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><impl>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.</impl></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 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>Example</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/ns/xproc"&gt;
&lt;p:input port="document" primary="true"/&gt;
&lt;p:input port="stylesheet"/&gt;
&lt;p:output port="result" primary="true"/&gt;

&lt;p:xinclude/&gt;

&lt;p:validate-with-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-with-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
subpipeline that only processes a single document, the
<tag>p:for-each</tag> construct can be used as a wrapper around that
subpipeline. The <tag>p:for-each</tag> will apply that subpipeline to
each document in the sequence in turn.</para>

<para>The result of the <tag>p:for-each</tag> is a sequence of
documents produced by processing each individual document in the input
sequence.
If the <tag>p:for-each</tag> has one or more output ports, what appears on
each of those ports is the sequence of documents that is the
concatenation of the sequence produced by each iteration of the
loop on the port to which it is connected.</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:iteration-source</tag> is
wrapped in a document node (unless it is a document) 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 <glossterm>last step</glossterm> in the subpipeline does
not have a primary output port.</error></para>

<section xml:id="for-each-xpath-context">
<title>XPath Context</title>

<para>Within a <tag>p:for-each</tag>, the
<function>p:iteration-position</function> and
<function>p:iteration-size</function>
are taken from the sequence of documents that will be processed by the
<tag>p:for-each</tag>. The total number of documents is the size; the
ordinal value of the current document (the document appearing on the
<literal>current</literal> port) is the position.</para>

<note xml:id="impl1">
<title>Note to implementers</title>
<para>In the case where no XPath expression that must
be evaluated by the processor makes any reference to
<function>p:iteration-size</function>, its value
does not actually have to be calculated (and the entire
input sequence does not, therefore, need to be buffered so that its size can
be calculated before processing begins).</para>
</note>
</section>

<section xml:id="example-for-each" role="tocsuppress">
<title>Example</title>

<para>A <tag>p:for-each</tag> might accept a sequence of chapters as its input,
process each chapter in turn with XSLT, a step that accepts only a
single input document, and produce a sequence of formatted chapters as
its output.</para>

<example xml:id="ex.p.for-each">
<title>A Sample For-Each</title>
<programlisting>&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
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 <glossterm>last step</glossterm> in the subpipeline does
not have a primary output port.</error></para>

<section xml:id="viewport-xpath-context">
<title>XPath Context</title>

<para>Within a <tag>p:viewport</tag>, the
<function>p:iteration-position</function> and
<function>p:iteration-size</function>
are taken from the sequence of documents that will be processed by the
<tag>p:viewport</tag>. The total number of documents is the size; the
ordinal value of the current document (the document appearing on the
<literal>current</literal> port) is the position.</para>

<note xml:id="impl2">
<title>Note to implementers</title>
<para>In the case where no XPath expression that must
be evaluated by the processor makes any reference to
<function>p:iteration-size</function>, its value
does not actually have to be calculated (and the entire
input sequence does not, therefore, need to be buffered so that its size can
be calculated before processing begins).</para>
</note>
</section>

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

<para>A <tag>p:viewport</tag> might accept an XHTML document as its input,
add an <tag>hr</tag> element at the beginning of all <tag>div</tag> elements that
have the class value “chapter”, 
and return an XHTML document that is the same as the original except
for that change.</para>

<example xml:id="ex.p.viewport">
<title>A Sample Viewport</title>
<programlisting>&lt;p:viewport match="h:div[@class='chapter']"
            xmlns:h="http://www.w3.org/1999/xhtml"&gt;
  &lt;p:insert position="first-child"&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;
</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 XPath expressions.</para>

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

<para>A <tag>p:choose</tag> has no inputs. It contains an arbitrary number of
alternative <glossterm baseform="subpipeline">subpipelines</glossterm>,
exactly one of which
will be evaluated.</para>

<para>The list of alternative subpipelines consists of zero or more
subpipelines guarded by an XPath expression, followed optionally by a
single default subpipeline.</para>

<para>The <tag>p:choose</tag> considers each subpipeline in turn and selects
the first (and only the first) subpipeline for which the guard
expression evaluates to true in its context.
If there are no subpipelines for which the expression evaluates to
true, the default subpipeline, if it was specified, is
selected.</para>

<para>After a <glossterm>subpipeline</glossterm> is selected, it is
evaluated as if only it had been present.</para>

<para>The outputs of the <tag>p:choose</tag> are taken from the outputs
of the selected <glossterm>subpipeline</glossterm>. The <tag>p:choose</tag>
has the same number of outputs as the selected subpipeline with the same
names. If the selected subpipeline has a <glossterm>primary output
port</glossterm>, the port with the same name on the <tag>p:choose</tag>
is also a primary output port.</para>

<para>In order to ensure that the 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 of outputs with the same names. If any of the subpipelines
specifies a <glossterm>primary output port</glossterm>, each subpipeline must
specify exactly the same output as primary.
<error code="S0007">It is a 
<glossterm>static error</glossterm> if two
<glossterm baseform="subpipeline">subpipelines</glossterm>
in a <tag>p:choose</tag> declare different outputs.</error></para>

<para><error code="D0004">It is a <glossterm>dynamic error</glossterm>
if no <glossterm>subpipeline</glossterm> is selected by the <tag>p:choose</tag>
and no default is provided.</error></para>

<para>The <tag>p:choose</tag> can specify the context node against
which the XPath
expressions that occur on each branch are evaluated. The context node
is specified as a <glossterm>binding</glossterm> for the
<tag>p:xpath-context</tag>. If no binding is provided, the default
<tag>p:xpath-context</tag> is the document on the <glossterm>default
readable port</glossterm>.
</para>

<para>Each conditional <glossterm>subpipeline</glossterm> is
represented by a <tag>p:when</tag> element. The default branch is
represented by a <tag>p:otherwise</tag> element.</para>

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

<para>An XPath context specifies
the context against which an 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>.
No <tag class="attribute">select</tag> expression is allowed.
<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>If the context node is bound to <tag>p:empty</tag>, or is unbound
and the <glossterm>default readable port</glossterm> is undefined, an
<link linkend="empty-xpath-context">empty document node</link> is used
instead as the context.</para>
</section>

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

<para>A when specifies one subpipeline guarded by a test expression.</para>

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

<para>Each <tag>p:when</tag> branch of the <tag>p:choose</tag> has a
<tag class="attribute">test</tag> attribute which
<rfc2119>must</rfc2119> contain an XPath
expression. That XPath expression's effective boolean value is the
guard expression for the <glossterm>subpipeline</glossterm> contained
within that <tag>p:when</tag>.</para>

<para><error code="D0020">It is a <glossterm>dynamic error</glossterm>
if the value of the <tag class="attribute">test</tag> attribute is not
a valid XPath expression.</error></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>p:xpath-context</tag>.
If no context is specified on the <tag>p:when</tag>, the context
of the <tag>p:choose</tag> is used.</para>
</section>

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

<para>An otherwise specifies the default branch; the subpipeline selected if
no test expression on any preceding <tag>p:when</tag> evaluates to true.</para>

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

<!--
<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>Example</title>

<para>A <tag>p:choose</tag> might test the version attribute of the document
element and validate with an appropriate schema.</para>

<example xml:id="ex.p.choose">
<title>A Sample Choose</title>
<programlisting>&lt;p:choose name="version"&gt;
  &lt;p:when test="/*[@version = 2]"&gt;
    &lt;p:validate-with-xml-schema&gt;
      &lt;p:input port="schema"&gt;
	&lt;p:document href="v2schema.xsd"/&gt;
      &lt;/p:input&gt;
    &lt;/p:validate-with-xml-schema&gt;
  &lt;/p:when&gt;

  &lt;p:when test="/*[@version = 1]"&gt;
    &lt;p:validate-with-xml-schema&gt;
      &lt;p:input port="schema"&gt;
	&lt;p:document href="v1schema.xsd"/&gt;
      &lt;/p:input&gt;
    &lt;/p:validate-with-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:output port="result"&gt;
      &lt;!-- this output is necessary so that all the branches have
           the same outputs; it'll never really matter because
	   we're just about to raise an error. --&gt;
      &lt;p:inline&gt;
	&lt;nop/&gt;
      &lt;/p:inline&gt;
    &lt;/p:output&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>Example</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</title>

<para>A try/catch is specified by the <tag>p:try</tag> element. It
isolates a <glossterm>subpipeline</glossterm>, preventing any dynamic errors
that arise within it from being exposed to the rest of the
pipeline.</para>

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

<para>The <tag>p:group</tag> represents the initial subpipeline and
the recovery (or “catch”) pipeline is identified with a
<tag>p:catch</tag> element.</para>

<para>The <tag>p:try</tag> step evaluates the initial subpipeline and,
if no errors occur, the results of that pipeline are the results of
the <tag>p:try</tag> step. However, if any errors occur, the
<tag>p:try</tag> abandons the first subpipeline, discarding any output
that it might have generated, and evaluates the recovery
subpipeline.</para>

<para>If the recovery subpipeline is evaluated, the 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>The outputs of the <tag>p:try</tag> are taken from the outputs
of the initial subpipeline or the recovery subpipeline if an error occurred
in the initial subpipeline. The <tag>p:try</tag>
has the same number of outputs as the selected subpipeline with the same
names. If the selected subpipeline has a <glossterm>primary output
port</glossterm>, the port with the same name on the <tag>p:choose</tag>
is also a primary output port.</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>A pipeline author can cause an error to occur with the 
<tag>p:error</tag> step.</para>


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

<para>The environment inherited by its initial subpipeline, the
<tag>p:group</tag>, is the environment of the <tag>p:try</tag>.</para>
-->

<para>The recovery subpipeline of a <tag>p:try</tag>
is identified with a <tag xml:id="p.catch">p:catch</tag>:</para>

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

<!--
<para>The environment of a <tag>p:catch</tag> is the environment of
its containing <tag>p:try</tag>.</para>
-->

<para>The environment inherited by the <glossterm>contained
steps</glossterm> of the <tag>p:catch</tag> is the <glossterm>inherited
environment</glossterm> with
this modification:</para>

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

<para>What appears on the <code>error</code> port is an
<link linkend="err-vocab">error document</link>. The error
document may contain messages generated by steps that were part of the initial
subpipeline. Not all messages that appear are indicative of errors; for example,
it is common for all <tag>xsl:message</tag> output from the XSLT component to
appear on the <code>error</code> port. It is possible that the component which
fails may not produce any messages at all. It is also possible that the failure
of one component may cause others to fail so that there may be multiple failure messages
in the document.</para>

<section xml:id="err-vocab">
<title>The Error Vocabulary</title>

<para>In general, it is very difficult to predict error behavior. Step failure
may be catastrophic (programmer error), or it may be be the result of user error,
resource failures, etc. Steps may detect more than one error, and the failure of
one step may cause other steps to fail as well.</para>

<para>The <tag>p:try</tag>/<tag>p:catch</tag> mechanism gives pipeline authors
the opportunity to process the errors that caused the <tag>p:try</tag> to fail.
In order to facilitate some modicum of interoperability among processors, errors
that are reported on the <literal>error</literal> port of a
<tag>p:catch</tag> <rfc2119>should</rfc2119> conform to the format described here.
</para>

<section xml:id="cv.errors">
<title>c:errors</title>

<para>The error vocabulary consists of a root element, <tag>c:errors</tag>
which contains zero or more <tag>c:error</tag> elements.</para>

<e:rng-pattern name="Errors"/>
</section>

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

<para>Each specific error is represented by an <tag>c:error</tag> element:</para>

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

<para>The <tag class="attribute">name</tag> and <tag class="attribute">type</tag>
attributes identify the name and type, respectively, of the step which failed.</para>

<para>The <tag class="attribute">code</tag> is a QName which identifies the error.
For steps which have defined error codes, this is an opportunity for the step
to identify the error in a machine-processable fashion. Many steps omit this
because they do not include the concept of errors identified by QNames.</para>

<para>If the error was caused by a specific document, or by the location of some
erroneous construction in a specific document, the
<tag class="attribute">href</tag>, <tag class="attribute">line</tag>,
<tag class="attribute">column</tag>, and <tag class="attribute">offset</tag>
attributes identify this location. Generally, the error location is identified
either with line and column numbers or with an offset from the beginning of
the document, but not usually both.</para>

<para>The content of the <tag>c:error</tag> element is any well-formed XML.
Specific steps, or specific implementations, may provide more detail about the
format of the content of an error message.</para>
</section>

<section xml:id="error-example">
<title>Error Example</title>

<para>Consider the following XSLT stylesheet:</para>

<programlisting><![CDATA[<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

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

</xsl:stylesheet>]]></programlisting>

<para>If it was used in a step named “xform” in a <tag>p:try</tag>,
the following error document might be produced:</para>

<programlisting><![CDATA[<c:errors xmlns:c="http://www.w3.org/2007/03/xproc-step">
  <c:error name="xform" type="p:xslt"
             href="style.xsl" line="6">This stylesheet is <emph>pointless</emph>.</c:error>
</c:errors>]]></programlisting>

<para>It is not an error for steps to generate non-standard error output as long
as it is well-formed.</para>

</section>
</section>

<!--
<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>Example</title>

<para>A pipeline might attempt to process a document by dispatching it
to some web service. If the web service succeeds, then those results
are passed to the rest of the pipeline. However, if the web service
cannot be contacted or reports an error, the <tag>p:catch</tag> step can
provide some sort of default for the rest of the pipeline.</para>

<example xml:id="ex.p.trycatch">
<title>An Example Try/Catch</title>
<programlisting>&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: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: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. For example, other atomic steps:</para>

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

<para>Each <glossterm>atomic step</glossterm> 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><impl>The presence of other compound steps is
<glossterm>implementation-defined</glossterm>; XProc provides no standard
mechanism for defining them or describing what they can contain.</impl></para>

<para><error code="S0010">It is a <glossterm>static error</glossterm>
if a pipeline contains a step whose specified inputs, outputs, and
options do not <glossterm baseform="matches">match</glossterm> the
<glossterm>signature</glossterm> for steps of that
type.</error></para>

<para><error code="D0017">It is a <glossterm>dynamic error</glossterm>
if the running pipeline attempts to invoke a step which the processor
does not know how to perform.</error></para>

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

<para>Namespace qualified attributes on a step are
<glossterm baseform="extension attribute">extension attributes</glossterm>.
Attributes, other than <tag class="attribute">name</tag>, that are not
namespace qualified are treated as a syntactic shortcut for
specifying the value of an option. In other words, the following two
steps are equivalent:</para>

<para>The first step uses the standard <tag>p: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 <glossterm>atomic step</glossterm> 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</title>

<para>A <tag>p:input</tag> identifies an input port for a step. In
some contexts, <tag>p:input</tag> declares that a port with the
specified name exists and identifies the properties of that port. In
other contexts, it provides a binding for a port with a specified name
(in which case it must have been declared elsewhere). In some
contexts, it does both. The semantics of <tag>p:input</tag> are
complicated further by the fact that there are two kinds of inputs,
ordinary “document” inputs and “parameter” inputs.</para>

<para>On a <tag>p:declare-step</tag>, the <tag>p:input</tag> element
is only a declaration. On a <tag>p:pipeline</tag>, it is both a
declaration and a binding. In other contexts, it is only a
binding.</para>

<para>An input declaration may include a default binding. If no
binding is provided for an input port which has a default binding,
then the input is treated as if the default binding appeared.</para>

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

<para><error code="S0043">It is a <glossterm>static
error</glossterm> for a <tag>p:pipe</tag> to appear in a default
binding.</error>
</para>

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

<para>The declaration of a document input identifies the name of the port,
whether or not the port accepts a sequence, and whether or not the port is
a <glossterm>primary input port</glossterm>.</para>

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

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

<para>The <tag class="attribute">sequence</tag> attribute determines
whether or not a sequence of documents is allowed on the port.
<error code="D0006">If <tag class="attribute">sequence</tag> is not
specified, or has the value “false”, then it is a <glossterm>dynamic
error</glossterm> unless exactly one document appears
on the declared port.</error></para>

<para>The <tag class="attribute">primary</tag> attribute is used to identify
the <glossterm>primary input port</glossterm>.
An input port is a <glossterm>primary input port</glossterm> if
<tag class="attribute">primary</tag> is specified with the value “true”
or if the step has only a single input port and
<tag class="attribute">primary</tag> is not specified.
<error code="S0030">It is a <glossterm>static error</glossterm> to specify
that more than one input port is the primary.</error></para>

<para>The <tag class="attribute">kind</tag> attribute distinguishes between
the two kinds of inputs: document inputs and parameter inputs. An input port
is a document input port if <tag class="attribute">kind</tag> is specified
with the value “document” or if <tag class="attribute">kind</tag> is not
specified.</para>

<para>On <tag>p:declare-step</tag>, the <tag>p:input</tag> simply declares the
input port.
<error code="S0042">It is a <glossterm>static error</glossterm> if the
declaration of a document input port inside a <tag>p:declare-step</tag>.
</error> Document input port declarations must be empty unless
they are declaring <emphasis>and</emphasis> binding an input port
for a <tag>p:pipeline</tag>.</para>

<para>On an <glossterm>atomic step</glossterm>, it specifies 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></para>

<para>A <tag class="attribute">select</tag>
expression <rfc2119>may</rfc2119> also be provided with a binding. The
<tag class="attribute">select</tag> expression, if specified, applies the
specified XPath
select expression to the document(s) that are read.
Each selected node is wrapped in a document (unless it is a document)
and provided to the input port. In other words,</para>

<programlisting>&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" xmlns:html="http://www.w3.org/1999/xhtml"&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
<code>html:div</code> in <uri>http://example.org/input.html</uri>. (Note that
in the case of nested <code>html:div</code> elements, this may result in the same
content being returned in several documents.)</para>

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

<programlisting>&lt;p:input port="source" select="//html:div" xmlns:html="http://www.w3.org/1999/xhtml"&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
<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 element or document nodes.</error></para>

<para>When a <tag>p:input</tag> is used in any context where it
provides only a binding (e.g., on an atomic step), <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>
</section>

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

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

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

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

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

<para>The <tag class="attribute">primary</tag> attribute is used to identify
the <glossterm>primary parameter input port</glossterm>.
An input port is a <glossterm>primary parameter input port</glossterm> if
it is a <glossterm>parameter input port</glossterm> and
<tag class="attribute">primary</tag> is specified with the value “true”
or if the step has only a single parameter input port and
<tag class="attribute">primary</tag> is not specified.
<error code="S0030">It is a <glossterm>static error</glossterm> to specify
that more than one parameter input port is the primary.</error></para>

<para>The <tag class="attribute">kind</tag> attribute distinguishes between
the two kinds of inputs: document inputs and parameter inputs. An input port
is a parameter input port only if the <tag class="attribute">kind</tag>
attribute is specified with the value “parameter”.
<error code="S0033">It is a <glossterm>static
error</glossterm> to specify any kind of input other than “document”
or “parameter”.</error>
</para>

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

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

<para>When used on a step, parameter input ports always accept a
sequence of documents. If no binding is provided for a
<glossterm>primary parameter input port</glossterm>, then the port will be bound
to the primary parameter input port of the <tag>p:pipeline</tag> which contains
the step. If no binding is provided for a parameter input port other than the
primary parameter input port, then the port will be bound to an
<glossterm>empty sequence</glossterm>
of documents. <error code="S0035">It is a <glossterm>static error</glossterm> if
a primary parameter input port has no binding and the pipeline that contains
the step has no primary parameter input port.</error></para>

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

<para>All of the documents that appear on a parameter input must
either be <tag>c:parameter</tag> documents or <tag>c:parameter-set</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-set</tag>) to establish the value of the
named parameter. If the same name appears more than once, the last value specified
is used. If the step also has literal <tag>p: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> 

<para>Consider the example in <xref linkend="ex.parameter"/>.</para>

<example xml:id="ex.parameter">
<title>A Parameter Example</title>
<programlisting>&lt;p:pipeline name="main"
	    xmlns:p="http://www.w3.org/ns/xproc"
	    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
&lt;p:input port="source"/&gt;
&lt;p:input port="parameters" kind="parameter"/&gt;
&lt;p:output port="result"/&gt;

&lt;p:xslt&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="http://example.com/stylesheets/doc.xsl"/&gt;
  &lt;/p:input&gt;
  &lt;p:parameter name="output-type" value="html"/&gt;
  &lt;p:input port="parameters"&gt;
    &lt;p:pipe step="main" port="parameters"/&gt;
  &lt;/p:input&gt;
&lt;/p:xslt&gt;

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

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

<para>When the XSLT step runs, it will read those parameters and combine them with
any parameters specified literally on the step. Because the parameter input comes
<emphasis>after</emphasis> the literal declaration for <varname>output-type</varname>
on the step, the XSLT stylesheet will see both values that I passed in
(“<varname>output-type</varname>=<literal>fo</literal>” and
“<varname>profile</varname>=<literal>unclassified</literal>”).</para>

<para>If the parameter input came <emphasis>before</emphasis> the literal declaration,
then the XSLT stylesheet would see “<varname>output-type</varname>=<literal>html</literal>”
and
“<varname>profile</varname>=<literal>unclassified</literal>”.</para>

<para>Most stylesheets don't bother to declare parameter inputs, or provide explicit
bindings for them, and “the right thing” usually happens.</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.</para>

<para>If the
<tag class="attribute">namespace</tag> attribute is specified, then
the expanded name of the parameter is constructed from the specified
namespace and the local-name part of the
<tag class="attribute">name</tag> value (in other words, the prefix,
if any, is ignored).</para>

<para>If the
<tag class="attribute">namespace</tag> attribute is not specified,
and the <tag class="attribute">name</tag> contains a colon,
then the
expanded name of the parameter is constructed using the
<tag class="attribute">name</tag> value and the namespace declarations
in-scope on the <tag>c:parameter</tag> element.</para>

<para>If the
<tag class="attribute">namespace</tag> attribute is not specified,
and the <tag class="attribute">name</tag> does not contain a colon,
then the
expanded name of the parameter is in no namespace.</para>

<para>Any namespace-qualified attribute names that appear on the
<tag>c:parameter</tag> element are ignored. <error code="D0014">It is a
<glossterm>dynamic error</glossterm> for any unqualified attribute names
other than “<literal>name</literal>”, “<literal>namespace</literal>”,
or “<literal>value</literal>” to appear on a <tag>c:parameter</tag>
element.</error></para>
</section>

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

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

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

<para>The <tag>c:parameter-set</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 namespace-qualified attribute names that appear on the
<tag>c:parameter-set</tag> element are ignored. <error code="D0014">It
is a <glossterm>dynamic error</glossterm> for any unqualified
attribute names to appear on a <tag>c:parameter-set</tag>
element.</error></para>
</section>
</section>
</section>

<section xml:id="p.iteration-source">
<title>p:iteration-source</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</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> unless exactly one document
appears on the <tag>p:viewport-source</tag>.</error>
No <tag class="attribute">select</tag> expression is allowed.</para>
</section>

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

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

<para>A <tag>p:output</tag> identifies an output port, optionally
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 “true”,
then a sequence is allowed.
<error code="D0007">If <tag class="attribute">sequence</tag> is not
specified on <tag>p:output</tag>, or has the value “false”, then it is a
<glossterm>dynamic error</glossterm> if the step does not produce
exactly one document on the declared port.</error></para>

<para>The <tag class="attribute">primary</tag> attribute is used to
identify the primary output port. An output port is a primary output
port if <tag class="attribute">primary</tag> is specified with the value
“<literal>true</literal>” or if the step has only a single output port and
primary is not specified. <error code="S0014">It is a
<glossterm>static error</glossterm> to identify more than one output
port as primary.</error></para>

<para>On <glossterm baseform="compound step">compound steps</glossterm>,
the declaration <rfc2119>may</rfc2119> be accompanied by a
<glossterm>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</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.
<impl>If the <tag class="attribute">href</tag> attribute is not
specified, the location of the log file or files is
<glossterm>implementation-defined</glossterm>.</impl></para>

<para><impl>How a sequence
of documents is represented in a <tag>p:log</tag> is
<glossterm>implementation-defined</glossterm>.</impl></para>

<para><error code="S0026">It is a <glossterm>static error</glossterm> if the
port specified on the <tag>p:log</tag> is not the name of an output port
on the step in which it appears or if more than one <tag>p:log</tag>
element is applied to the same port.</error></para>

<para>Implementations may, at user option, ignore all <tag>p:log</tag>
elements.</para>

<note>
<para>This element represents a potential security risk: running
unexamined 3rd-party pipelines could result in vital system
resources being overwritten.</para>
</note>
</section>

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

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

<para>The <tag>p:serialization</tag> element allows the user to
request serialization properties on a <tag>p:pipeline</tag> output.
</para>

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

<para>If the pipeline processor serializes the output on the specified port,
it <rfc2119>must</rfc2119> use the serialization options specified. If the processor
is not serializing (if, for example, the pipeline has been called from another
pipeline), then the <tag>p:serialization</tag>
<rfc2119>must</rfc2119> be ignored. The processor
<rfc2119>may</rfc2119> reject statically a pipeline that requests
serialization options that it cannot provide.</para>

<para><impl>The default value of any unspecified serialization option is
<glossterm>implementation-defined</glossterm>.</impl></para>

<para>The semantics of the attributes on a <tag>p:serialization</tag> are
described in <xref linkend="serialization-options"/>.</para>

<para><error code="S0039">It is a <glossterm>static error</glossterm> if the
port specified on the <tag>p:serialization</tag> is not the name of an output port
on the pipeline in which it appears or if more than one <tag>p:serialization</tag>
element is applied to the same port.</error></para>

</section>

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

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

<para>Options and parameters are both name/value pairs. What
distinguishes them is whether or not the pipeline author is expected
to know their names in advance. Option names are always known and specified by
name. Parameter names may be known, in which case they can be specified by name
just like options, or they may be computed dynamically by the pipeline.</para>

<section xml:id="p.option">
<title>p:option</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 <glossterm>atomic step</glossterm>, it provides a value for one of
the declared options, overriding any default specified in the declaration.</para>
</listitem>
</orderedlist>

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

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

<para>Options are declared for atomic steps by putting 
<tag>p:option</tag> elements in the <tag>p:declare-step</tag> that
declares the atomic step type.</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>.</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>
<error code="S0017">It is a <glossterm>static error</glossterm> to specify
that an option is both <tag class="attribute">required</tag>
<emphasis>and</emphasis> has a default value.</error></para>
</section>

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

<para>Values are assigned to options on a particular 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.
</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
undeclared option on an atomic step.</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 as an XPath
expression using the context defined in <xref linkend="xproc-xpath-context"/>.
The XPath string value of the expression
becomes the value of the option.  Since all in-scope options are
present in the <citetitle>Processor XPath Context</citetitle> as
variable bindings, <tag class="attribute">select</tag> expressions may
refer to the value of 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>
<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>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>
If the context node is bound to <tag>p:empty</tag>, an
<link linkend="empty-xpath-context">empty document node</link> is used
instead as the context.</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>The <tag>p:namespaces</tag> element can be used to specify the namespace
bindings associated with the option, see
<xref linkend="opt-param-bindings"/>.</para>

<para>If the value of an option is a constant, and no namespace
bindings other than those in-scope on the step are necessary, 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, or if <tag class="attribute">value</tag> is
specified with a <glossterm>binding</glossterm>.</error>
</para>
</section>
</section>

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

<section xml:id="p.parameter">
<title>p:parameter</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. (Parameter names aren't known in advance; there's
no provision for declaring them.)</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>

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

<para>If a <tag class="attribute">select</tag> expression is given,
it is evaluated as an XPath
expression using the context defined in <xref linkend="xproc-xpath-context"/>.
The XPath string value of the expression
becomes the value of the parameter.  Since all in-scope options are
present in the <citetitle>Processor XPath Context</citetitle> as
variable bindings, <tag class="attribute">select</tag> expressions may
refer to the value of 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>
<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>

<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>
If the context node is bound to <tag>p:empty</tag>, an
<link linkend="empty-xpath-context">empty document node</link> is used
instead as the context.</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>

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

</section>

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

<para>Option and parameter values carry with them not only their literal
or computed string value but also a set of namespaces. To see why this is
necessary, consider the following step:</para>

<programlisting>&lt;p:delete xmlns:p="http://www.w3.org/ns/xproc"&gt;
  &lt;p:option name="match" value="html:div"
	    xmlns:html="http://www.w3.org/1999/xhtml"/&gt;
&lt;/p:delete&gt;
</programlisting>

<para>The <tag>p:delete</tag> step will delete elements that match the
expression “<literal>html:div</literal>”, but that expression can only be
correctly interpreted if there's a namespace binding for the prefix
“<literal>html</literal>” so that binding has to travel with the option.</para>

<para>The default namespace bindings associated with an option or parameter
value are computed as follows:</para>

<orderedlist>
<listitem>
<para>If the <tag class="attribute">select</tag> attribute was used to specify
the value and it contained a single <literal>VariableReference</literal>
(per <biblioref linkend="xpath"/> or <biblioref linkend="xpath2"/>, as
appropriate), then the namespace bindings from the referenced
option are used.</para>
</listitem>
<listitem>
<para>If the <tag class="attribute">select</tag> attribute was used to specify
the value and it evaluated to a node-set, then the in-scope namespaces from the
first node in the selected node-set (or, if it's not an element, its parent)
are used.</para>
<para>The expression is evaluated in the appropriate context,
See <xref linkend="xpath-context"/>.</para>
</listitem>
<listitem>
<para>Otherwise, the in-scope namespaces from the <tag>p:option</tag> or
<tag>p:parameter</tag> itself are used.</para>
</listitem>
</orderedlist>

<para>The default namespace is never included in the namespace bindings for
an <tag>p:option</tag> or <tag>p:parameter</tag>. Unqualified names are always
in no-namespace.</para>

<para>Unfortunately, in more complex situations, there may be no
single option or parameter that can reliably be expected to have the
correct set of namespace bindings. Consider this pipeline:</para>

<programlisting>&lt;p:pipeline type="ex:delete-in-div"
	    xmlns:p="http://www.w3.org/ns/xproc"
	    xmlns:ex="http://example.org/ns/ex"
	    xmlns:h="http://www.w3.org/1999/xhtml"&gt;
&lt;p:input port="source"/&gt;
&lt;p:output port="result"/&gt;
&lt;p:option name="divchild" required="true"/&gt;

&lt;p:delete&gt;
  &lt;p:option name="match" select="concat('h:div/',$divchild)"/&gt;
&lt;/p:delete&gt;

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

<para>It defines an atomic step
(“<literal>ex:delete-in-div</literal>”) that deletes elements that
occur inside of XHTML div elements. It might be used as
follows:</para>

<programlisting>&lt;ex:delete-in-div&gt;
  &lt;p:option name="divchild" select="html:p[@class='delete']"
	    xmlns:html="http://www.w3.org/1999/xhtml"/&gt;
&lt;/ex:delete-in-div&gt;
</programlisting>

<para>In this case, the <varname>match</varname> option passed to the
<tag>p:delete</tag> step needs <emphasis>both</emphasis> the namespace
binding of “<literal>h</literal>” specified in the
<tag>ex:delete-in-div</tag> pipeline definition
<emphasis>and</emphasis> the namespace binding of
“<literal>html</literal>” specified in the <varname>divchild</varname>
option on the call of that pipeline. It's not sufficient to provide
just one of the sets of bindings.</para>

<para xml:id="p.namespaces">The <tag>p:namespaces</tag> element can be
used as a child of <tag>p:option</tag> or <tag>p:parameter</tag>
to provide explicit bindings.</para>

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

<para>The namespace bindings specified by a <tag>p:namespaces</tag>
element are determined as follows:</para>

<orderedlist>
<listitem>
<para>If the <tag class="attribute">option</tag> attribute is specified,
it <rfc2119>must</rfc2119> contain the name of a single in-scope option.
The namespace bindings associated with that option are used;</para>
</listitem>
<listitem>
<para>If the <tag class="attribute">element</tag> attribute is specified,
it <rfc2119>must</rfc2119> contain an
XPath expression which identifies a single element node (the
input binding for this expression is the same as the binding
for the <tag>p:option</tag> or <tag>p:parameter</tag> which contains it). The
in-scope namespaces of that node are used;</para>
<para>The expression is evaluated in the appropriate context,
See <xref linkend="xpath-context"/>.</para>
</listitem>
<listitem>
<para>If neither <tag class="attribute">option</tag> nor
<tag class="attribute">element</tag> is specified, the in-scope namespaces
on the <tag>p:namespaces</tag> element itself are used.</para>
</listitem>
</orderedlist>

<para>Irrespective of how the set of namespaces are determined,
the <tag class="attribute">except-prefixes</tag> attribute can
be used to exclude one or more namespaces.
The value of the except-prefixes attribute
<rfc2119>must</rfc2119> be a sequence of tokens, each of which
<rfc2119>must</rfc2119> be bound to a
namespace in the in-scope namespaces of the <tag>p:namespaces</tag> element. All
bindings of prefixes to each of the namespaces thus identified are
excluded.</para>

<para><error code="S0041">It is a <glossterm>static error</glossterm>
to specify both <tag class="attribute">option</tag> and
<tag class="attribute">element</tag> on the same
<tag>p:namespaces</tag> element.</error>
<error code="S0005">It is a <glossterm>static error</glossterm> if any token
specified in the prefix list is not
the prefix of an in-scope namespace.</error></para>

<para>If a <tag>p:option</tag> or <tag>p:parameter</tag> includes one
or more <tag>p:namespaces</tag> elements, then the union of all the
namespaces specified on those elements are used as the bindings for
the option or parameter value. In this case, the in-scope namespaces
on the <tag>p:option</tag> or <tag>p:parameter</tag> are ignored.
<error code="D0013">It is a <glossterm>dynamic error</glossterm> if the
specified namespace bindings are inconsistent; that is, if the same prefix
is bound to two different namespace names.</error></para>

<para>For example, this would allow the preceding example to work:</para>

<programlisting>&lt;p:pipeline type="ex:delete-in-div"
	    xmlns:p="http://www.w3.org/ns/xproc"
	    xmlns:ex="http://example.org/ns/ex"
	    xmlns:h="http://www.w3.org/1999/xhtml"&gt;
&lt;p:input port="source"/&gt;
&lt;p:output port="result"/&gt;
&lt;p:option name="divchild" required="true"/&gt;

&lt;p:delete&gt;
  &lt;p:option name="match" select="concat('h:div/',$divchild)"&gt;
    &lt;p:namespaces xmlns:h="http://www.w3.org/1999/xhtml"
		  xmlns:html="http://www.w3.org/1999/xhtml"/&gt;
  &lt;/p:option&gt;
&lt;/p:delete&gt;

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

<para>The <tag>p:namespaces</tag> element provides namespace bindings
for both of the prefixes necessary to correctly interpret the expression ultimately
passed to the <tag>p:delete</tag> step.</para>

<para>This solution has the weakness that it depends on knowing the bindings that
will be used by the caller. A more flexible solution would use the
<tag class="attribute">option</tag> attribute to copy the bindings from the caller's
option value.</para>

<programlisting>&lt;p:pipeline type="ex:delete-in-div"
	    name="main"
	    xmlns:p="http://www.w3.org/ns/xproc"
	    xmlns:ex="http://example.org/ns/ex"
	    xmlns:h="http://www.w3.org/1999/xhtml"&gt;
&lt;p:input port="source"/&gt;
&lt;p:output port="result"/&gt;
&lt;p:option name="divchild" required="true"/&gt;

&lt;p:delete&gt;
  &lt;p:option name="match" select="concat('h:div/',$divchild)"&gt;
    &lt;p:namespaces option="divchild"/&gt;
    &lt;p:namespaces xmlns:h="http://www.w3.org/1999/xhtml"/&gt;
  &lt;/p:option&gt;
&lt;/p:delete&gt;

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

<para>This example will succeed as long as the caller-specified option does
not bind the “<literal>h</literal>” prefix to something other than the
XHTML namespace.
</para>
</section>
</section>

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

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

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

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

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

<para>The value of the <tag class="attribute">type</tag> can be from
any namespace provided that the expanded-QName of the value has
a non-null namespace URI. <error code="S0025">It is a
<glossterm>static error</glossterm>
if the expanded-QName value of the
<tag class="attribute">type</tag> attribute is in no namespace.</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 implementers 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</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/ns/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>

<para><termdef xml:id="dt-expanded-pipeline-name">The <firstterm>expanded
pipeline name</firstterm> of a pipeline is the expanded name denoted by its
type, if it has one, otherwise the expanded name specified by the
namespace of its containing pipeline-library and its name.</termdef>
</para>
</section>

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

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

<para>An <tag>p:import</tag> loads a pipeline or pipeline library,
making it available in the pipeline or library which contains the
<tag>p:import</tag>.</para>

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

<para>An import statement loads the specified 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
<glossterm>expanded pipeline name</glossterm> (either directly or within a
library).</error>
</para>
</section>

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

<para>A <tag>p:pipe</tag> connects an input to a port on another step.</para>

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

<para>The <tag>p:pipe</tag> element connects to a readable port of
another step. It identifies the readable port to which it connects with
the name of the step in the <tag class="attribute">step</tag>
attribute and the name of the port on that step in the
<tag class="attribute">port</tag> attribute.</para>

<para><error code="S0022">In all cases except the <tag>p:output</tag>
of a <glossterm>compound step</glossterm>, it is a <glossterm>static
error</glossterm> if the port identified by a <tag>p:pipe</tag> is not
in the <glossterm>readable ports</glossterm> of the step that contains
the <tag>p:pipe</tag>.</error></para>

<para>A <tag>p:pipe</tag> that is a <glossterm>binding</glossterm> for
an <tag>p:output</tag> of a <glossterm>compound step</glossterm> may
connect to one of the readable ports of the compound step or to an
output port on one of the compound step's <glossterm>contained
steps</glossterm>. In other words, the output of a compound step can
simply be a copy of one of the available inputs or it can be the
output of one of its children.</para>

</section>

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

<para>A <tag>p:inline</tag> provides a document inline.</para>

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

<para>The content of the <tag>p:inline</tag> element is wrapped in a document
node and passed as input. The base URI of the document is the base URI of the
<tag>p:inline</tag> element.</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 does not consist of exactly one element, optionally
preceded and/or followed by any number of processing instructions,
comments or whitespace characters.</error></para>
</section>

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

<para>A <tag>p:document</tag> reads an XML document from a URI.</para>

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

<para>The document identified by the URI in the <tag class="attribute">href</tag>
attribute is loaded and returned.</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</title>

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

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

</section>

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

<para>A <tag>p:documentation</tag> contains human-readable documentation.</para>

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

<para>There are no constraints on the content of the <tag>p:documentation</tag> element.
Documentation is ignored by pipeline processors.
</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 xml:id="step-errors">
<title>Step Errors</title>

<para>Several of the steps in the standard and option step library can
generate dynamic errors.</para>

<?step-error-list?>

</section>
</section>

<section 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/ns/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/ns/xproc-step</uri> and is
represented by the prefix 'c:' in this appendix.</para>

<para>When a step in this library produces an output document,
the base URI of the output is the base URI of the step's primary
input document unless the step's process explicitly sets an
<tag class="attribute">xml:base</tag> attribute or the step's
description explicitly states how the base URI is constructed.</para>

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

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

<para>When a step uses an XPath from an option value, the XPath
context is as defined in <link linkend="step-xpath-context"/>.</para>
 <para><error code="C0016">It is a <glossterm>dynamic
error</glossterm> if the value supplied for any option specified for any step
in this section is not of the type mandated in the step description, 
with phrases such as "The value of the <option>xxx-name</option> option
&must; be a &qn;" or "the value of the
<option>yyy-flag</option> option
&must; be a boolean".</error></para>

<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.add-attribute">
<title>p:add-attribute</title>

<para>The <code>p:add-attribute</code> step adds a single attribute to a set of
   matching elements.  The input document specified on the <code>source</code> is
   processed for matches specified by the match pattern in the <option>match</option> option.  
   For each of these matches, the attribute whose name is specified by the <option>attribute-name</option> option
   is set to the attribute value specified by the <option>attribute-value</option> option.
</para>

<para>The resulting document is produced on the <code>result</code> output port and consists of
a exact copy of the input with the exception of the matched elements.  Each of the match elements
is copied to the output with the addition or change of the specified attribute name.</para>

<p:declare-step type="p:add-attribute">
  <p:input port="source"/>
  <p:output port="result"/>
  <p:option name="match" required="true"/>
  <p:option name="attribute-name" required="true"/>
  <p:option name="attribute-value" required="true"/>
</p:declare-step>

<para>The value of the <option>match</option> option &must; be
an XSLTMatchPattern.  <error code="C0013">It is a <glossterm>dynamic
error</glossterm> if the match pattern does not match an
element.</error></para>

<para>The value of the <option>attribute-name</option> option
&must; be a &qn;. The corresponding expanded name is used to
construct the added attribute.</para>
 
 <para>The value of the <option>attribute-value</option> option
&must; be a legal attribute value according to &xml;.</para>

<note><para>If multiple attributes need to be set, the <link linkend="c.set-attributes">p:set-attributes</link> step should be
used.</para></note>

</section>

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

<section xml:id="c.add-xml-base">
   
<title>p:add-xml-base</title>

<para>The <code>p:add-xml-base</code> step exposes the base URI via
explicit <code>xml:base</code> attributes. The input document from the
<port>source</port> port is replicated to the <port>result</port> port
with <code>xml:base</code> attributes added to each element as specified
by the options on this step.</para>

<p:declare-step type="p:add-xml-base">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="all" value="false"/>
   <p:option name="relative" value="true"/>
</p:declare-step>
 
 <para>The value of the <option>all</option> option
&must; be a boolean.</para>
 
 <para>The value of the <option>relative</option> option
&must; be a boolean.</para>

<para>The <tag>p:add-xml-base</tag> step adds <tag class="attribute">xml:base</tag>
attributes according to the following rules:</para>

<itemizedlist>
<listitem><para>If the document element does not have an <tag class="attribute">xml:base</tag> attribute specified, an
<code>xml:base</code> attribute is added.</para></listitem>

<listitem><para>If an element's base URI is different from its
parent's base URI, an <code>xml:base</code> attribute is added to the
element.</para></listitem>

<listitem><para>If the <option>all</option> option has the value
“<literal>true</literal>”, an <code>xml:base</code> attribute is added
to every element in the document.</para></listitem>
</itemizedlist>

<para>Whenever an <tag class="attribute">xml:base</tag> attribute is
added, its value is set to the base URI of the element to which it is
added.</para>

<para>If the value of the <option>relative</option> option is
“<literal>true</literal>”, any <code>xml:base</code> attribute value
<rfc2119>should</rfc2119> be expressed relative to the current base
URI. Otherwise, the value of the <code>xml:base</code> attribute
<rfc2119>should</rfc2119> be an absolute URI.</para>

</section>

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

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

<para>The <code>p:compare</code> step compares two documents for
equality.</para>

<p:declare-step type="p:compare">
   <p:input port="source" primary="true"/>
   <p:input port="alternate"/>
   <p:output port="result" primary="false"/>
   <p:option name="fail-if-not-equal" value="false"/>
</p:declare-step>
 
 <para>The value of the <option>fail-if-not-equal</option> option &must; be a boolean.</para>
 
 <para>This step takes single documents on each of two ports and compares them
using the <function>fn:deep-equal</function> (as defined in
<biblioref linkend="xpath-functions"/>).  <error code="C0019">It is a
<glossterm>dynamic error</glossterm> if the documents are not equal, and the value
of the <option>fail-if-not-equal</option> option is
“<literal>true</literal>”.</error>  If the documents are equal, or if the value
of the <option>fail-if-not-equal</option> option is
“<literal>false</literal>”, a <tag>c:result</tag>
document is produced with contents “<literal>true</literal>” if the documents
are equal, otherwise “<literal>false</literal>”.</para>

</section>

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

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

<para>The <code>p:count</code> 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 contents is the string representation of the number of documents in the sequence.</para>

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

</section>

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

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

<para>The <code>p:delete</code> step deletes items specified by a match
pattern from the
<code>source</code> input document and produces the resulting document
with the deletions on the <port>result</port> port.</para>

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

<para>The value of the <option>match</option> option &must; be
an XSLTMatchPattern.  It may match multiple items to be deleted, but note that
nested matches are not considered as their ancestors will already have been
deleted.</para>

</section>

<!-- ************************************************************************-->
<section xml:id="c.directory-list">
<title>p:directory-list</title>

<para>The <code>p:directory-list</code> step produces a list of the
contents of a specified
directory.</para>

<p:declare-step type="p:directory-list">
  <p:output port="result"/>
  <p:option name="path" value="."/>
  <p:option name="filter"/>
</p:declare-step>
 
 <para>The value of the <option>path</option> option &must; be an
anyURI.  It
is interpreted as an IRI reference.  If relative, it is resolved to absolute
form.  The base URI used for
resolution is the base URI of
<tag>p:option</tag> element, if present, otherwise, that is in case
the default of '.' is used, the base URI of the <tag>p:directory-list</tag>
element.  <error code="C0017">It is a <glossterm>dynamic
error</glossterm> if the absolute path does not identify a directory.</error>  <error code="C0012">It is a <glossterm>dynamic error</glossterm> if the
contents of the directory path
are not available to the step due to access restrictions in the environment in which the pipeline is run.</error></para>
 
<para><impl>Conformant processors &must; support directory paths whose
scheme is <code>file</code>. It is
<glossterm>implementation-defined</glossterm> what other schemes are
supported by <tag>p:directory-list</tag>, and what the interpretation
of 'directory', 'file' and 'contents' is for those schemes.</impl>
<error code="C0018">It is a <glossterm>dynamic error</glossterm> if the
directory path's scheme is not supported.</error></para>
 
 <para>If present, the value of the <option>filter</option> option &must; be a regular expression as specified
in <biblioref linkend="xpath-functions"/>, section 7.61 “<literal>Regular Expression Syntax</literal>”.  If the 
pattern matches a directory entry's name, the entry is included in the output.</para>

<para xml:id="cv.directory">The result document produced for
the specified directory path has a <tag>c:directory</tag> document
element whose base URI is the directory path and whose <code>name</code> attribute is the last segment
of the directory path (that is, the directory's (local) name).  Its contents are
determined as follows, based on the entries in the directory identified by
the directory path:</para> 

<itemizedlist>
   <listitem>
<para>For each entry in the directory, if either no
<option>filter</option> was specified, or the (local) name of the entry matches the filter pattern, a <tag>c:file</tag>, a <tag>c:directory</tag>, or a <tag>c:other</tag>
element is produced, as follows:
</para>
   </listitem>
   <listitem>
<para xml:id="cv.file">A <tag>c:file</tag> is produced for each file not determined to be special.</para>
   </listitem>
   <listitem>
<para>A <tag>c:directory</tag> is produced for each subdirectory not determined to be special.</para>
   </listitem>
   <listitem>

<para xml:id="cv.other"><impl>Any file or directory determined to be
special by the <tag>p:directory-list</tag> step may be output using a
<tag>c:other</tag> element but the criteria for marking a file as
special is <glossterm>implementation-defined</glossterm>.</impl>
</para>
   </listitem>
</itemizedlist>

<para>When a directory entry is a subdirectory, that directory's entries are not
output as part of that entry's <tag>c:directory</tag>.  A user must apply this step
again to the subdirectory to list subdirectory contents.</para>

<para>Each of the elements <tag>c:file</tag>, <tag>c:directory</tag>,
and <tag>c:other</tag> has a <code>name</code> attribute when they
appear within the top-level <tag>c:directory</tag> element, whose
value is a relative IRI reference, giving the (local) file or
directory name.</para>

<para><impl>Any attributes other than <tag class="attribute">name</tag> on
<tag>c:file</tag>, <tag>c:directory</tag>, or <tag>c:other</tag>
is <glossterm>implementation-defined</glossterm>.</impl></para>

</section>

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

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

<para>The <code>c:error</code> step generates a <glossterm role="unwrapped">dynamic error</glossterm> 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="true"/>
   <p:option name="description" required="true"/>
</p:declare-step>
 
 <para>The value of the <option>code</option> option &must; be a &qn;</para>

<para>This step has no inputs and no outputs. It needs no input, and
since it generates an error upon invocation,
there can be no normal output. Instead, an instance of
the <tag>c:errors</tag> element will be produced on the error port, as is
always the case for
<glossterm baseform="dynamic error" role="unwrapped">dynamic errors</glossterm>.   The presence or absence
of a <tag>p:try</tag> overhead will determine whether or not the error surfaces.</para>

<para>For example, given the following invocation:</para>
<programlisting>
<![CDATA[<p:error name="bad-document" xmlns:my="http://www.example.org/error">
   <p:option name="code" value="my:unk12">
   <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 would be:</para>
<programlisting>
<![CDATA[<c:errors xmlns:c="http://www.w3.org/ns/xproc-step"
          xmlns:p="http://www.w3.org/ns/xproc"
          xmlns:my="http://www.example.org/error">
 <c:error name="bad-document" type="p:error"
          code="my:unk12">The document element is unknown</c:error>
</c:errors>]]>
</programlisting>

<para>The <tag class="attribute">href</tag>,
<tag class="attribute">line</tag> and <tag class="attribute">column</tag>,
or <tag class="attribute">offset</tag>, might also be present on the
<tag>c:error</tag> to identify the location of the <tag>p:error</tag>
element in the pipeline.</para>

</section>

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

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

<para>The <code>p:escape-markup</code> 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 as they were
serialized.</para>

<p:declare-step type="p:escape-markup">
  <p:input port="source"/>
  <p:output port="result"/>
  <p:option name="cdata-section-elements"/>
  <p:option name="doctype-public"/>
  <p:option name="doctype-system"/>
  <p:option name="encoding"/>
  <p:option name="escape-uri-attributes"/>
  <p:option name="include-content-type"/>
  <p:option name="indent" value="false"/>
  <p:option name="media-type"/>
  <p:option name="method" value="xml"/>
  <p:option name="omit-xml-declaration"/>
  <p:option name="standalone"/>
  <p:option name="undeclare-prefixes"/>
  <p:option name="version" value="1.0"/>
</p:declare-step>

<para>This step supports the standard serialization options as specified in <link linkend="serialization-options"/>.  These 
options control how the output markup is produced before it is escaped.</para>

<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>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.http-request">
<title>p:http-request</title>

<para>The <code>p:http-request</code> step provides for interaction
with resources identified by IRIs over HTTP or closely related protocols.
The input
document provided on the <port>source</port> port specifies a request
by a single <tag>c:request</tag> element. This element specifies
the method, resource, and other request properties as well as possibly
including an entity body (content) for the request.</para>

<p:declare-step type="p:http-request">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="byte-order-mark"/>
   <p:option name="cdata-section-elements"/>
   <p:option name="doctype-public"/>
   <p:option name="doctype-system"/>
   <p:option name="encoding"/>
   <p:option name="escape-uri-attributes"/>
   <p:option name="include-content-type"/>
   <p:option name="indent" value="false"/>
   <p:option name="media-type"/>
   <p:option name="method" value="xml"/>
   <p:option name="normalization-form"/>
   <p:option name="omit-xml-declaration"/>
   <p:option name="standalone"/>
   <p:option name="undeclare-prefixes"/>
</p:declare-step>

<para>The standard serialization options are provided to control the
serialization of any XML content which is sent as part of the request.
The effect of these options are as specified in <link linkend="serialization-options"/>. See <link linkend="c.request_body"/> for a discussion of when serialization
occurs in constructing a request.</para>

<para><error code="C0040">It is a <glossterm>dynamic error</glossterm>
if the document element of the document that arrives on the
<port>source</port> port is not <tag>c:request</tag>.</error></para>
 
<section xml:id="cv.request">
<title>Specifying a request</title>

<para>A HTTP request is represented by a <tag>c:request</tag> element.</para>

<e:rng-pattern name="VocabHttpRequest"/>
  
<para><error code="C0021">It is a <glossterm>dynamic error</glossterm>
if the scheme of the <code>href</code> attribute is not
supported.</error>
<impl>The set of schemes supported on HTTP request
URIs is <glossterm>implementation defined</glossterm>.
Implementations <rfc2119>must</rfc2119> support the "<literal>http</literal>"
scheme.</impl></para>

<para><error code="C0005">It is a <glossterm>dynamic error</glossterm> if the
request contains a <tag>c:body</tag> or <tag>c:multipart</tag> but the method does not allow for an entity body being sent with the request.</error></para>

<para><error code="C0004">It is a <glossterm>dynamic error</glossterm> if the
<code>status-only</code> attribute has the value “<literal>true</literal>” and
the <code>detailed</code> attribute does not have the value “<literal>true</literal>”.</error></para>

<para>The <code>method</code> attribute specifies the method to be used against the IRI specified by
the <code>href</code> attribute, e.g. <code>GET</code> or <code>POST</code>.  If the <code>href</code> attribute is not
absolute, it will be resolved
against the base URI of its owner element.</para>

<para>If the <code>username</code> attribute is specified, the
<code>username</code>, <code>password</code>, <code>auth-method</code>, and
<code>send-authorization</code> attributes are used to handle authentication as
per <biblioref linkend="rfc2617"/>.  If the initial response to the request is an authentication challenge, the <code>username</code> and <code>password</code> attribute values are used to generate an <code>Authorization</code> header and the request is sent again.  If that authorization fails, the request is not retried.</para>

<para>For the purposes of avoiding an authentication challenge, if the <code>send-authorization</code> attribute has a value of “<literal>true</literal>” and the authentication method specified by the <code>auth-method</code> supports generation of an <code>Authorization</code> header without a challenge, then an <code>Authorization</code> header is generated and sent on the first request.  If the response contains an authentication challenge, the request is retried with an appropriate <code>Authorization</code> header.</para>

<para>Appropriate values for the <code>auth-method</code> attribute
are "Basic" or "Digest" but other values are allowed. <impl>The
interpretation of <code>auth-method</code> values on
<tag>c:request</tag> other than “Basic” or “Digest” is
<glossterm>implementation-defined</glossterm>.</impl>
<error code="C0003">It
is a <glossterm>dynamic error</glossterm> if the requested
<code>auth-method</code> isn't supported or the authentication
challenge contains an authentication method that isn't
supported.</error> All implementations are required to support "Basic"
and "Digest" authentication per <biblioref linkend="rfc2617"/>.</para>
  
  <para>The <code>c:header</code> element specifies a
header name and value, either for inclusion in a request, or as received in a response.</para>
  
<e:rng-pattern name="VocabHeader" xml:id="cv.header"/>

<para>The request is formulated from the attribute values on the
<tag>c:request</tag> element and its
<tag>c:header</tag> and <tag>c:multipart</tag> or <tag>c:body</tag> children,
if present, and transmitted to the host (and port, if present) specified by the
<code>href</code> attribute.  The details of how the request entity body, if any, is
constructed are given in the next section.</para>

<para>When the request is formulated, the step and/or protocol implementation may add headers as necessary to either complete
the request or as appropriate for the content specified (e.g. transfer
encodings).  A user of this step is guaranteed that their requested headers and
content will be sent with the exception of any conflicts with protocol-related
headers.  <error code="C0020">It is a <glossterm>dynamic error</glossterm> if
the value of a header specified via <tag>c:header</tag> (e.g.
<literal>Content-Type</literal>) conflicts with the value for that header that the step and/or protocol implementation must set.</error></para>
</section>
 
 <section xml:id="c.request_body">
  <title>Request Entity body conversion</title>

  <para>The <code>c:multipart</code> element specifies a multi-part body, per <biblioref linkend="rfc1521"/>,
either for inclusion in a request or as received in a response.</para>
    
<e:rng-pattern name="VocabMultipart" xml:id="cv.multipart"/>

<para>In the context of a request, the media type of the <tag>c:multipart</tag>
&must; be a multipart media type (i.e. have a main type of 'multipart'). If the <code>content-type</code> attribute is not specified, a value of "multipart/mixed" will be assumed.</para>

<para>The <tag>c:body</tag> element holds the body or body part of the message.  Each of the attributes holds controls some aspect of the encoding of the body or body part when the request is formulated.  These are specified as follows:</para>

<e:rng-pattern name="VocabBody" xml:id="cv.body"/>

<para>The <code>content-type</code> attribute specifies the media type of the
body or body part, that is, the value of its <code>Content-Type</code> header. If the media type is not an XML type nor is it text, the content must already be base64-encoded.</para>

<para>The <code>encoding</code> attribute specifies the value of the
<code>Content-Transfer-Encoding</code> header for the body or body part.  If the value of <code>encoding</code> is 'base64' but the content type does not require such an encoding, the <tag>c:body</tag> element is assumed to contain base64-encoded content of that media type.</para>
  
  <para>The <code>id</code> attribute specifies the value of the
<code>Content-ID</code> header for the body or body part.</para>
  
  <para>The <code>description</code> attribute specifies the value of the <code>Content-Description</code> header for the body or body part.</para>

  <para>If an entity body is to be sent as part of a request (e.g. a
<code>POST</code>), either a <tag>c:body</tag> element, specifying the request
entity body, or a <tag>c:multipart</tag>
element, specifying multiple entity body parts, may be used. When <tag>c:multipart</tag> is used it may contain
multiple <tag>c:body</tag> children.  A <tag>c:body</tag> specifies the
construction of a body or body part as follows:</para>
  
  <para>If the <code>content-type</code> attribute does not specify an XML media
type, or the <code>encoding</code> attribute is 'base64', then <error code="C0028">it is a <glossterm>dynamic error</glossterm> if the content of the <tag>c:body</tag> element does not consist entirely of characters</error>, and the entity body or body part will consist of exactly those characters.</para>

<para>Otherwise (the <code>content-type</code> attribute
<emphasis>does</emphasis> specify an XML media type and the
<code>encoding</code> attribute is <emphasis>not</emphasis> 'base64'),
<error code="C0022">it is a <glossterm>dynamic error</glossterm> if
the content of the <tag>c:body</tag> element does not consist of
exactly one element, optionally preceded and/or followed by any number
of processing instructions, comments or whitespace characters</error>,
and the entity body or body part will consist of the serialization of
a document node containing that content. The serialization of that
document is controlled by the serialization options on the
<code>p:http-request</code> step itself.</para>

<para>For example, the following input to a <code>p:http-request</code> step will POST a small XML document:</para>

<programlisting>
<![CDATA[<c:request method="POST" href="http://example.com/someservice">
<c:body xmlns:c="http://www.w3.org/ns/xproc-step" content-type="application/xml">
<doc>
<title>My document</title>
</doc>
</c:body>
</c:request>]]>
</programlisting> 
  <para>The corresponding request should look something like this:</para>
  
  <programlisting><![CDATA[POST http://example.com/someservice HTTP/1.1
Host: example.com
Content-Type: application/xml; charset="utf-8"


<doc>
<title>My document</title>
</doc>
]]></programlisting>
 </section>
 
 <section xml:id="c.request_response">
  <title>Managing the response</title>
  <para>The handling of the response to the request and the generation of the
step's result document is controlled by the <code>status-only</code>,
<code>override-content-type</code> and <code>detailed</code> attributes on the
<tag>c:request</tag> input.</para>
  
<para>The <code>override-content-type</code> attribute controls interpretation
of the response's <code>Content-Type</code> header. If
this attribute is present, the response will be treated as if it returned
the <code>Content-Type</code> given by its value.  This original <code>Content-Type</code> header will
however be reflected unchanged as a <tag>c:header</tag> in the result document.  <error code="C0030">It is a <glossterm>dynamic error</glossterm> if
the <code>override-content-type</code> value cannot be used (e.g. <code>text/plain</code> to override <code>image/png</code>).</error></para>

<para>If the <code>status-only</code> attribute has the value
“<literal>true</literal>”, the result document will contain only header
information.  The entity of the response will not
be processed to produce a <tag>c:body</tag> or <tag>c:multipart</tag> element.</para>

<para>The <tag>c:response</tag> element represents an HTTP response.  The response's status code is encoded in the
<code>status</code> attribute and the headers and entity body are processing
into <tag>c:header</tag> and <tag>c:multipart</tag> or <tag>c:body</tag> content.</para>

<e:rng-pattern name="VocabHttpResponse" xml:id="c.response"/>

<para>The value of the <code>detailed</code> attribute determines the content
of the result document.  If it is “<literal>true</literal>”, the response to the request is handled as follows:</para>

<orderedlist>
<listitem><para>A single <tag>c:response</tag> element is produced with the <code>status</code> attribute containing the status of the response received.</para></listitem>
<listitem><para>Each response header whose name does not start with "Content-" is translated into a <tag>c:header</tag> element.</para></listitem>
<listitem><para>Unless the <code>status-only</code> attribute has a value “<literal>true</literal>”, the entity body of the response is converted into
a <tag>c:body</tag> or <tag>c:multipart</tag> element via the rules given in
the next section.</para></listitem>
</orderedlist>

<para>Otherwise (the <code>detailed</code> attribute is not specified or its value is
“<literal>false</literal>”), the response to the request is handled as follows:</para>

<orderedlist>
<listitem><para>If the media type (as determined by the
<code>override-content-type</code> attribute or the <code>Content-Type</code>
response header) is an XML media type, the entity is decoded if necessary, then parsed as an XML document
and produced on the <code>result</code> output port as the entire output of the step.</para></listitem>
<listitem><para>Otherwise, the entity body of the response is converted into
a <tag>c:body</tag> or <tag>c:multipart</tag> element via the rules given in
the next section.</para></listitem>
</orderedlist>

<para>In either case the base URI of the output document is the resolved value
of the <code>href</code> attribute from the input <tag>c:request</tag>.</para>
 </section>

<section xml:id="c.response_body">
   <title>Converting Response Entity Bodies</title>   
<para>The entity of a response may be multipart per <biblioref linkend="rfc1521"/>.  In those situations, the result document will be a <tag>c:multipart</tag> element that contains multiple <tag>c:body</tag> elements inside.</para>

<para>If the media type of the response is a text type with a
<code>charset</code> parameter that is a Unicode character encoding, the content of the constructed <tag>c:body</tag> element is the translation of the text into a Unicode character sequence</para>

<para>If the media type of the response is an XML media type, the content of
the constructed <tag>c:body</tag> element is the result of decoding the body if
necessary, then parsing it with an XML parser.  If the content is not well-formed, the step fails.</para>

<para>For all other media types, the response is encoded as base64 (unless it
is encoded already)
and then produced as text children of the <tag>c:body</tag> element.</para>

<para>In the case of a multipart response, the same rules apply when constructing a <tag>c:body</tag> element for each body part encountered.</para>

<note>
<para>Given the above description, any content identified as
<code>text/html</code> will be base64-encoded in the <tag>c:body</tag>
element, as HTML isn't always well-formed XML. A user can attempt to
convert such content into XML using the <tag>p:unescape-markup</tag>
step.</para>
</note>
</section>

<section xml:id="example-http-request">
<title>HTTP Request Example</title>

<para>A simple form might be posted as follows:</para>
<programlisting>&lt;c:http-request method="POST" href="http://www.example.com/form-action" xmlns:c="http://www.w3.org/ns/xproc-step"&gt;
&lt;c:body content-type="application/x-www-form-urlencoded"&gt;
name=W3C&amp;amp;spec=XProc
&lt;/c:body&gt;
&lt;/c:http-request&gt;
</programlisting>
<para>and if the response was an XHTML document, the result document would be:</para>
<programlisting>&lt;c:http-response status="200" xmlns:c="http://www.w3.org/ns/xproc-step"&gt;
&lt;c:header name="Date" value=" Wed, 09 May 2007 23:12:24 GMT"/&gt;
&lt;c:header name="Server" value="Apache/1.3.37 (Unix) PHP/4.4.5"/&gt;
&lt;c:header name="Vary" value="negotiate,accept"/&gt;
&lt;c:header name="TCN" value="choice"/&gt;
&lt;c:header name="P3P" value="policyref=&amp;quot;http://www.w3.org/2001/05/P3P/p3p.xml&amp;quot;"/&gt;
&lt;c:header name="Cache-Control" value="max-age=600"/&gt;
&lt;c:header name="Expires" value="Wed, 09 May 2007 23:22:24 GMT"/&gt;
&lt;c:header name="Last-Modified" value="Tue, 08 May 2007 16:10:49 GMT"/&gt;
&lt;c:header name="ETag" value="&amp;quot;4640a109;42380ddc&amp;quot;"/&gt;
&lt;c:header name="Accept-Ranges" value="bytes"/&gt;
&lt;c:header name="Keep-Alive" value="timeout=2, max=100"/&gt;
&lt;c:header name="Connection" value="Keep-Alive"/&gt;
&lt;c:body content-type="application/xhtml+xml"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;&lt;title&gt;OK&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;&lt;p&gt;OK!&lt;/p&gt;&lt;/body&gt;
&lt;/html&gt;
&lt;/c:body&gt;
&lt;/c:http-response&gt;
</programlisting>
</section>

</section>

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

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

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

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

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

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

<para>The <code>p:insert</code> step inserts the <code>insertion</code> port's
document as a child of matching elements in the <code>source</code>
port's document.</para>

<p:declare-step type="p:insert">
   <p:input port="source" primary="true"/>
   <p:input port="insertion"/>
   <p:output port="result"/>
   <p:option name="match" value="/*"/>
   <p:option name="position" required="true"/>
</p:declare-step>

<para>The value of the <option>match</option> option &must; be an XSLTMatchPattern.  <error code="C0023">It is a <glossterm>dynamic error</glossterm> if that
pattern matches anything other than element nodes.</error>  Multiple matches
are allowed, in which case multiple copies of the <port>insertion</port>
document will occur.</para>

<para>The value of the <option>position</option> option &must; be an NMTOKEN in
the following list:
</para>

<itemizedlist>
<listitem>
<para>”<literal>first-child</literal>” - the insertion is made as the first child of the match;</para>
</listitem>
<listitem>
<para>”<literal>last-child</literal>” - the insertion is made as the last child of the match;</para>
</listitem>
<listitem>
<para>”<literal>before</literal>” - the insertion is made as the immediate preceding sibling of the match;</para>
</listitem>
<listitem>
<para>”<literal>after</literal>” - the insertion is made as the immediate following sibling of the match.</para>
</listitem>
</itemizedlist>
 
 <para><error code="C0025">It is a <glossterm>dynamic error</glossterm> if the
match pattern matches the document element and the value of the
<option>position</option> option is ”<literal>before</literal>” or ”<literal>after</literal>”.</error></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>p:label-elements</title>

<para>The <code>p:label-elements</code> step generates a label for each selected
element and stores that label in the specified attribute.</para>
 
 <p:declare-step type="p:label-elements">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="attribute" value="xml:id"/>
   <p:option name="prefix" value="_"/>
   <p:option name="suffix" value=""/>
   <p:option name="select" value="*"/>
   <p:option name="scheme" value="count-elements"/>
</p:declare-step>
 
<para>The value of the <option>attribute</option> option &must; be a &qn;.</para>
 
<para>The value of the <option>select</option> option &must; be an
XPathExpression. <error code="C0024">It is a <glossterm>dynamic
error</glossterm> if that expression selects anything other than
element nodes.</error></para>

<para>The value of the <option>scheme</option> option must be a &qn;.
If it does not have a prefix, it must have the value
<literal>count-elements</literal>.
</para>
 
<para>This step operates by generating labels for each element
selected. The algorithm by which label values are generated depends on
the <option>scheme</option> value specified. If a selected element
already has an attribute whose name is the value of the
<option>attribute</option> option, that attribute is not changed,
otherwise an attribute with that name is added, with a value
consisting of the concatenation of the value of the
<option>prefix</option> option, the computed label, and the value of
the <option>suffix</option> option.
</para>

<para>If the value of the <option>scheme</option> option is
<literal>count-elements</literal>, then the label for each selected
element is its position in the sequence of selected elements.
In other words, the first element (in document order) selected gets
the label “1”, the second gets the label “2”, the third, “3”, etc.
The labeling process counts every element, even those which already have
an attribute whose name is the value of the <option>attribute</option> option.</para>

<para>All implementations <rfc2119>must</rfc2119> support the
<option>scheme</option> value <literal>count-elements</literal>. <impl>Support
for scheme values other than <literal>count-elements</literal> on the
<tag>p:label-elements</tag> step is
<glossterm>implementation-defined</glossterm>.</impl></para>

<para>The <tag>p:label-elements</tag> step <rfc2119>must not</rfc2119>
generate two labels with the same value in the course of processing
any single document. However, no attempt must be made to assure that
the generated attribute values are unique with respect to attribute
values already present in the document.</para>

<para><error code="C0032">It is a <glossterm>dynamic error</glossterm> if
the value specified for the <option>scheme</option> option is not one of
the values supported by the implementation.</error>
</para>
</section>

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

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

<para>The <code>p:load</code> step has no inputs but produces as its result an XML resource
specified by an IRI.</para>

<p:declare-step type="p:load">
  <p:output port="result"/>
  <p:option name="href" required="true"/>
  <p:option name="validate"/>
</p:declare-step>
 
 <para>The value of the <option>href</option> option &must; be an anyURI.  It
is interpreted as an IRI reference.</para>
 
 <para>The value of the <option>validate</option> option &must; be a boolean.</para>

<para>Load attempts to read an XML document from the specified IRI reference, which may
be relative, in which case it will be resolved relative to the base URI of its
<code>p:option</code> element. <error code="C0026">It is a
<glossterm>dynamic error</glossterm> if the
document does not exist or is not well-formed.</error>  <error code="C0011">It
is a <glossterm>dynamic error</glossterm> if the step is not allowed to retrieve from the specified location.</error> Otherwise,
the retrieved document is produced on the <port>result</port> port.  The base URI of
the result is the
(absolute) IRI used to retrieve it.</para>

<para>If the value of the <option>validate</option> option is
“<literal>true</literal>”, namespace-aware DTD validation is performed on the
retrieved document.  <error code="C0027">It is a <glossterm>dynamic error</glossterm> if the document is not valid or the step
doesn't support DTD validation.</error></para>

<para><impl>Implementations &must; support the <code>file</code> and
<code>http</code> URI schemes on <tag>p:load</tag>. It is
<glossterm>implementation-defined</glossterm> what other URI schemes
are supported.</impl> <error code="C0007">It is a <glossterm>dynamic
error</glossterm> if the scheme of the IRI reference is not
supported.</error></para>

</section>

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

<section xml:id="c.make-absolute-uris">
<title>p:make-absolute-uris</title>

<para>The <code>p:make-absolute-uris</code> step makes an element or attribute's value in the source document an
absolute IRI value in the result document.</para>

<p:declare-step type="p:make-absolute-uris">
  <p:input port="source"/>
  <p:output port="result"/>
  <p:option name="match" required="true"/>
  <p:option name="base-uri"/>
</p:declare-step>

<para>The value of the <option>match</option> option &must; be an XSLTMatchPattern.

<error code="C0008">It is a <glossterm>dynamic error</glossterm> if
the pattern matches anything other than element or attribute nodes.</error></para>
 
 <para>The value of the <option>base-uri</option> option &must; be an anyURI.  It
is interpreted as an IRI reference.</para>
 
 <para>For every element or attribute in the input document which
matches the specified pattern, its XPath string-value is resolved
against the specified base URI and the resulting absolute IRI is used
as the matched node's entire contents in the output.</para>

<para>The base URI used for resolution defaults to the matched
attribute's element or the matched element's base URI unless the
<option>base-uri</option> option is specified. When the
<option>base-uri</option> option is specified, the option value is
used as the base URI regardless of any contextual base URI value in
the document. This option value is resolved against the base URI of
the <tag>p:option</tag> element used to set the option.</para>

<para><impl>If the IRI reference specified by the <option>base-uri</option> option
on <tag>p:make-absolute-uris</tag> is
not valid, or if it is absent and the input document has no base URI,
the results are <glossterm>implementation-dependent</glossterm>.</impl>
</para>

</section>

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

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

<para>The <code>p:namespace-rename</code> step renames any namespace declaration or
use of a namespace in a document to a new IRI value.</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:option name="elements-only"/>
</p:declare-step>
 
 <para>The value of the <option>from</option> option &must; be an anyURI.  It
<rfc2119>should</rfc2119> be either empty or absolute, but will not be resolved
in any case.</para>
 
 <para>The value of the <option>to</option> option &must; be an anyURI.  It
<rfc2119>should</rfc2119> be empty or absolute, but will not be resolved in any case.</para>
 
 <para><error code="C0014">It is a <glossterm>dynamic error</glossterm> 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 the value of either the
<option>from</option> option or the <option>to</option> option.</error></para>

<para>If the value of the <option>from</option> option is the same as the value
of the <option>to</option> option, the input is reproduced unchanged on the
output.  Otherwise, namespace bindings, namespace attributes and element and attribute names are
changed as follows:</para>
 <itemizedlist>
  <listitem>
   <para>Namespace bindings:  If the <option>from</option> option is present
and its value is not the empty string,
then every binding of a prefix (or the default namespace) in the input
document whose value is the same as the value of the <option>from</option>
option is</para>
   <itemizedlist>
    <listitem>
     <para>replaced in the output with a binding to the value of the <option>to</option>
option, provided it is present and not the empty string;</para>
    </listitem>
    <listitem>
     <para>otherwise (the <option>to</option> option is
not specified or has an empty string as its value) absent from the output.</para>
    </listitem>
   </itemizedlist>   
   <para>If the <option>from</option> option is absent, or its value is the empty string,
then no bindings are changed or removed.</para>
  </listitem>
  <listitem>
   <para>Elements and attributes: If the <option>from</option> option is present
and its value is not the empty string, for every element (and attribute, 
unless the value of the <option>elements-only</option> option is
“<literal>true</literal>”) in the input whose namespace name is the same as the value of the
<option>from</option> option, in the output its namespace name</para>
   <itemizedlist>
    <listitem>
     <para>replaced with the value of the <option>to</option>
option, provided it is present and not the empty string;</para>
    </listitem>
    <listitem>
     <para>otherwise (the <option>to</option> option is
not specified or has an empty string as its value) changed to have no value.</para>
    </listitem>
   </itemizedlist>
   <para>If the <option>from</option> option is absent, or its value is the empty string,
then for every element (and attribute, 
unless the value of the <option>elements-only</option> option is
“<literal>true</literal>”) whose namespace name has no value, in the output its namespace
name is set to the value of the <option>to</option> option.</para>
  </listitem>
  <listitem>
   <para>Namespace attributes:  If the <option>from</option> option is present
and its value is not the empty string, for every namespace attribute in the
input whose value is the same as the value of the <option>from</option> option, in the output</para>
   <itemizedlist>
    <listitem>
     <para>the namespace attribute's value is replaced with the value of the <option>to</option>
option, provided it is present and not the empty string;</para>
    </listitem>
    <listitem>
     <para>otherwise (the <option>to</option> option is
not specified or has an empty string as its value) the namespace attribute is absent.</para>
    </listitem>
   </itemizedlist>
  </listitem>
 </itemizedlist>
 
 <note><para>The <option>elements-only</option> option is primarily intended to make
it possible to avoid renaming attributes when the <option>from</option> option
specifies no namespace, since many attributes are in no namespace.</para>

<para>Care should be taken when specifying no namespace with the
<option>to</option> option.  Prefixed names in content, for example QNames and
XPath expressions, may end up with no appropriate namespace binding.</para></note>

</section>

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

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

<para>The <code>p:pack</code> step merges two document sequences in a pair-wise
fashion.</para>

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

<para>The value of the <option>wrapper</option> option &must; be a &qn;.</para>

<para>The step takes each pair of documents, in order, one from the
<port>source</port> port and one from the <port>alternate</port> port,
wraps them with a new element node whose QName is the value specified
in the <option>wrapper</option> option, and writes that element to the
<port>result</port> port as a document.</para>

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

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

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

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

<para>The <code>p:parameters</code> 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="false" sequence="true"/>
   <p:output port="result" sequence="true" primary="false"/>
</p:declare-step>

<para>Each parameter passed to the step is converted into a
<tag>c:parameter</tag> element and written to the <port>result</port>
port as a document. The step resolves duplicate parameters in the
normal way (see <link linkend="parameter-inputs"/>). <impl>The order in
which parameters are written to the parameter port of <tag>p:parameters</tag>
is <glossterm>implementation-dependent</glossterm>.</impl></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 &must; be used. Each
<tag class="attribute">name</tag> &must; be an NCName.</para>

<para>The base URI of the output document is the URI of the pipeline document
that contains the step.</para>
 
 <note>
<para>Since the <port>parameters</port> port is <emphasis>not</emphasis>
primary, any explicit <tag>p:parameter</tag> settings &must; include a <tag class="attribute">port</tag> attribute with value <literal>parameters</literal>, per the last paragraph of <link linkend="p.parameter"/>.</para>
</note>

</section>

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

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

<para>The <code>p:rename</code> step renames elements, attributes, or
processing-instruction targets in a document.</para>

<p:declare-step type="p:rename">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="match" required="true"/>
   <p:option name="new-name" required="true"/>
</p:declare-step>
 
 <para>The value of the <option>match</option> option must be an
XSLTMatchPattern.  <error code="C0031">It is a <glossterm>dynamic error</glossterm> if
the pattern matches anything other than element, attribute or processing instruction nodes.</error></para>
  
 <para>The value of the <option>new-name</option> option must be a &qn;.</para>

<para>Each element, attribute, or processing-instruction in the input matched by
the match pattern specified in the <option>match</option> option is renamed in the output
to the name specified by the <option>new-name</option> option.</para>

<!--<para><error code="C0015">It is a <glossterm>dynamic error</glossterm> if the
renaming would introduce a syntactic error into the document (e.g., if it would
create two attributes with the same name on the same element).</error></para>-->

</section>

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

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

<para>The <code>p:replace</code> step replaces matching elements in its primary input with the
document element of the <code>replacement</code> port's document.</para>

<p:declare-step type="p:replace">
   <p:input port="source" primary="true"/>
   <p:input port="replacement"/>
   <p:output port="result"/>
   <p:option name="match" required="true"/>
</p:declare-step>
 
 <para>The value of the <option>match</option> option &must; be an XSLTMatchPattern.  <error code="C0023">It is a <glossterm>dynamic error</glossterm> if that
pattern matches anything other than element nodes.</error>  Multiple matches
are allowed, in which case multiple copies of the <port>replacement</port>
document will occur.</para> 

<para>Every element in the primary input matching the specified pattern is
replaced in the output is replaced by the document element of the <port>replacement</port>
document. Only non-nested matches are replaced. That is, once an element is
replaced, its descendants cannot be matched.</para>

</section>

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

<section xml:id="c.set-attributes">
<title>p:set-attributes</title>

<para>The <tag>p:set-attributes</tag> step sets attributes on
matching elements.</para>

<p:declare-step type="p:set-attributes">
   <p:input port="source" primary="true"/>
   <p:input port="attributes"/>
   <p:output port="result"/>
   <p:option name="match" required="true"/>
</p:declare-step>
 
 <para>The value of the <option>match</option> option &must; be an XSLTMatchPattern.  <error code="C0023">It is a <glossterm>dynamic error</glossterm> if that
pattern matches anything other than element nodes.</error></para>

<para>Each attribute on the document element of the document that
appears on the <port>attributes</port> port is copied to each element
that matches the <option>match</option> expression.</para>

<para>If an attribute with the same name as one of the attributes to
be copied already exists, the value specified on the
<port>attribute</port> port's document is used. The result port of
this step produces a copy of the <port>source</port> port's document
with the matching elements' attributes modified.</para>

<para>The matching elements are specified by the match pattern in the
<option>match</option> option. All matching elements are processed.
If no elements match, the step will not change any elements.</para>
</section>

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

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

<para>The <tag>p:sink</tag> step accepts a sequence of documents and
discards them. It has no output.</para>

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

</section>

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

<section xml:id="c.split-sequence">
<title>p:split-sequence</title>

<para>The <tag>p:split-sequence</tag> step accepts a sequence of
documents and divides it into two sequences.</para>

<p:declare-step type="p:split-sequence">
  <p:input port="source" sequence="true"/>
  <p:output port="matched" sequence="true" primary="true"/>
  <p:output port="not-matched" sequence="true"/>
  <p:option name="test" required="true"/>
</p:declare-step>
 
 <para>The value of the <option>test</option> option &must; be an XPathExpression.</para>

<para>The XPath expression in the
<option>test</option> option is applied to each document in the input
sequence. If the effective boolean value of the expression is true,
the document is copied to the <port>matched</port> port; otherwise it
is copied to the <port>not-matched</port> port.</para>

<para>The <link linkend="step-xpath-context">XPath context</link> for
the <option>test</option> option changes over time. For each document
that appears on the <code>source</code> port, the expression is
evaluated with that document as the context document. The context
position is the position of that document within the sequence and the
context size is the total number of documents in the sequence.</para>

<note>
<para>In principle, this component cannot stream because it must
buffer all of the input sequence in order to find the context size. In
practice, if the test expression does not use the
<function>last()</function> function, the implementation can stream
and ignore the context size.</para>
</note>

</section>

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

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

<para>The <tag>p:store</tag> step stores a serialized version of its
input to a URI. The URI is either specified explicitly by the 'href'
option or implicitly by the base URI of the document. This step
outputs a reference to the location of the stored document.</para>

<p:declare-step type="p:store">
   <p:input port="source"/>
   <p:output port="result" primary="false"/>
   <p:option name="href"/>
   <p:option name="byte-order-mark"/>
   <p:option name="cdata-section-elements"/>
   <p:option name="doctype-public"/>
   <p:option name="doctype-system"/>
   <p:option name="encoding"/>
   <p:option name="escape-uri-attributes"/>
   <p:option name="include-content-type"/>
   <p:option name="indent" value="false"/>
   <p:option name="media-type"/>
   <p:option name="method" value="xml"/>
   <p:option name="normalization-form"/>
   <p:option name="omit-xml-declaration"/>
   <p:option name="standalone"/>
   <p:option name="undeclare-prefixes"/>
   <p:option name="version" value="1.0"/>
</p:declare-step>

<para>The step attempts to store the XML document to the specified
URI. <error code="C0050">It is a <glossterm>dynamic error</glossterm>
if the URI scheme is not supported or the step cannot store to the
specified location.</error></para>

<para>The output of this step is a document containing a single
<tag>c:result</tag> element whose content is the absolute URI of the
document stored by the step.</para>

<para>The standard serialization options are provided to control the
serialization of the XML content when it is stored. These options are
as specified in <link linkend="serialization-options"/>.</para>

</section>

<section xml:id="c.unescape-markup">
<title>p:unescape-markup</title>

<para>The <tag>p:unescape-markup</tag> step takes the string value of
the document element and parses the content as if it was a Unicode
character stream containing serialized XML. The output consists of the
same document element with children that result from the parse. This
is the reverse of the <tag>p:escape-markup</tag> step.</para>

<p:declare-step type="p:unescape-markup">
  <p:input port="source"/>
  <p:output port="result"/>
  <p:option name="namespace"/>
  <p:option name="content-type" value="application/xml"/>
  <p:option name="encoding"/>
  <p:option name="charset"/>
</p:declare-step>
 
 <para>The value of the <option>namespace</option> option &must; be an anyURI. 
 It <rfc2119>should</rfc2119> be absolute, but will not be resolved.</para>

<para>When the string value is parsed, the original document element is
preserved so that the result will be well-formed XML even if the content
consists of multiple, sibling elements.</para>

<para>The <option>namespace</option> option specifies the default
namespace. If it is provided, it will be declared as the default
namespace on the document element.</para>

<para>The <option>content-type</option> option <rfc2119>may</rfc2119>
be used to specify an alternate content type for the string value. An
implementation <rfc2119>may</rfc2119> use a different parser to
produce XML content depending on the specified content-type. For
example, an implementation might provide an HTML to XHTML parser (e.g.
<biblioref linkend="tidy"/> or <biblioref linkend="tagsoup"/>) for the
content type '<literal>text/html</literal>'.</para>

<para><impl>Behavior of
<tag>p:unescape-markup</tag> for <option>content-type</option>s other
than <literal>application/xml</literal> is
<glossterm>implementation-defined</glossterm>.</impl></para>

<para>All implementations <rfc2119>must</rfc2119> support the content
type <literal>application/xml</literal>, and must use a standard XML
parser for it. <error code="C0051">It is a <glossterm>dynamic
error</glossterm> if the content-type specified is not supported by
the implementation.</error></para>

<para>The <option>encoding</option> option specifies how the data is
encoded. All implementations <rfc2119>must</rfc2119> support the
<literal>base64</literal> encoding (and the absence of an encoding
option, which implies that the content is plain Unicode text).
<error code="C0052">It is a <glossterm>dynamic error</glossterm> if the
encoding specified is not supported by the
implementation.</error></para>

<para>If an <option>encoding</option> is specified, a <option>charset</option>
may also be specified. The octet-stream that results from decoding the
text <rfc2119>must</rfc2119> be interpreted using the specified encoding
to produce a sequence of Unicode characters to parse. If the option is not
specified, the value “UTF-8” <rfc2119>must</rfc2119> be used.</para>

<para><error code="C0010">It is a <glossterm>dynamic error</glossterm>
if the <option>charset</option> specified is not supported by the
implementation or if <option>charset</option> is specified when
<option>encoding</option> is not.</error></para>

<para>For example, with the 'namespace' option set to the XHTML
namespace, the following input:</para>

<programlisting>&lt;description&gt;
&amp;lt;p&gt;This is a chunk.&amp;lt;/p&gt;
&amp;lt;p&gt;This is a another chunk.&amp;lt;/p&gt;
&lt;/description&gt;
</programlisting>

<para>would produce:</para>

<programlisting>&lt;description xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;p&gt;This is a chunk.&lt;/p&gt;
&lt;p&gt;This is a another chunk.&lt;/p&gt;
&lt;/description&gt;
</programlisting>
</section>

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

<section xml:id="c.string-replace">
<title>p:string-replace</title>

<para>The <tag>p:string-replace</tag> step matches nodes in the
document provided on the <port>source</port> port and replaces them
with the string result of evaluating an XPath expression.</para>

<p:declare-step type="p:string-replace">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="match" required="true"/>
   <p:option name="replace" required="true"/>
</p:declare-step>
 
 <para>The value of the <option>match</option> option &must; be an XSLTMatchPattern.</para>
 
 <para>The value of the <option>replace</option> option &must; be an XPathExpression.</para>

<para>The matched nodes are specified with the match pattern in the
<option>match</option> option. For each matching node, the XPath
expression provided by the <option>replace</option> option is
evaluated and the string value of the result is used in the output.
Nodes that do not match are copied without change.</para>

<para>If the expression given in the <option>match</option> option 
matches an <emphasis>attribute</emphasis>, the string value of the
<option>replace</option>
expression is used as the new value of the attribute in the output.
</para>

<para>If the expression matches any other kind of node, the entire
node (and <emphasis>not</emphasis> just its contents) is replaced by
the string value of the <option>replace</option> expression.</para>
</section>

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

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

<para>The <tag>p:unwrap</tag> step replaces matched elements with their
children.</para>

<p:declare-step type="p:unwrap">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="match" required="true"/>
</p:declare-step>
 
 <para>The value of the <option>match</option> option &must; be an XSLTMatchPattern.  <error code="C0023">It is a <glossterm>dynamic error</glossterm> if that
pattern matches anything other than element nodes.</error></para>

<para>Every element in the <port>source</port> document that matches
the specified <option>match</option> pattern is replaced by its children,
effectively “unwrapping” the children from their parent. Non-element nodes
and unmatched elements are passed through unchanged.</para>

<note>
<para>The matching applies to the entire document, not just the “top-most”
matches. A pattern of the form <literal>h:div</literal> will replace
<emphasis>all</emphasis> <tag>h:div</tag> elements, not just the top-most
ones.</para>
</note>

<para>This step produces a single document; if the document element is
unwrapped, the result may not be well-formed XML.</para>
</section>

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

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

<para>The <tag>p:wrap</tag> step wraps matching nodes in the
<port>source</port> document with a new parent element.</para>

<p:declare-step type="p:wrap">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="wrapper" required="true"/>
   <p:option name="match" required="true"/>
   <p:option name="group-adjacent"/>
</p:declare-step>

<para>The value of the <option>wrapper</option> option &must; be a &qn;.</para>
 
 <para>The value of the <option>match</option> option &must; be an XSLTMatchPattern.</para>
 
 <para>The value of the <option>group-adjacent</option> option &must; be an XPathExpression.</para>
 
 <para>Every node that matches the specified
<option>match</option> pattern is replaced with a new element node
whose QName is the value specified in the <option>wrapper</option>
option. The content of that new element is a copy of the original,
matching node.</para>

<para>The <option>group-adjacent</option> option can be used to group
adjacent matching nodes in a single wrapper element. The specified
XPath expression is evaluated for each matching node with that node
as the XPath context node. Whenever two or more adjacent matching nodes
have the same “group adjacent” value, they are wrapped together in
a single wrapper element.</para>

<para>Two matching nodes are considered adjacent if and only if they
are siblings and either there are no nodes between them or all
intervening nodes are whitespace text, comment, or processing
instruction nodes.</para>

</section>

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

<section xml:id="c.wrap-sequence">
<title>p:wrap-sequence</title>

<para>The <tag>p:wrap-sequence</tag> step accepts a sequence of
documents and produces either a single document or a new sequence of
documents.</para>

<p:declare-step type="p:wrap-sequence">
   <p:input port="source" sequence="true"/>
   <p:output port="result" sequence="true"/>
   <p:option name="wrapper" required="true"/>
   <p:option name="group-adjacent"/>
</p:declare-step>

<para>The value of the <option>wrapper</option> option &must; be a &qn;.</para>
 
 <para>The value of the <option>group-adjacent</option> option &must; be an XPathExpression.</para>

<para>In its simplest form, <tag>p:wrap-sequence</tag> takes a
sequence of documents and produces a single, new document by placing
each document in the <port>source</port> sequence inside a new
document element as sequential siblings. The name of the document
element is the value specified in the <option>wrapper</option>
option.</para>

<para>The <option>group-adjacent</option> option can be used to group
adjacent documents. The specified XPath expression is evaluated for
each document with that document as the XPath context node. Whenever
two or more sequentially adjacent documents have the same “group
adjacent” value, they are wrapped together in a single wrapper
element.</para>
</section>

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

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

<para>The <tag>p:xinclude</tag> step applies <biblioref linkend="xinclude"/> processing to the <port>source</port> document.</para>

<p:declare-step type="p:xinclude">
  <p:input port="source"/>
  <p:output port="result"/>
  <p:option name="fixup-xml-base" value="false"/>
  <p:option name="fixup-xml-lang" value="false"/>
</p:declare-step>

<para>The value of the <option>fixup-xml-base</option> option &must; be a
boolean. If it is true, base URI fixup will be performed as per
<biblioref linkend="xinclude"/>.</para>

<para>The value of the <option>fixup-xml-lang</option> option &must; be a
boolean. If it is true, language fixup will be performed as per
<biblioref linkend="xinclude"/>.</para>

<para>The included documents are located with the base URI of the
input document and are not provided as input to the step.</para>

<para><error code="C0029">It is a <glossterm>dynamic error</glossterm>
if an XInclude error occurs during processing.</error> </para>
</section>

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

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

<para>The <tag>p:xslt</tag> step applies an
<biblioref linkend="xslt10"/> or
<biblioref linkend="xslt20"/> stylesheet to a document.</para>

<p:declare-step type="p:xslt">
  <p:input port="source" sequence="true" primary="true"/>
  <p:input port="stylesheet"/>
  <p:input port="parameters" kind="parameter" sequence="true"/>
  <p:output port="result" primary="true"/>
  <p:output port="secondary" sequence="true"/>
  <p:option name="initial-mode"/>
  <p:option name="template-name"/>
  <p:option name="output-base-uri"/>
  <p:option name="version"/>
</p:declare-step>
 
<para>If present, the value of the <option>initial-mode</option>
option &must; be a &qn;.</para>
 
<para>If present, the value of the <option>template-name</option>
option &must; be a &qn;.</para>
 
<para>If present, the value of the <option>output-base-uri</option>
option &must; be an anyURI.</para>

<para>If the step specifies a <option>version</option>, then that version
of XSLT <rfc2119>must</rfc2119> be used to process the transformation.
<error code="C0038">It is a
<glossterm>dynamic error</glossterm> if the specified version of XSLT
is not available.</error> If the step does not specify a version, the
implementation may use any version it has available and may use any means
to determine what version to use, including, but not limited to,
examining the version of the stylesheet.</para>

<para>The XSLT stylesheet provided on the <port>stylesheet</port> port
is applied to the document on the <port>source</port> port. The
primary result document of the transformation appears on the
<port>result</port> port. All other result documents appear on the
<port>secondary</port> port. If XSLT 1.0 is used, an empty sequence of
documents <rfc2119>must</rfc2119> appear on the <port>secondary</port>
port.</para>

<para>If a sequence of documents is provided on the
<port>source</port> port, the first document is assumed to be the
primary input document. This sequence is also the default
collection.
<error code="C0039">It is a
<glossterm>dynamic error</glossterm> if a sequence of documents is provided
to an XSLT 1.0 step.</error>
</para>

<para>A dynamic error occurs if the XSLT processor signals a fatal
error. This includes the case where the transformation terminates due
to a <tag>xsl:message</tag> instruction with a <tag class="attribute">terminate</tag> attribute value of
“<literal>yes</literal>”. <impl>How XSLT message termination
errors are reported to the XProc processor is
<glossterm>implementation-dependent</glossterm>.</impl></para>

<para>The invocation of the transformation is controlled by the
<option>initial-mode</option> and <option>template-name</option>
options that set the initial mode and/or named template in the XSLT
transformation where processing begins. <error code="C0056">It is a
<glossterm>dynamic error</glossterm> if the specified initial mode
or named template cannot be applied to the specified stylesheet.</error>
</para>

<para>The <option>output-base-uri</option> option sets the context's
output base URI per the XSLT 2.0 specification, otherwise the base URI
of the <port>result</port> document is the base URI of the first
document in the <code>source</code> port's sequence. If the value of
the <option>output-base-uri</option> option is not absolute, it will
be resolved using the base URI of its <tag>p:option</tag>
element. An XSLT 1.0 step <rfc2119>should</rfc2119> use the value of the
<option>output-base-uri</option> as the base URI of its output, if the
option is specified.</para>
</section>
</section>

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

<section xml:id="std-optional">
<title>Optional Steps</title>

<para>The following steps are optional. If they are supported by a
processor, they must conform to the semantics outlined here, but a
conformant processor is not required to support all (or any) of these
steps.</para>

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

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

<para>The <tag>p:exec</tag> step runs an external command passing the
input that arrives on its <port>source</port> port as standard input,
reading <port>result</port> from standard output, and <port>errors</port>
from standard error.</para>

<p:declare-step type="p:exec">
  <p:input port="source" primary="true" sequence="true"/>
  <p:output port="result" primary="true"/>
  <p:output port="errors"/>
  <p:option name="command" required="true"/>
  <p:option name="args"/>
  <p:option name="cwd"/>
  <p:option name="source-is-xml" value="true"/>
  <p:option name="result-is-xml" value="true"/>
  <p:option name="wrap-result-lines" value="false"/>
  <p:option name="errors-is-xml" value="false"/>
  <p:option name="wrap-error-lines" value="false"/>
  <p:option name="fix-slashes" value="false"/>
  
  <!-- plus the serialization options -->
  <p:option name="byte-order-mark"/>
  <p:option name="cdata-section-elements"/>
  <p:option name="doctype-public"/>
  <p:option name="doctype-system"/>
  <p:option name="encoding"/>
  <p:option name="escape-uri-attributes"/>
  <p:option name="include-content-type"/>
  <p:option name="indent" value="false"/>
  <p:option name="media-type"/>
  <p:option name="method" value="xml"/>
  <p:option name="normalization-form"/>
  <p:option name="omit-xml-declaration"/>
  <p:option name="standalone"/>
  <p:option name="undeclare-prefixes"/>
  <p:option name="version" value="1.0"/>
</p:declare-step>  

<para>The values of the <option>command</option>, <option>args</option>
and <option>cwd</option> options <rfc2119>must</rfc2119> be a string.</para>

<para>The values of the <option>source-is-xml</option>,
<option>result-is-xml</option>, <option>errors-is-xml</option>,
and <option>fix-slashes</option> options <rfc2119>must</rfc2119> be 
boolean.</para>

<para>The <tag>p:exec</tag> step executes the command passed on
<option>command</option> with the arguments passed on
<option>args</option>.
<error code="C0033">It is a <glossterm>dynamic
error</glossterm> if the command cannot be run.</error>
</para>

<para>If <option>cwd</option> is specified, then the current working
directory is changed to the value of that option before execution
begins. <error code="C0034">It is a <glossterm>dynamic
error</glossterm> if the current working directory cannot be changed
to the value of the <option>cwd</option> option.</error>
<impl>If <option>cwd</option> is not
specified, the current working directory is
<glossterm>implementation-defined</glossterm>.</impl></para>

<para>If the <option>command</option> or <option>cwd</option> options
contain any “/” or “\” characters, they will be replaced with the
platform-specific path separator character. If the <option>fix-slashes</option>
option is “true”, this fixup will be applied to <option>args</option>
as well.</para>

<para>The document that arrives on the <port>source</port> port will
be passed to the command as its standard input. If
<option>source-is-xml</option> is true, the serialization options are
used to convert the input into serialized XML which is passed to
the command, otherwise the XPath string-value
of the document is passed.</para>

<para>The standard output of the command is read and returned on
<port>result</port>; the standard error output is read and returned on
<port>errors</port>. In order to assure that the result will be an
XML document, each of the results will be wrapped in a <tag>c:result</tag>
element.</para>

<para>If <option>result-is-xml</option> is true, the standard output of
the program is assumed to be XML and will be parsed as a single document.
If it is false, the output is assumed <emphasis>not</emphasis> to be XML
and will be returned as escaped text.</para>

<para xml:id="cv.line">If <option>wrap-result-lines</option> is
true, a <tag>c:line</tag> element will be wrapped around each line of output.</para>

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

<para><error code="C0035">It is a <glossterm>dynamic
error</glossterm> to specify both <option>result-is-xml</option> and
<option>wrap-result-lines</option>.</error></para>

<para>The same rules apply to the
standard error output of the program, with the <option>errors-is-xml</option>
and <option>wrap-error-lines</option> options, respectively.</para>

<para>If either of the results are XML, they <rfc2119>must</rfc2119> be
parsed with namespaces enabled and validation turned off, just like
<tag>p:document</tag>.</para>

<para>The single <option>args</option> option is treated as a series
of whitespace-separated values. Values which contain spaces may be quoted
with either single (') or double (") quotes. A literal quote character
may be inserted by doubling it.</para>
</section>

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

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

<para>The <tag>p:hash</tag> step generates a hash, or digital “fingerprint”,
for some value and injects it into the <port>source</port> document.</para>

<p:declare-step type="p:hash">
  <p:input port="source" primary="true"/>
  <p:output port="result"/>
  <p:input port="parameters" kind="parameter"/>
  <p:option name="value" required="true"/>
  <p:option name="algorithm" required="true"/>
  <p:option name="match" required="true"/>
</p:declare-step>

<para>The value of the <option>algorithm</option> option must be a QName.
If it does not have a prefix, then it must be one of the following values:
“md5”, “sha1”.</para>

<para>A hash is constructed from the string specified in the
<option>value</option> option using the specified algorithm.</para>
 
<para>The value of the <option>match</option> option must be an
XSLTMatchPattern.</para>

<para>The hash of the specified value is computed using the algorithm and
parameters specified. <error code="C0036">It is a
<glossterm>dynamic error</glossterm> if the requested hash algorithm is not
one that the processor understands or if the value or parameters are
not appropriate for that algorithm.</error></para>

<para><impl>Conformant processors &must; support the “md5” and “sha1”
algorithms. It is
<glossterm>implementation-defined</glossterm> what other algorithms are
supported.</impl></para>

<note role="editorial">
<para>TBD: Are there any parameters to the md5 or sha1 algorithms?
</para>
</note>
 
<para>The matched nodes are specified with the match pattern in the
<option>match</option> option. For each matching node, the string
value of the computed hash is used in the output. Nodes that do not
match are copied without change.</para>

<para>If the expression given in the <option>match</option> option 
matches an <emphasis>attribute</emphasis>, the hash
is used as the new value of the attribute in the output.
</para>

<para>If the expression matches any other kind of node, the entire
node (and <emphasis>not</emphasis> just its contents) is replaced by
the hash.</para>
</section>

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

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

<para>The <tag>p:uuid</tag> step generates a UUID and injects it into
the <port>source</port> document.</para>

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

<para>The value of the <option>match</option> option must be an
XSLTMatchPattern.</para>

<note role="editorial">
<para>TBD: Do we need to provide options or parameters for UUID
construction?</para>
</note>
 
<para>The matched nodes are specified with the match pattern in the
<option>match</option> option. For each matching node, the generated
UUID is used in the output. Nodes that do not
match are copied without change.</para>

<para>If the expression given in the <option>match</option> option 
matches an <emphasis>attribute</emphasis>, the UUID
is used as the new value of the attribute in the output.
</para>

<para>If the expression matches any other kind of node, the entire
node (and <emphasis>not</emphasis> just its contents) is replaced by
the UUID.</para>
</section>

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

<section xml:id="c.validate-with-relax-ng">
<title>p:validate-with-relax-ng</title>

<para>The <tag>p:validate-with-relax-ng</tag> step applies 
<biblioref linkend="iso19757-2"/>
validation to the <port>source</port> document.</para>

<p:declare-step type="p:validate-with-relax-ng">
  <p:input port="source" primary="true"/>
  <p:input port="schema"/>
  <p:output port="result"/>
  <p:option name="dtd-compatibility" value="false"/>
  <p:option name="assert-valid" value="true"/>
</p:declare-step>
 
 <para>The value of the <option>dtd-compatibility</option> option &must; be a boolean.</para>
 
 <para>The value of the <option>assert-valid</option> option &must; be a boolean.</para>

<para>If the <option>dtd-compatibility</option> option is
“<literal>true</literal>”, then the conventions of
<biblioref linkend="relaxng-dtd-compat"/> are also applied.</para>

<para><error code="C0053">It is a <glossterm>dynamic error</glossterm>
if the <option>assert-valid</option> option is <literal>true</literal>
and the input document is not valid.</error></para>

<para>The output from this step is a copy of the input, possibly
augmented by application of the
<biblioref linkend="relaxng-dtd-compat"/>.</para>
</section>

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

<section xml:id="c.validate-with-schematron">
<title>p:validate-with-schematron</title>

<para>The <tag>p:validate-with-schematron</tag> step applies
<biblioref linkend="iso19757-3"/>
processing to the <port>source</port> document.</para>

<p:declare-step type="p:validate-with-schematron">
  <p:input port="source" primary="true"/>
  <p:input port="schema"/>
  <p:output port="result"/>
</p:declare-step>

<para><error code="C0054">It is a <glossterm>dynamic error</glossterm>
if any Schematron assertions fail.</error></para>

<para>The output from this step is a copy of the input.</para>
</section>

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

<section xml:id="c.validate-with-xml-schema">
<title>p:validate-with-xml-schema</title>

<para>The <tag>p:validate-with-xml-schema</tag> step applies
<biblioref linkend="xmlschema-1"/>
validity assessment to the <port>source</port> input.</para>

<p:declare-step type="p:validate-with-xml-schema">
  <p:input port="source" primary="true"/>
  <p:input port="schema" sequence="true"/>
  <p:output port="result"/>
  <p:option name="assert-valid" value="true"/>
  <p:option name="mode" value="strict"/>
</p:declare-step>
 
 <para>The value of the <option>assert-valid</option> option &must; be a boolean.</para>
 
 <para>The value of the <option>mode</option> option &must; be an NMTOKEN whose
value is either “<literal>strict</literal>” or “<literal>lax</literal>”.</para>

<para>Validation is performed against the set of schemas represented by the documents on
the <port>schema</port> port.</para>

<para><error code="C0053">It is a <glossterm>dynamic error</glossterm>
if the <option>assert-valid</option> option is <literal>true</literal>
and the input document is not valid.</error></para>

<para>When XML Schema validation assessment
is performed, the processor is invoked in the mode specified by the
<option>mode</option> option.
<error code="C0055">It is a <glossterm>dynamic error</glossterm>
if the implementation does not support the specified mode.</error>
</para>

<para>The <port>result</port> of the assessment is a document with the
Post-Schema-Validation-Infoset (PSVI) (<biblioref linkend="xmlschema-1"/>) annotations, if the pipeline implementation
supports such annotations. If not, the input document is reproduced
with any defaulting of attributes and elements performed as specified
by the XML Schema recommendation.</para>

<para><impl>Whether or not the pipeline processor supports passing
PSVI annotations between steps is
<glossterm>implementation-defined</glossterm>.</impl></para>
</section>

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

<section xml:id="c.www-form-urldecode">
<title>p:www-form-urldecode</title>

<para>The <tag>p:www-form-urldecode</tag> step decodes a
<literal>x-www-form-urlencoded</literal> string into a set of parameters.</para>

<p:declare-step type="p:www-form-urldecode">
  <p:output port="result"/>
  <p:option name="value" required="true"/>
</p:declare-step>

<para>The <option>value</option> option is interpreted as a string of
parameter values encoded using the 
<literal>x-www-form-urlencoded</literal> algorithm. It turns each such
encoded name/value pair into a parameter. The entire set of parameters
is written (as a <tag>c:parameter-set</tag>) on the <port>result</port>
output port.</para>

<para><error code="C0037">It is a
<glossterm>dynamic error</glossterm> if the <option>value</option> provided
is not a properly 
<literal>x-www-form-urlencoded</literal> value.</error></para>
</section>

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

<section xml:id="c.www-form-urlencode">
<title>p:www-form-urlencode</title>

<para>The <tag>p:www-form-urlencode</tag> step encodes a set of parameter
values as a <literal>x-www-form-urlencoded</literal> string and
injects it into the <port>source</port> document.</para>

<p:declare-step type="p:www-form-urlencode">
  <p:input port="source" primary="true"/>
  <p:output port="result"/>
  <p:input port="parameters" kind="parameter"/>
  <p:option name="match" required="true"/>
</p:declare-step>

<para>The value of the <option>match</option> option must be an
XSLTMatchPattern.</para>

<para>The set of parameters is encoded as a single 
<literal>x-www-form-urlencoded</literal> string.</para>

<para>The matched nodes are specified with the match pattern in the
<option>match</option> option. For each matching node, the encoded
string is used in the output. Nodes that do not
match are copied without change.</para>

<para>If the expression given in the <option>match</option> option 
matches an <emphasis>attribute</emphasis>, the encoded
string is used as the new value of the attribute in the output.
</para>

<para>If the expression matches any other kind of node, the entire
node (and <emphasis>not</emphasis> just its contents) is replaced by
the encoded string.</para>
</section>

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

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

<para>The <tag>p:xquery</tag> step applies an
<biblioref linkend="xquery10"/> query to the sequence of documents
provided on the <port>source</port> port.</para>

<p:declare-step type="p:xquery">
  <p:input port="source" sequence="true" primary="true"/>
  <p:input port="query"/>
  <p:input port="parameters" kind="parameter" sequence="true"/>
  <p:output port="result" sequence="true"/>
</p:declare-step>

<para>The sequence of documents provided on the <port>source</port>
port is treated as the default collection. The result of the XQuery is
a sequence of documents constructed from an <biblioref linkend="xpath2"/> sequence of elements. Each element in the sequence
is assumed to be the document element of a separate document. <error code="C0057">It is a <glossterm>dynamic error</glossterm> if the
sequence that results from an XQuery contains items other than
elements.</error>
</para>

<para>The <port>query</port>&gt; port must receive a single document
whose element is <tag xml:id="cv.query">c:query</tag>. As an XQuery is
not necessarily well-formed XML, the text descendants of this element
are considered the query.</para>

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

<para>The base URI of each of the output documents is the base URI of
the first document in the <code>source</code> port's sequence.</para>

<para>For example:</para>
<programlisting><![CDATA[
<c:query>
declare namespace atom="http://www.w3.org/2005/Atom";
/atom:feed/atom:entry
</c:query>
]]>
</programlisting>
</section>

<!-- ************************************************************************-->
<!--
<section xml:id="c.xslt2">
<title>p:xslt2</title>

<para>The <tag>p:xslt2</tag> step applies an
<biblioref linkend="xslt20"/> stylesheet to a document.</para>

<p:declare-step type="p:xslt2">
  <p:input port="source" sequence="true" primary="true"/>
  <p:input port="stylesheet"/>
  <p:input port="parameters" kind="parameter" sequence="true"/>
  <p:output port="result" primary="true"/>
  <p:output port="secondary" sequence="true"/>
  <p:option name="initial-mode"/>
  <p:option name="template-name"/>
  <p:option name="allow-version-mismatch" value="true"/>
  <p:option name="output-base-uri"/>
  <p:option name="allow-collections" value="true"/>
</p:declare-step>
 
 <para>If present, the value of the <option>initial-mode</option> option &must; be a &qn;.</para>
 
 <para>If present, the value of the <option>template-name</option> option &must; be a &qn;.</para>
 
 <para>The value of the <option>allow-version-mismatch</option> option &must; be a boolean.</para>
 
 <para>If present, the value of the <option>output-base-uri</option> option &must; be an
anyURI.</para>

 <para>The value of the <option>allow-collections</option> option &must; be a boolean.</para>

<para>The XSLT stylesheet provided on the <port>stylesheet</port> port
is applied to the document on the <port>source</port> port. The
primary result document of the transformation appears on the
<port>result</port> port. All other result documents appear on the
<port>secondary</port> port.</para>

<para>If a sequence of documents is provided on the
<port>source</port> port, the first document is assumed to be the
primary input document. By default, this sequence is also the default
collection unless the <option>allow-collections</option> option is set
to “<literal>false</literal>”.</para>

<para>A dynamic error occurs if the XSLT processor signals a fatal
error. This includes the case where the transformation terminates due
to a <tag>xsl:message</tag> instruction with a <tag class="attribute">terminate</tag> attribute value of
“<literal>yes</literal>”. <impl>How XSLT 2.0 message termination
errors are reported to the XProc processor is
<glossterm>implementation-dependent</glossterm>.</impl></para>

<para>The invocation of the transformation is controlled by the
<option>initial-mode</option> and <option>template-name</option>
options that set the initial mode and/or named template in the XSLT
transformation where processing begins. <error code="C0056">It is a
<glossterm>dynamic error</glossterm> if the specified initial mode
or named template cannot be applied to the specified stylesheet.</error>
</para>

<para>The <option>allow-version-mismatch</option> option indicates
whether an XSLT 1.0 transformation should be allowed to be run through
the XSLT 2.0 processor. A value of “<literal>true</literal>” means
that it should be allow.</para>

<para>The <option>output-base-uri</option> option sets the context's
output base URI per the XSLT 2.0 specification, otherwise the base URI
of the <port>result</port> document is the base URI of the first
document in the <code>source</code> port's sequence.  If the value of the
<option>output-base-uri</option> option is not absolute, it will be resolved using the
base URI of its <tag>p:option</tag> element.</para>
</section>
-->
<!-- ************************************************************************-->

<section xml:id="c.xsl-formatter">
<title>p:xsl-formatter</title>

<para>The <tag>p:xsl-formatter</tag> step receives an <biblioref linkend="xsl11"/> document and renders the content. The result of
rendering is stored to the URI provided via the <option>uri</option>
option. A reference to that result is produced on the output
port.</para>

<p:declare-step type="p:xsl-formatter">
  <p:input port="source"/>
  <p:input port="parameters" kind="parameter" sequence="true"/>
  <p:output port="result" primary="false"/>
  <p:option name="uri" required="true"/>
  <p:option name="content-type"/>
</p:declare-step>
 
 <para>The value of the <option>output-base-uri</option> option &must; be an
anyURI.  It may be relative, in which case it will be resolved against the base
URI of its <tag>p:option</tag> element before use.</para>

<para>The content-type of the output is controlled by the
<option>content-type</option> option. This option specifies a media
type as defined by <biblioref linkend="media-types"/>. The option may
include media type parameters as well (e.g.
"application/someformat; charset=UTF-8"). <impl>The use of media type
parameters on the <option>content-type</option> option is
<glossterm>implementation-defined</glossterm>.</impl></para>

<para><impl>If the <option>content-type</option> option is not specified,
the output type is <glossterm>implementation-defined</glossterm>.</impl> The default <rfc2119>should</rfc2119> be
PDF.</para>

<para><impl>A formatter may take any number of optional rendering
parameters via the step's parameters; such parameters are defined by
the XSL implementation used and are
<glossterm>implementation-defined</glossterm>.</impl></para>

<para>The output of this step is a document containing a single
<tag>c:result</tag> element whose content is the absolute URI of the
document stored by the step.</para>
</section>
</section>

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

<para>Several steps in this step library require serialization options
to control the serialization of XML. These options are used to control
serialization as in the <biblioref linkend="xml-serialization"/>
specification.</para>

<para>The following options may be present on steps that perform
serialization:</para>

<itemizedlist spacing="compact">
<listitem>
<simpara><option>byte-order-mark</option> -
The value of this option &must; be a boolean.</simpara>
</listitem>
<listitem>
<simpara><option>cdata-section-elements</option> -
The value of this option &must; be a list of &qn;s.  They are interpreted as elements name.</simpara>
</listitem>
<listitem>
<simpara><option>doctype-public</option> -
The value of this option &must; be an anyURI.  The public identifier of the
doctype.  It need not be absolute, and is not resolved.</simpara>
</listitem>
<listitem>
<simpara><option>doctype-system</option> -
The value of this option &must; be an anyURI.  The system identifier of the doctype.  It need not be absolute, and is not resolved.</simpara>
</listitem>
<listitem>
<simpara><option>encoding</option> -
A character set name.</simpara>
</listitem>
<listitem>
<simpara><option>escape-uri-attributes</option> -
The value of this option &must; be a boolean.</simpara>
</listitem>
<listitem>
<simpara><option>include-content-type</option> -
The value of this option &must; be a boolean.</simpara>
</listitem>
<listitem>
<simpara><option>indent</option> -
The value of this option &must; be a boolean.</simpara>
</listitem>
<listitem>
<simpara><option>media-type</option> -
The value of this option &must; be a string.  It specifies the media type (MIME content type).</simpara>
</listitem>
<listitem>
<simpara><option>method</option> -
The value of this option &must; be a &qn;.  It specifies the serialization method.</simpara>
</listitem>
<listitem>
<simpara><option>normalization-form</option> -
The value of this option &must; be an NMTOKEN, one of the enumerated values <code>NFC</code>, <code>NFD</code>,
<code>NFKC</code>, <code>NFKD</code>, <code>fully-normalized</code>,
<code>none</code> or an implementation-defined value.</simpara>
</listitem>
<listitem>
<simpara><option>omit-xml-declaration</option> -
The value of this option &must; be a boolean.</simpara>
</listitem>
<listitem>
<simpara><option>standalone</option> -
The value of this option &must; be an NMTOKEN, one of the enumerated values <code>true</code>, <code>false</code>, or <code>omit</code>.
</simpara>
</listitem>
<listitem>
<simpara><option>undeclare-prefixes</option> -
The value of this option &must; be a boolean.</simpara>
</listitem>
<listitem>
<simpara><option>version</option> -
The value of this option &must; be a string.</simpara>
</listitem>
</itemizedlist>

<para>In order to be consistent with the rest of this specification,
boolean values for the serialization parameters use “true” and “false”
where the serialization specification uses “yes” and “no”. No change in
semantics is implied by this different spelling.</para>

<para>The <option>method</option> option controls the serialization
method used by this component with standard values of 'html', 'xml',
'xhtml', and 'text' but only the 'xml' value is required to be
supported. The interpretation of the remaining options are as
specified in <biblioref linkend="xml-serialization"/>.</para>

<para><impl>Implementations may support other method values but their
results are <glossterm>implementation-defined</glossterm>.</impl>
<error code="C0001">It is a <glossterm>dynamic error</glossterm> if the
requested method is not supported.</error></para>

<para>A minimally conforming implementation must support the
<code>xml</code> output method with the following option
values:</para>

<itemizedlist>
   <listitem><para>The <code>version</code> must support the value <code>1.0</code>.</para></listitem>
   <listitem><para>The <code>encoding</code> must support the values <code>UTF-8</code>.</para></listitem>
   <listitem><para>The <code>omit-xml-declaration</code> must support be supported.  If the value is not specified or has the value <code>no</code>, an XML declaration must be produced.</para></listitem>
</itemizedlist>

<para>All other option values may be ignored for the <code>xml</code>
output method.</para>

<para>If a processor chooses to implement an option for serialization,
it must conform to the semantics defined in the <biblioref linkend="xml-serialization"/> specification.</para>

<note>
<para>The use-character-maps parameter in <biblioref linkend="xml-serialization"/> specification has not been provided in
the standard serialization options provided by this
specification.</para>
</note>
</section>
</section>

<appendix xml:id="conformance">
<title>Conformance</title>

<para>Conformant processors <rfc2119>must</rfc2119> implement all of the features
described in this specification except those that are explicitly identified
as optional.</para>

<para>Some aspects of processor behavior are not completely specified; those
features are either <glossterm role="unwrapped">implementation-dependent</glossterm> or
<glossterm role="unwrapped">implementation-defined</glossterm>.</para>

<para><termdef xml:id="dt-implementation-dependent">An
<firstterm>implementation-dependent</firstterm> feature is one where the
implementation has discretion in how it is performed.
Implementations are not required to document or explain
how <glossterm role="unwrapped">implementation-dependent</glossterm> features are performed.</termdef>
</para>

<para><termdef xml:id="dt-implementation-defined">An
<firstterm>implementation-defined</firstterm> feature is one where the
implementation has discretion in how it is performed.
Conformant implementations <rfc2119>must</rfc2119> document
how <glossterm role="unwrapped">implementation-defined</glossterm> features are performed.</termdef>
</para>

<section xml:id="implementation-defined">
<title>Implementation-defined features</title>

<para>The following features are implementation-defined:</para>

<?implementation-defined-features?>
</section>

<section xml:id="implementation-dependent">
<title>Implementation-dependent features</title>

<para>The following features are implementation-dependent:</para>

<?implementation-dependent-features?>
</section>

<section xml:id="infoset-conformance">
<title>Infoset Conformance</title>

<para>This specification conforms to the XML Information Set <biblioref linkend="xml-infoset-rec"/>. The information corresponding to the
following information items and properties must be available to the
processor for the documents that flow through the pipeline.</para>

<itemizedlist>
  <listitem><para>The <literal role="info-item">Document Information Item</literal> with
           <literal role="infoset-property">base URI</literal> and
           <literal role="infoset-property">children</literal>
           properties.</para></listitem>

  <listitem><para><literal role="info-item">Element Information Items</literal> with
           <literal role="infoset-property">base URI</literal>,
           <literal role="infoset-property">children</literal>,
           <literal role="infoset-property">attributes</literal>,
           <literal role="infoset-property">in-scope namespaces</literal>,
           <literal role="infoset-property">prefix</literal>,
           <literal role="infoset-property">local name</literal>,
           <literal role="infoset-property">namespace name</literal>,
           <literal role="infoset-property">parent</literal> properties.</para></listitem>

  <listitem><para><literal role="info-item">Attribute Information Items</literal> with
           <literal role="infoset-property">namespace name</literal>,
           <literal role="infoset-property">prefix</literal>,
           <literal role="infoset-property">local name</literal>,
           <literal role="infoset-property">normalized value</literal>,
           <literal role="infoset-property">attribute type</literal>, and
           <literal role="infoset-property">owner element</literal> properties.</para></listitem>

  <listitem><para><literal role="info-item">Character Information Items</literal> with
           <literal role="infoset-property">character code</literal>,
           <literal role="infoset-property">parent</literal>, and, optionally,
           <literal role="infoset-property">element content whitespace</literal>
           properties.</para></listitem>

  <listitem><para><literal role="info-item">Processing Instruction Information Items</literal> with
           <literal role="infoset-property">base URI</literal>,
           <literal role="infoset-property">target</literal>,
           <literal role="infoset-property">content</literal> and
           <literal role="infoset-property">parent</literal> properties.</para></listitem>

  <listitem><para><literal role="info-item">Comment Information Items</literal> with
           <literal role="infoset-property">content</literal> and
           <literal role="infoset-property">parent</literal> properties.</para></listitem>

  <listitem><para><literal role="info-item">Namespace Information Items</literal> with
           <literal role="infoset-property">prefix</literal> and
           <literal role="infoset-property">namespace name</literal> properties.</para></listitem>
</itemizedlist>

<para><impl>It is <glossterm>implementation-defined</glossterm> whether
additional information items and properties, particularly those made available
in the PSVI, are preserved between steps.</impl></para>
</section>
</appendix>

<appendix xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="references" version="5.0-extension w3c-xproc">

<title>References</title>

<bibliolist>
<bibliomixed xml:id="xml-core-wg"><abbrev>XML Core Req</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/proc-model-req/">XML
Processing Model Requirements</citetitle>.
Dmitry Lenkov, Norman Walsh, editors. W3C
Working Group Note 05 April 2004
</bibliomixed>

<bibliomixed xml:id="xml-infoset-rec"><abbrev>Infoset</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xml-infoset/">XML
Information Set (Second Edition)</citetitle>. John Cowan,
Richard Tobin, editors. W3C Working Group Note 04 February 2004.
</bibliomixed>

<bibliomixed xml:id="xml10"><abbrev>XML 1.0</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/REC-xml/">Extensible
Markup Language (XML) 1.0 (Fourth Edition)</citetitle>. Tim Bray,
Jean Paoli, C. M. Sperberg-McQueen, et. al.
editors. W3C Recommendation 16 August 2006.</bibliomixed>

<bibliomixed xml:id="xmlns10"><abbrev>Namespaces 1.0</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/REC-xml-names/">Namespaces
in XML 1.0 (Second Edition)</citetitle>. Tim Bray,
Dave Hollander, Andrew Layman, et. al.,
editors. W3C Recommendation 16 August 2006.</bibliomixed>

<bibliomixed xml:id="xml11"><abbrev>XML 1.1</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xml11/">Extensible
Markup Language (XML) 1.1 (Second Edition)</citetitle>. Tim Bray,
Jean Paoli, C. M. Sperberg-McQueen, et. al.
editors. W3C Recommendation 16 August 2006.</bibliomixed>

<bibliomixed xml:id="xmlns11"><abbrev>Namespaces 1.1</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xml-names11/">Namespaces
in XML 1.1 (Second Edition)</citetitle>. Tim Bray,
Dave Hollander, Andrew Layman, et. al.,
editors. W3C Recommendation 16 August 2006.</bibliomixed>

<bibliomixed xml:id="xpath"><abbrev>XPath 1.0</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xpath">XML Path Language (XPath)
Version 1.0</citetitle>. James Clark and Steve DeRose, editors.
W3C Recommendation. 16 November 1999.</bibliomixed>

<bibliomixed xml:id="xslt10"><abbrev>XSLT 1.0</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xslt">XSL Transformations (XSLT)
Version 1.0</citetitle>. James Clark, editor.
W3C Recommendation. 16 November 1999.</bibliomixed>

<bibliomixed xml:id="xpath2"><abbrev>XPath 2.0</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xpath20/">XML Path Language (XPath)
2.0</citetitle>. Anders Berglund, Scott Boag, Don Chamberlin, et. al., editors.
W3C Recommendation. 23 January 2007.</bibliomixed>

<bibliomixed xml:id="xpath-functions"><abbrev>XPath 2.0 Functions and Operators</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xpath-functions/">XQuery 1.0 and
XPath 2.0 Functions and Operators</citetitle>.
Ashok Malhotra, Jim Melton, and Norman Walsh, editors.
W3C Recommendation. 23 January 2007.</bibliomixed>

<bibliomixed xml:id="xslt20"><abbrev>XSLT 2.0</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xslt20/">XSL Transformations (XSLT)
Version 2.0</citetitle>. Michael Kay, editor.
W3C Recommendation. 23 January 2007.</bibliomixed>

<bibliomixed xml:id="xsl11"><abbrev>XSL 1.1</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xsl/">Extensible Stylesheet
Language (XSL) Version 1.1</citetitle>.
Anders Berglund, editor. W3C Recommendation. 5 December 2006.</bibliomixed>

<bibliomixed xml:id="xquery10"><abbrev>XQuery 1.0</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xquery/">XQuery 1.0: An XML
Query Language</citetitle>. Scott Boag, Don Chamberlin, Mary Fernández, et. al.,
editors. W3C Recommendation. 23 January 2007.</bibliomixed>

<bibliomixed xml:id="iso19757-2"><abbrev>RELAX NG</abbrev>ISO/IEC JTC 1/SC 34.
<citetitle>ISO/IEC FDIS 19757-2:2002(E) Document Schema Definition
Languages (DSDL) — Part 2: Grammar-based validation — RELAX NG</citetitle>
2002.
</bibliomixed>

<bibliomixed xml:id="relaxng-dtd-compat"><abbrev>RELAX NG DTD Compatibility</abbrev>
<citetitle>RELAX NG DTD Compatibility</citetitle>.
OASIS Committee Specification.
3 December 2001.
</bibliomixed>

<bibliomixed xml:id="iso19757-3"><abbrev>Schematron</abbrev>ISO/IEC JTC 1/SC 34.
<citetitle>ISO/IEC FDIS 19757-2:2002(E) Document Schema Definition
Languages (DSDL) — Part 3: Rule-based validation — Schematron</citetitle>
2004.
</bibliomixed>

<bibliomixed xml:id="xmlschema-1"><abbrev>W3C XML Schema: Part 1</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xmlschema-1/">XML Schema Part 1:
Structures Second Edition</citetitle>.
Henry S. Thompson, David Beech, Murray Maloney, et. al., editors.
World Wide Web Consortium, 28 October 2004.
</bibliomixed>

<bibliomixed xml:id="xmlschema-2"><abbrev>W3C XML Schema: Part 2</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xmlschema-2/">XML Schema Part 2:
Structures Second Edition</citetitle>.
Paul V. Biron and Ashok Malhotra, editors.
World Wide Web Consortium, 28 October 2004.
</bibliomixed>

<bibliomixed xml:id="xml-id"><abbrev>xml:id</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xml-id/">xml:id
Version 1.0</citetitle>. Jonathan Marsh, Daniel Veillard, and Norman Walsh, editors.
W3C Recommendation. 9 September 2005.</bibliomixed>

<bibliomixed xml:id="xinclude"><abbrev>XInclude</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xinclude/">XML Inclusions
(XInclude) Version 1.0 (Second Edition)</citetitle>. Jonathan Marsh,
David Orchard, and Daniel Veillard, editors.
W3C Recommendation. 15 November 2005.</bibliomixed>

<bibliomixed xml:id="xml-base"><abbrev>XML Base</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xmlbase/">XML Base</citetitle>.
Jonathan Marsh, editor.
W3C Recommendation. 27 June 2001.</bibliomixed>

<bibliomixed xml:id="xptr-framework"><abbrev>XPointer Framework</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xptr-framework/">XPointer Framework</citetitle>.
Paul Grosso, Eve Maler, Jonathan Marsh, et. al., editors.
W3C Recommendation. 25 March 2003.</bibliomixed>

<bibliomixed xml:id="xptr-element"><abbrev>XPointer element() Scheme</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xptr-element/">XPointer element() Scheme</citetitle>.
Paul Grosso, Eve Maler, Jonathan Marsh, et. al., editors.
W3C Recommendation. 25 March 2003.</bibliomixed>

<bibliomixed xml:id="xml-serialization"><abbrev>XML Serialization</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xslt-xquery-serialization/">XSLT 2.0 and XQuery 1.0 Serialization</citetitle>.
 Scott Boag, Michael Kay, Joanne Tong, Norman Walsh, and Henry Zongaro, editors.  W3C Recommendation. 23 January 2007.</bibliomixed>

<bibliomixed xml:id="rfc1521"><abbrev>RFC 1521</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc1521.txt">RFC 1521:
MIME (Multipurpose Internet Mail Extensions) Part One: Mechanisms for
Specifying and Describing the Format of Internet Message
Bodies</citetitle>. N. Borenstein, N. Freed, editors. Internet
Engineering Task Force. September, 2003.</bibliomixed>

<bibliomixed xml:id="rfc2616"><abbrev>RFC 2616</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616:
Hypertext Transfer Protocol — HTTP/1.1</citetitle>.
R. Fielding, J. Gettys, J. Mogul, et. al., editors. Internet
Engineering Task Force. June, 1999.</bibliomixed>

<bibliomixed xml:id="rfc2617"><abbrev>RFC 2617</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc2617.txt">RFC 2617:
HTTP Authentication: Basic and Digest Access Authentication</citetitle>.
J. Franks, P. Hallam-Baker, J. Hostetler, S. Lawrence, P. Leach, A. Luotonen, L. Stewart. June, 1999
.</bibliomixed>

<bibliomixed xml:id="rfc3023"><abbrev>RFC 3023</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc3023.txt">RFC 3023:
XML Media Types</citetitle>.
M. Murata, S. St. Laurent, and D. Kohn, editors. Internet
Engineering Task Force. January, 2001.</bibliomixed>

<bibliomixed xml:id="rfc3548"><abbrev>RFC 3548</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc3548.txt">RFC 3548:
The Base16, Base32, and Base64 Data Encodings</citetitle>.
S. Josefsson, Editor. Internet
Engineering Task Force. July, 2003.</bibliomixed>

<bibliomixed xml:id="rfc3986"><abbrev>RFC 3986</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986:
Uniform Resource Identifier (URI): General Syntax</citetitle>.
T. Berners-Lee, R. Fielding, and L. Masinter, editors.
Internet Engineering Task Force. January, 2005.</bibliomixed>

<bibliomixed xml:id="rfc3987"><abbrev>RFC 3987</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc3987.txt">RFC 3987:
Internationalized Resource Identifiers (URIs)</citetitle>.
M. Duerst and M. Suignard, editors.
Internet Engineering Task Force. January, 2005.</bibliomixed>

<bibliomixed xml:id="media-types"><abbrev>IANA Media Types</abbrev>
<citetitle xlink:href="http://www.iana.org/assignments/media-types/">IANA MIME Media Types</citetitle>. Internet Engineering Task Force.
</bibliomixed>

<bibliomixed xml:id="tidy"><abbrev>HTML Tidy</abbrev>
<citetitle xlink:href="http://tidy.sourceforge.net/">HTML Tidy Library
Project</citetitle>. SourceForge project.
</bibliomixed>

<bibliomixed xml:id="tagsoup"><abbrev>TagSoup</abbrev>
<citetitle xlink:href="http://ccil.org/~cowan/XML/tagsoup/">TagSoup - Just Keep On Truckin'</citetitle>.
John Cowan.
</bibliomixed>

</bibliolist>
</appendix>
<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="app.mimetype">

<title>The XProc Media Type</title>

<para>This appendix registers a new MIME media type,
<quote><code>application/xproc+xml</code></quote>.</para>

<section xml:id="media-type-registration">
<title>Registration of MIME media type application/xproc+xml</title>

<variablelist>
<varlistentry>
<term>MIME media type name:</term>
<listitem>
<para><code>application</code>
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>MIME subtype name:</term>
<listitem>
<para><code>xproc+xml</code>
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Required parameters:</term>
<listitem>
<para>None.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Optional parameters:</term>
<listitem>
  <variablelist>
  <varlistentry>
  <term><code>charset</code></term>
  <listitem>
  <para>This parameter has identical semantics to the <code>charset</code>
parameter of the <code>application/xml</code> media type as
specified in <biblioref linkend="rfc3023"/> or its successors.
</para>
  </listitem>
  </varlistentry>
  </variablelist>
</listitem>
</varlistentry>

<varlistentry>
<term>Encoding considerations:</term>
<listitem>
<para>The XProc syntax is XML; it has the same
considerations when sent as <quote><code>application/xproc+xml</code></quote>
as does XML. See <biblioref linkend="rfc3023"/>, Section 3.2.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Security considerations:</term>
<listitem>
<para>XProc elements may refer to arbitrary URIs.
In this case, the security issues of <biblioref linkend="rfc3986"/>, section 7,
should be considered.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Interoperability considerations:</term>
<listitem>
<para>None.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Published specification:</term>
<listitem>
<para>This media type registration is for XProc documents as described by this
document.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Applications which use this media type:</term>
<listitem>
<para>There is no experimental, vendor specific, or personal tree
predecessor to <quote><code>application/xproc+xml</code></quote>,
reflecting the fact that no applications currently recognize it. This
new type is being registered in order to allow for the
deployment of XProc on the World Wide Web, as a first class XML
application.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Additional information:</term>
<listitem>
  <variablelist>
  <varlistentry>
  <term>Magic number(s):</term>

  <listitem>
  <para>There is no single initial octet sequence that is always present in
XProc documents.
  </para>
  </listitem>
  </varlistentry>

  <varlistentry>
  <term>File extension(s):</term>
  <listitem>
  <para>XProc documents are most often identified with the extension
<quote><filename class="extension">.xpl</filename></quote>.
  </para>
  </listitem>
  </varlistentry>

  <varlistentry>
  <term>Macintosh File Type Code(s):</term>
  <listitem>
  <para>TEXT</para>
  </listitem>
  </varlistentry>
  </variablelist>
</listitem>
</varlistentry>

<varlistentry>
<term>Person &amp; email address to contact for further information:</term>
<listitem>
<para>The XML Processing Model Working Group at the W3C,
<email>public-xml-processing-model-comments@w3.org</email>.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Intended usage:</term>
<listitem>
<para>COMMON</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Author/Change controller:</term>
<listitem>
<para>The XProc specification is a work product of the XML Processing Model
Working Group at the W3C.</para>
</listitem>
</varlistentry>
</variablelist>
</section>

<section xml:id="fragid">
<title>Fragment Identifiers</title>

<para>The fragment identifier notation for documents labeled
<quote><code>application/xproc+xml</code></quote> is an extension of the
<biblioref linkend="xptr-framework"/>.</para>

<orderedlist>
<listitem>
<para>If the fragment identifier is a
<link xlink:href="http://www.w3.org/TR/xptr-framework/#NT-SchemeBased">SchemeBased</link>
pointer, then the semantics are determined by the relevant XPointer scheme.
Only the
<biblioref linkend="xptr-element"/> is mandated by this specification.</para>
</listitem>
<listitem>
<para>If the fragment identifier begins with a slash (“/”) and
consists of one or more slash-separated strings then each string is
interpreted as the name of a step. The first such string identifies the
first step (in document order) with the specified name. The second and subsequent
strings, if present, identify the first step with the specified name within the
descendants of the currently identified step. If no step is identified by
the sequence of names, the pointer is in error.</para>
<para>For the purposes of pointer resolution, the
<link linkend="step-names">defaulted names</link>
<rfc2119>must</rfc2119> be supported.</para>
</listitem>
<listitem>
<para>If the fragment identifier is a
<link xlink:href="http://www.w3.org/TR/xptr-framework/#NT-Shorthand">Shorthand</link>
pointer, then it has the semantics of an 
<biblioref linkend="xptr-framework"/> shorthand pointer.</para>
</listitem>
<listitem>
<para>Any other pointer is in error.</para>
</listitem>
</orderedlist>

</section>
</appendix>
<appendix xmlns:db="http://docbook.org/ns/docbook" xmlns="http://docbook.org/ns/docbook" xml:id="glossary"><title>Glossary</title><glosslist><glossentry><glossterm>Namespaces in XML</glossterm><glossdef><para>Unless otherwise noted, the term
<firstterm>Namespaces in XML</firstterm> refers equally to
<biblioref linkend="xmlns10"/> and <biblioref linkend="xmlns11"/>.</para></glossdef></glossentry><glossentry><glossterm>QName</glossterm><glossdef><para>In the context of XProc, a
<firstterm>QName</firstterm> is almost always a QName in the
<glossterm>Namespaces in XML</glossterm> sense.
Note, however, that <tag>p:option</tag> and
<tag>p:parameter</tag> values can get their namespace declarations in
a non-standard way (with <tag>p:namespaces</tag>) and QNames that have
no prefix are always in no-namespace, irrespective of the default
namespace.</para></glossdef></glossentry><glossentry><glossterm>XML</glossterm><glossdef><para>XProc is intended to work equally
well with <biblioref linkend="xml10"/> and <biblioref linkend="xml11"/>.
Unless otherwise noted, the term “<firstterm>XML</firstterm>”
refers equally to both versions.</para></glossdef></glossentry><glossentry><glossterm>atomic step</glossterm><glossdef><para>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.</para></glossdef></glossentry><glossentry><glossterm>binding</glossterm><glossdef><para>A <firstterm>binding</firstterm> associates an input
or output port with some data source.</para></glossdef></glossentry><glossentry><glossterm>by URI</glossterm><glossdef><para>A document is specified
<firstterm>by URI</firstterm> if it is referenced with a URI.</para></glossdef></glossentry><glossentry><glossterm>by source</glossterm><glossdef><para>A document is specified
<firstterm>by source</firstterm> if it references a specific port
on another step.</para></glossdef></glossentry><glossentry><glossterm>compound
step</glossterm><glossdef><para>A <firstterm>compound
step</firstterm> is a step that contains one or more <glossterm baseform="subpipeline">subpipelines</glossterm>. That is, a compound
step differs from an atomic step in that its semantics are at least
partially determined by the steps that it contains.</para></glossdef></glossentry><glossentry><glossterm>contained
steps</glossterm><glossdef><para>The steps that occur directly inside a
compound step are called <firstterm>contained
steps</firstterm>.</para></glossdef></glossentry><glossentry><glossterm>container</glossterm><glossdef><para>A compound
step which immediately contains another step is called its
<firstterm>container</firstterm>.</para></glossdef></glossentry><glossentry><glossterm>declared inputs</glossterm><glossdef><para>The input ports declared on
a step are its <firstterm>declared inputs</firstterm>.</para></glossdef></glossentry><glossentry><glossterm>declared options</glossterm><glossdef><para>The options declared on a
step are its <firstterm>declared options</firstterm>.</para></glossdef></glossentry><glossentry><glossterm>declared outputs</glossterm><glossdef><para>The output ports declared on a
step are its <firstterm>declared outputs</firstterm>.</para></glossdef></glossentry><glossentry><glossterm>default readable port</glossterm><glossdef><para>The <firstterm>default readable port</firstterm>,
which may be undefined, is a specific step name/port name pair from the set of readable
ports.</para></glossdef></glossentry><glossentry><glossterm>dynamic
error</glossterm><glossdef><para>A <firstterm>dynamic
error</firstterm> is one which occurs while a pipeline is being
evaluated.</para></glossdef></glossentry><glossentry><glossterm>empty environment</glossterm><glossdef><para>The
<firstterm>empty environment</firstterm> contains no readable ports,
no in-scope options, and an undefined default readable port.
</para></glossdef></glossentry><glossentry><glossterm>empty sequence</glossterm><glossdef><para>An
<firstterm>empty sequence</firstterm> of documents is specified with the
<tag>p:empty</tag> element.</para></glossdef></glossentry><glossentry><glossterm>environment</glossterm><glossdef><para>The
<firstterm>environment</firstterm> of a step is the information
available to each instance of a step in a pipeline.</para></glossdef></glossentry><glossentry><glossterm>expanded
pipeline name</glossterm><glossdef><para>The <firstterm>expanded
pipeline name</firstterm> of a pipeline is the expanded name denoted by its
type, if it has one, otherwise the expanded name specified by the
namespace of its containing pipeline-library and its name.</para></glossdef></glossentry><glossentry><glossterm>extension
element</glossterm><glossdef><para>An <firstterm>extension
element</firstterm> is any element that is not in the XProc namespace
and is not a step.</para></glossdef></glossentry><glossentry><glossterm>extension attribute</glossterm><glossdef><para>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>.</para></glossdef></glossentry><glossentry><glossterm>ignorable element</glossterm><glossdef><para>Any element in an ignored namespace
is an <firstterm>ignorable element</firstterm>.</para></glossdef></glossentry><glossentry><glossterm>implementation-defined</glossterm><glossdef><para>An
<firstterm>implementation-defined</firstterm> feature is one where the
implementation has discretion in how it is performed.
Conformant implementations <rfc2119>must</rfc2119> document
how <glossterm role="unwrapped">implementation-defined</glossterm> features are performed.</para></glossdef></glossentry><glossentry><glossterm>implementation-dependent</glossterm><glossdef><para>An
<firstterm>implementation-dependent</firstterm> feature is one where the
implementation has discretion in how it is performed.
Implementations are not required to document or explain
how <glossterm role="unwrapped">implementation-dependent</glossterm> features are performed.</para></glossdef></glossentry><glossentry><glossterm>in-scope options</glossterm><glossdef><para>The
<firstterm>in-scope options</firstterm> are the set of options that
are visible to a step.</para></glossdef></glossentry><glossentry><glossterm>inherited
environment</glossterm><glossdef><para>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>.
</para></glossdef></glossentry><glossentry><glossterm>inline document</glossterm><glossdef><para>An
<firstterm>inline document</firstterm> is specified directly in
the body of the element that binds it.</para></glossdef></glossentry><glossentry><glossterm>last step</glossterm><glossdef><para>The <firstterm>last step</firstterm> in a
subpipeline is the last step in document order within its container.
</para></glossdef></glossentry><glossentry><glossterm>matches</glossterm><glossdef><para>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.</para></glossdef></glossentry><glossentry><glossterm>namespace
fixup</glossterm><glossdef><para>To produce a serializable
<glossterm>XML</glossterm> document, the XProc processor must
sometimes add additional namespace nodes, perhaps even renaming
prefixes, to satisfy the constraints of <glossterm>Namespaces in
XML</glossterm>. This process is referred to as <firstterm>namespace
fixup</firstterm>.</para></glossdef></glossentry><glossentry><glossterm>option</glossterm><glossdef><para>An <firstterm>option</firstterm> is
a name/value pair where the name is an
<link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.w3.org/TR/REC-xml-names/#dt-expname">expanded name</link>
and the value <rfc2119>must</rfc2119> be a string.</para></glossdef></glossentry><glossentry><glossterm>parameter</glossterm><glossdef><para>A <firstterm>parameter</firstterm> is
a name/value pair where the name is an
<link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.w3.org/TR/REC-xml-names/#dt-expname">expanded name</link>
and the value <rfc2119>must</rfc2119> be a string.</para></glossdef></glossentry><glossentry><glossterm>parameter input port</glossterm><glossdef><para>A
<firstterm>parameter input port</firstterm> is a distinguished kind of
input port which accepts (only) dynamically constructed parameter name/value
pairs.</para></glossdef></glossentry><glossentry><glossterm>pipeline</glossterm><glossdef><para>A <firstterm>pipeline</firstterm>
is a set of connected steps, with outputs of one step flowing
into inputs of another.</para></glossdef></glossentry><glossentry><glossterm>primary input port</glossterm><glossdef><para>If a step has a document input
port which is explicitly marked “<code>primary='true'</code>”, or if it has
exactly one document input port and that port is <emphasis>not</emphasis>
explicitly marked “<code>primary='false'</code>”, then that input port
is the <firstterm>primary input port</firstterm> of the step.</para></glossdef></glossentry><glossentry><glossterm>primary output port</glossterm><glossdef><para>If a step has a document output
port which is explicitly marked “<code>primary='true'</code>”, or if it has
exactly one document output port and that port is <emphasis>not</emphasis>
explicitly marked “<code>primary='false'</code>”, then that output port
is the <firstterm>primary output port</firstterm> of the step.</para></glossdef></glossentry><glossentry><glossterm>primary parameter input port</glossterm><glossdef><para>If a step has
a parameter input port which is explicitly marked “<code>primary='true'</code>”,
or if it has exactly one parameter input port and that port is
<emphasis>not</emphasis> explicitly marked “<code>primary='false'</code>”, then
that parameter input port is the <firstterm>primary parameter input port</firstterm>
of the step.</para></glossdef></glossentry><glossentry><glossterm>readable ports</glossterm><glossdef><para>The
<firstterm>readable ports</firstterm> are the step name/port name
pairs that are visible to the step.</para></glossdef></glossentry><glossentry><glossterm>signature</glossterm><glossdef><para>The
<firstterm>signature</firstterm> of a step is the set of inputs,
outputs, and options that it is declared to accept.</para></glossdef></glossentry><glossentry><glossterm>specified options</glossterm><glossdef><para>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>.</para></glossdef></glossentry><glossentry><glossterm>static
error</glossterm><glossdef><para>A <firstterm>static
error</firstterm> is one which can be detected before pipeline evaluation
is even attempted.</para></glossdef></glossentry><glossentry><glossterm>step</glossterm><glossdef><para>A <firstterm>step</firstterm> is the
basic computational unit of a pipeline.</para></glossdef></glossentry><glossentry><glossterm>subpipeline</glossterm><glossdef><para>The steps (and the
connections between them) within a compound step form a
<firstterm>subpipeline</firstterm>.</para></glossdef></glossentry></glosslist></appendix>

<appendix xml:id="language-summary">
<title>Pipeline Language Summary</title>

<para>This appendix summarizes the XProc pipeline language. Machine readable
descriptions of this language are available in
<link xlink:href="schemas/xproc.rng">RELAX NG</link> (and the
RELAX NG 
<link xlink:href="schemas/xproc.rnc">compact syntax</link>),
<link xlink:href="schemas/xproc.xsd">W3C XML Schema</link>,
and 
<link xlink:href="schemas/xproc.dtd">DTD</link> syntaxes.</para>

<?syntax-summary?>

<para>The core steps are also summarized here.</para>

<?required-step-summary?>

<para>As are the optional steps.</para>

<?optional-step-summary?>

<para>And the step vocabulary elements.</para>

<?step-vocabulary-summary?>

</appendix>

<appendix xml:id="namespace-fixup-guidance">
<title>Guidance on Namespace Fixup (Non-Normative)</title>

<para>An XProc processor may find it necessary to add missing
namespace declarations to ensure that a document can be serialized.
While this process is implementation defined, the purpose of this
appendix is to provide guidance as to what an implementation might do
to either prevent such situations or fix them as before
serialization.</para>

<para>When a namespace binding is generated, the prefix associated
with the QName of the element or attribute in question should be used.
From an infoset perspective, this is accomplished by setting the
<code>[prefix]</code> on the element or attribute. Then when an
implementation needs to add a namespace binding, it can reuse that
prefix if possible. If reusing the prefix is not possible, the
implementation must generate a new prefix that is unique to the
in-scope namespace of the element or owner element of the
attribute.</para>

<para>An implementation can avoid namespace fixup by making sure that
the standard step library does not output documents that require
fixup. The following list contains suggestions as to how to accomplish
this within the steps:</para>

<orderedlist>

<listitem>
<para>Any step that outputs an element in the step vocabulary namespace <uri type="xmlnamespace">http://www.w3.org/ns/xproc-step</uri> must ensure that namespace is declared.  An implementation should generate a namespace binding using the prefix “<literal>c</literal>”.</para>
</listitem>

<listitem>
<para>When attributes are added by <link linkend="c.add-attribute">p:add-attribute</link> or 
<link linkend="c.set-attributes">p:set-attributes</link>, the step must ensure the namespace of the 
attributes added are declared.  If the prefix used by the QName is not in the in-scope namespaces 
of the element on which the attribute was added, the step must add a namespace declaration of the 
prefix to the in-scope namespaces.  If the prefix is amongst the in-scope namespace and is not bound 
to the same namespace name, a new prefix and namespace binding must be added.  When a new prefix is 
generated, the prefix associated with the attribute should be changed to reflect that generated prefix value.
</para>
</listitem>

<listitem>
<para>When an element is renamed by <link linkend="c.rename">p:rename</link>, the step must ensure the
namespace of the element is declared.  If the prefix used by the QName is not in the in-scope namespaces 
of the element being renamed, the step must add a namespace declaration of the prefix to the in-scope 
namespaces. If the prefix is amongst the in-scope namespace and is not bound to the same namespace name, 
a new prefix and namespace binding must be added.  When a new prefix is generated, the prefix associated
with the element should be changed to reflect that generated prefix value.
</para>
<para>If the element does not have a namespace name and there is a default namespace, the default namespace
must be undeclared.  For each of the child elements, the original default
namespace declaration must be preserved by adding a default namespace declaration unless the child element 
has a different default namespace.</para>
</listitem>

<listitem>
<para>When an attribute is renamed by <link linkend="c.rename">p:rename</link>, 
 the step must ensure the namespace of the renamed attribute is declared.  If the prefix used by the
 QName is not in the in-scope namespaces of the element on which the attribute was added, the step
 must add a namespace declaration of the prefix to the in-scope namespaces. If the prefix is amongst the 
 in-scope namespace and is not bound to the same namespace name, a new prefix and namespace binding must be 
 added.  When a new prefix is generated, the prefix associated with the attribute should be changed to
 reflect that generated prefix value.
</para>
</listitem>

<listitem>
<para>When an element wraps content via <link linkend="c.wrap">p:wrap</link>, there may be in-scope
namespaces coming from ancestor elements of the new wrapper element.  The step must ensure the
namespace of the element is declared properly.  By default, the wrapper element will inherit the
in-scope namespaces of the parent element if one exists.  As such, there may be a existing namespace
declaration or default namespace.</para>
<para>If the prefix used by the QName is not in the in-scope namespaces 
of the wrapper element, the step must add a namespace declaration of the prefix to the in-scope 
namespaces. If the prefix is amongst the in-scope namespace and is not bound to the same namespace name, 
a new prefix and namespace binding must be added.  When a new prefix is generated, the prefix associated
with the wrapper element should be changed to reflect that generated prefix value.
</para>
<para>If the element does not have a namespace name and there is a default namespace, the default namespace
must be undeclared.  For each of the child elements, the original default namespace declaration must be
preserved by adding a default namespace declaration unless the child element has a different default 
namespace.</para>
</listitem>

<listitem>
<para>When the wrapper element is added for <link linkend="c.wrap-sequence">p:wrap-sequence</link> or 
<link linkend="c.pack">p:pack</link>, the prefix used by the QName must be added to the
 in-scope namespaces.</para>
</listitem>

<listitem>
<para>When a element is removed via <link linkend="c.unwrap">p:unwrap</link>, an in-scope namespaces that 
are declared on the element must be copied to any child element except when the child element declares 
the same prefix or declares a new default namespace.</para>
</listitem>

<listitem>
<para>In the output from <link linkend="c.xslt">p:xslt</link>, if an element was generated from the xsl:element or an
 attribute from xsl:attribute, the step must guarantee that an namespace declaration exists for the namespace name 
 used.  Depending on the XSLT implementation, the namespace declaration for the namespace name of the
 element or attribute may not be declared.  It may also be the case that the original prefix is available.  
 If the original prefix is available, the step should attempt to re-use that prefix.  Otherwise, it must 
 generate a prefix for a namespace binding and change the prefix associated the element or attribute.</para>
</listitem>

</orderedlist>

</appendix>

</specification>
