<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE specification [
<!ENTITY serialization-options '<p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="byte-order-mark" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="cdata-section-elements" select="&apos;&apos;" e:type="ListOfQNames"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="doctype-public" e:type="xsd:string"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="doctype-system" e:type="xsd:anyURI"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="encoding" e:type="xsd:string"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="escape-uri-attributes" select="&apos;false&apos;" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="include-content-type" select="&apos;true&apos;" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="indent" select="&apos;false&apos;" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="media-type" e:type="xsd:string"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="method" select="&apos;xml&apos;" e:type="xsd:QName"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="normalization-form" select="&apos;none&apos;" e:type="NormalizationForm"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="omit-xml-declaration" select="&apos;true&apos;" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="standalone" select="&apos;omit&apos;" e:type="true|false|omit"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="undeclare-prefixes" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="version" select="&apos;1.0&apos;" e:type="xsd:string"/>'>
<!ENTITY serialization-options-for-escape-markup '<p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="cdata-section-elements" select="&apos;&apos;" e:type="ListOfQNames"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="doctype-public" e:type="xsd:string"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="doctype-system" e:type="xsd:anyURI"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="escape-uri-attributes" select="&apos;false&apos;" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="include-content-type" select="&apos;true&apos;" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="indent" select="&apos;false&apos;" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="media-type" e:type="xsd:string"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="method" select="&apos;xml&apos;" e:type="xsd:QName"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="omit-xml-declaration" select="&apos;true&apos;" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="standalone" select="&apos;omit&apos;" e:type="true|false|omit"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="undeclare-prefixes" e:type="xsd:boolean"/>
  <p:option xmlns:p="http://www.w3.org/ns/xproc" xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" name="version" select="&apos;1.0&apos;" e:type="xsd:string"/>'>
]>
<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="rec" version="5.0-extension w3c-xproc">
  <info><title>XProc: An XML Pipeline Language</title>
    <w3c-shortname>xproc</w3c-shortname>
    <pubdate>2010-05-11</pubdate>
    <bibliorelation role="errata" type="references" xlink:href="http://www.w3.org/XML/2010/xproc-errata.html">errata</bibliorelation>
    <bibliorelation role="translations" type="references" xlink:href="http://www.w3.org/2003/03/Translations/byTechnology?technology=xproc">translations</bibliorelation>
    <bibliorelation type="isformatof" xlink:href="langspec.xml">XML</bibliorelation>
<!--
    <bibliorelation type="isformatof" xlink:href="diff.html">Revision markup</bibliorelation>
-->
    <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2010/PR-xproc-20100309/"/>
    <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2010/WD-xproc-20100105/"/>
    <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2009/CR-xproc-20090528/"/>
    <!--
    <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2008/CR-xproc-20081126/"/>
    <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2008/WD-xproc-20080814/"/>
      <bibliorelation type="replaces" xlink:href="http://www.w3.org/TR/2007/WD-xproc-20071129/"/>
      <bibliorelation type="replaces"
		xlink:href="http://www.w3.org/TR/2007/WD-xproc-20070920/"/>
<bibliorelation type="replaces"
		xlink:href="http://www.w3.org/TR/2007/WD-xproc-20070706/"/>
<bibliorelation type="replaces"
		xlink:href="http://www.w3.org/TR/2007/WD-xproc-20070405/"/>
<bibliorelation type="replaces"
		xlink:href="http://www.w3.org/TR/2006/WD-xproc-20061117/"/>
-->
    <authorgroup>
      <author>
        <personname>Norman Walsh</personname>
        <affiliation>
          <orgname>MarkLogic Corporation</orgname>
        </affiliation>
        <email>norman.walsh@marklogic.com</email>
      </author>
      <author>
        <personname>Alex Milowski</personname>
        <affiliation>
          <orgname>Invited expert</orgname>
        </affiliation>
        <email>alex@milowski.org</email>
      </author>
      <author>
        <personname>Henry S. Thompson</personname>
        <affiliation>
          <orgname>University of Edinburgh</orgname>
        </affiliation>
        <email>ht@inf.ed.ac.uk</email>
      </author>
    </authorgroup>

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

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

<legalnotice role="status">

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

<para>This document is a
<link xlink:href="http://www.w3.org/2005/10/Process-20051014/tr.html#q74">W3C
Recommendation</link>. It implements the requirements and use cases
documented in <biblioref linkend="use-cases"/>. This document is a
product of the
<link xlink:href="http://www.w3.org/XML/Processing/">XML Processing Model
Working Group</link>
as part of the W3C
<link xlink:href="http://www.w3.org/XML/Activity">XML Activity</link>.
</para>

<para>This document has been reviewed by W3C Members, by software
developers, and by other W3C groups and interested parties, and is
endorsed by the Director as a W3C Recommendation. It is a stable
document and may be used as reference material or cited from another
document. W3C's role in making the Recommendation is to draw attention
to the specification and to promote its widespread deployment. This
enhances the functionality and interoperability of the Web.</para>

<para>Please report errors in this document to the public
mailing list
<link xlink:href="mailto:public-xml-processing-model-comments@w3.org">public-xml-processing-model-comments@w3.org</link> (public
<link xlink:href="http://lists.w3.org/Archives/Public/public-xml-processing-model-comments/">archives</link> are available).</para>

<para>There is an
<link xlink:href="http://www.w3.org/XML/XProc/2010/02/ir.html">Implementation
Report for XProc</link>. It documents the performance of implementations
against the
<link xlink:href="http://tests.xproc.org/">XProc Test Suite</link>.
</para>

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

</legalnotice>
</info>

<section xml:id="introduction">
    <title>Introduction</title>
    <para>An XML Pipeline specifies a sequence of operations to be performed on a collection of XML
      input documents. Pipelines take zero or more XML documents as their input and produce zero or
      more XML documents as their output.</para>
    <para>A <glossterm>pipeline</glossterm> consists of steps. Like pipelines, steps take zero or
      more XML documents as their inputs and produce zero or more XML documents as their outputs.
      The inputs of a step come from the web, from the pipeline document, from the inputs to the
      pipeline itself, or from the outputs of other steps in the pipeline. The outputs from a step
      are consumed by other steps, are outputs of the pipeline as a whole, or are discarded.</para>
    <para>There are three kinds of steps: atomic steps, compound steps, and multi-container steps.
      Atomic steps carry out single operations and have no substructure as far as the pipeline is
      concerned. Compound steps and multi-container steps control the execution of other steps,
      which they include in the form of one or more subpipelines.</para>
    <para>This specification defines a standard library, <xref linkend="std-components"/>, of steps.
      Pipeline implementations <rfc2119>may</rfc2119> support additional types of steps as well. </para>
    <para><xref linkend="fig-xival"/> is a graphical representation of a simple pipeline that
      performs XInclude processing and validation on a document.</para>
    <figure xml:id="fig-xival">
      <title>A simple, linear XInclude/Validate pipeline</title>
      <mediaobject>
        <alt>A simple, linear XInclude/Validate pipeline</alt>
        <imageobject>
          <imagedata fileref="graphics/sch-xinclude-validate-pipeline.png"/>
        </imageobject>
      </mediaobject>
    </figure>
    <para>This is a pipeline that consists of two atomic steps, XInclude and Validate with XML
      Schema. The pipeline itself has two inputs, “source” (a source document) and “schemas” (a
      sequence of W3C XML Schemas). The XInclude step reads the pipeline input “source” and produces
      a result document. The Validate with XML Schema step reads the pipeline input “schemas” and
      the result of the XInclude step and produces its own result document. The result of the
      validation, “result”, is the result of the pipeline. (For consistency across the step
      vocabulary, the standard input is usually named “source” and and the standard output is
      usually named “result”.) </para>
    <para>The pipeline document determines how the steps are connected together inside the pipeline,
      that is, how the output of one step becomes the input of another.</para>
    <para>The pipeline document for this pipeline is shown in <xref linkend="ex1"/>.</para>
    <example xml:id="ex1">
      <title>A simple, linear XInclude/Validate pipeline</title>
      <programlisting>&lt;p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
		name="xinclude-and-validate"
		version="1.0"&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="xinclude-and-validate" 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="xinclude-and-validate" port="schemas"/&gt;
    &lt;/p:input&gt;
  &lt;/p:validate-with-xml-schema&gt;
&lt;/p:declare-step&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:</para>
    <itemizedlist>
      <listitem>
        <para>If you use <tag>p:pipeline</tag> instead of <tag>p:declare-step</tag>, the
            “<port>source</port>” input port and “<port>result</port>” output port are implicitly
          declared for you.</para>
      </listitem>
      <listitem>
        <para>Where inputs and outputs are connected between sequential sibling steps, they do not
          have to be made explicit.</para>
      </listitem>
    </itemizedlist>
    <para>The same pipeline, using XProc defaults, is shown in <xref linkend="ex1-abbr"/>.</para>
    <example xml:id="ex1-abbr">
      <title>A simple, linear XInclude/Validate pipeline (simplified)</title>
      <programlisting>&lt;p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
	    name="xinclude-and-validate"
	    version="1.0"&gt;
  &lt;p:input port="schemas" sequence="true"/&gt;

  &lt;p:xinclude/&gt;

  &lt;p:validate-with-xml-schema&gt;
    &lt;p:input port="schema"&gt;
      &lt;p:pipe step="xinclude-and-validate" 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" version="1.0"&gt;

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

  &lt;p:xslt&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>
    <para>The media type for pipeline documents is <literal>application/xml</literal>. Often,
      pipeline documents are identified by the extension <filename class="extension">.xpl</filename>.</para>
    <para>In this specification the words <rfc2119>must</rfc2119>, <rfc2119>must not</rfc2119>,
        <rfc2119>should</rfc2119>, <rfc2119>should not</rfc2119>, <rfc2119>may</rfc2119> and
        <rfc2119>recommended</rfc2119> are to be interpreted as described in <biblioref linkend="rfc2119"/>.</para>
  </section>

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

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

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

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

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

&lt;p:split-sequence name="select-chapters" test="@role='chapter'"&gt;
  &lt;p:input port="source" select="//section"/&gt;
&lt;/p:split-sequence&gt;
</programlisting>
      <para>The select expression on the variable “<varname>home</varname>” is evaluated by the
        XProc processor. The value of the variable is “<uri>http://example.com/docs</uri>”.</para>
      <para>The <option>href</option> option of the <tag>p:load</tag> step is evaluated by the XProc
        processor. The actual <literal>href</literal> option received by the step is simply the
        string literal “<uri>http://example.com/docs/document.xml</uri>”. (The select expression on
        the <literal>source</literal> input of the <tag>p:split-sequence</tag> step is also
        evaluated by the XProc processor.) </para>
      <para>The XPath expression “<literal>@role='chapter'</literal>” is passed literally to the
          <literal>test</literal> option on the <tag>p:split-sequence</tag> step. That's because the
        nature of the <tag>p:split-sequence</tag> is that <emphasis>it evaluates</emphasis> the
        expression. Only some options on some steps expect XPath expressions. </para>
      <para>The XProc processor evaluates all of the XPath expressions in <tag class="attribute">select</tag> attributes on variables, options, parameters, and inputs, in <tag class="attribute">match</tag> attributes on <tag>p:viewport</tag>, and in <tag class="attribute">test</tag> attributes on <tag>p:when</tag> steps.</para>
      <para>An XProc implementation can use <emphasis>either</emphasis>
        <biblioref linkend="xpath"/> or <biblioref linkend="xpath2"/> to evaluate these
        expressions.</para>
      <note>
        <para>Allowing either XPath 1.0 or XPath 2.0 is a compromise driven entirely by the timing
          of XProc development. During the development of this specification, the community
          indicated that it was too early to mandate that all implementations use XPath 2.0 and too
          late to mandate that all implementations use XPath 1.0.</para>
      </note>
      <para>Many, many expressions that are likely to be used in XProc pipelines are the same in
        both versions (simple element tests, ancestor and descendant tests, string-based attribute
        tests, etc.).</para>
      <para>As an aid to interoperability, pipeline authors may indicate the version of XPath that
        they require. The attribute <tag class="attribute">xpath-version</tag> may be used on
          <tag>p:pipeline</tag>, <tag>p:declare-step</tag>, or <tag>p:library</tag> to identify the
        XPath version that <rfc2119>must</rfc2119> be used to evaluate XPath expressions on the
        pipeline(s). The attribute is lexically scoped, but see below.</para>

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

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

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

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

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

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

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

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


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

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

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

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

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

<programlisting>&lt;p:declare-step type="ex:dir-list"&gt;
  &lt;p:output port="result"/&gt;
  &lt;p:option name="path"/&gt;

  &lt;p:choose&gt;
    &lt;p:when test="p:value-available('path')"&gt;
      &lt;p:directory-list&gt;
	&lt;p:with-option name="path" select="$path"/&gt;
      &lt;/p:directory-list&gt;
    &lt;/p:when&gt;
    &lt;p:otherwise&gt;
      &lt;p:directory-list path="."/&gt;
    &lt;/p:otherwise&gt;
  &lt;/p:choose&gt;
&lt;/p:declare-step&gt;
</programlisting>

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

</section>

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

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

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

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

</section>

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

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

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

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

</section>

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

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

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

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

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

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

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

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

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

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

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

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

</section>

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

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

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

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

</section>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  <p:sink/>

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

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

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

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

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

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

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

<para>Parameter names are not scoped; they are distinct on each step.</para>
</section>
    <section xml:id="xml-base-attribute">
      <title>Base URIs and xml:base</title>
      <para>When a relative URI appears in an option value, the base URI against which it
          <rfc2119>must</rfc2119> be made absolute is the base URI of the <tag>p:option</tag>
        element. If an option value is specified using a <link linkend="option-shortcut">syntactic
          shortcut</link>, the base URI of the step on which the shortcut attribute appears
          <rfc2119>must</rfc2119> be used. In general, whenever a relative URI appears, its base URI
        is the base URI of the nearest ancestor element.</para>
      <para>The pipeline author can control the base URIs of elements within the pipeline document
        with the <tag class="attribute">xml:base</tag> attribute. The <tag class="attribute">xml:base</tag> attribute <rfc2119>may</rfc2119> appear on any element in a pipeline and
        has the semantics outlined in <biblioref linkend="xml-base"/>.</para>
    </section>
    <section xml:id="xml-id-attribute">
      <title>Unique identifiers</title>
      <para>A pipeline author can provide a globally unique identifier for any element in a pipeline
        with the <tag class="attribute">xml:id</tag> attribute.</para>
      <para>The <tag class="attribute">xml:id</tag> attribute <rfc2119>may</rfc2119> appear on any
        element in a pipeline and has the semantics outlined in <biblioref linkend="xml-id"/>.</para>
    </section>
    <section xml:id="syntax-docs-ports">
      <title>Associating Documents with Ports</title>
      <para><termdef xml:id="dt-connection">A <firstterm>connection</firstterm> associates an input
          or output port with some data source.</termdef> A document or a sequence of documents can
        be connected to a port in four ways: <glossterm>by source</glossterm>, <glossterm>by
          URI</glossterm>, by providing an <glossterm>inline document</glossterm>, or by making it
          <glossterm baseform="empty-sequence">explicitly empty</glossterm>. Each of these
        mechanisms is allowed on the <tag>p:input</tag>, <tag>p:output</tag>,
          <tag>p:xpath-context</tag>, <tag>p:iteration-source</tag>, and
          <tag>p:viewport-source</tag> elements.</para>
      <variablelist>
        <varlistentry>
          <term>Specified by URI</term>
          <listitem>
            <para><termdef xml:id="dt-by-URI">A document is specified <firstterm>by URI</firstterm>
                if it is referenced with a URI.</termdef> The <tag class="attribute">href</tag>
              attribute on the <tag>p:document</tag> or <tag>p:data</tag> element is used to refer
              to documents by URI.</para>
            <para>In this example, the input to the <tag>p:identity</tag> step named
                “<literal>otherstep</literal>” comes from “<uri>http://example.com/input.xml</uri>”. </para>
            <programlisting>&lt;p:output port="result"/&gt;

&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>
          </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>See the description of <tag>p:pipe</tag> for a complete description of the ports
              that can be connected.</para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>Specified inline</term>
          <listitem>
            <para><termdef xml:id="dt-inline-document">An <firstterm>inline document</firstterm> is
                specified directly in the body of the element to which it connects.</termdef> The
              content of the <tag>p:inline</tag> element is used for this purpose. </para>
            <para>In this example, the “<literal>stylesheet</literal>” input to the XSLT step named
                “<literal>xform</literal>” comes from the content of the <tag>p:input</tag> element
              itself.</para>
            <programlisting>&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 other
              namespaces that would have other semantics outside of the <tag>p:inline</tag>.</para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>Specified explicitly empty</term>
          <listitem>
            <para><termdef xml:id="dt-empty-sequence">An <firstterm>empty sequence</firstterm> of
                documents is specified with the <tag>p:empty</tag> element.</termdef>
            </para>
            <para>In this example, the “<literal>source</literal>” input to the XSLT 2.0 step named
                “<literal>generate</literal>” is explicitly empty:</para>
            <programlisting>&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:with-option name="template-name" select="'someName'"/&gt;
&lt;/p:xslt&gt;
</programlisting>
            <para>If you omit the connection on a primary input port, a connection to the
                <glossterm>default readable port</glossterm> will be assumed. Making the connection
              explicitly empty guarantees that the connection will be to an empty sequence of
              documents.</para>
            <para xml:id="empty-xpath-context">It is inconsistent with the <biblioref linkend="xpath"/> specification to specify an empty connection as the context for
              evaluating an XPath expression. When an empty connection is specified for an XPath 1.0
              expression, an empty document node <rfc2119>must</rfc2119> be used instead as the
              context node.</para>
          </listitem>
        </varlistentry>
      </variablelist>
      <para>Note that a <tag>p:input</tag> or <tag>p:output</tag> element may contain more than one
          <tag>p:pipe</tag>, <tag>p:document</tag>, <tag>p:data</tag>, or <tag>p:inline</tag>
        element. If more than one <glossterm>connection</glossterm> is provided, then the specified
        sequence of documents is made available on that port in the same order as the
        connections.</para>
    </section>
    <section xml:id="documentation">
      <title>Documentation</title>
      <para>Pipeline authors may add documentation to their pipeline documents with the
          <tag>p:documentation</tag> element. Except when it appears as a descendant of
          <tag>p:inline</tag>, the <tag>p:documentation</tag> element is completely ignored by
        pipeline processors, it exists simply for documentation purposes. If a
          <tag>p:documentation</tag> is provided as a descendant of <tag>p:inline</tag>, it has no
        special semantics, it is treated literally as part of the document to be provided on that
        port. The <tag>p:documentation</tag> element has no special semantics when it appears in
        documents that flow through the pipeline.</para>
      <para>Pipeline processors that inspect the contents of <tag>p:documentation</tag> elements and
        behave differently on the basis of what they find are <emphasis>not conformant</emphasis>.
        Processor extensions <rfc2119>must</rfc2119> be specified with <tag>p:pipeinfo</tag>.</para>
    </section>
    <section xml:id="annotations">
      <title>Processor annotations</title>
      <para>Pipeline authors may add annotations to their pipeline documents with the
          <tag>p:pipeinfo</tag> element. <impl>The semantics of <tag>p:pipeinfo</tag> elements are
            <glossterm>implementation-defined</glossterm>.</impl> Processors
          <rfc2119>should</rfc2119> specify a way for their annotations to be identified, perhaps
        with <link linkend="extension-attributes">extension attributes</link>.</para>
      <para>Where <tag>p:documentation</tag> is intended for human consumption,
          <tag>p:pipeinfo</tag> elements are intended for processor consumption. A processor might,
        for example, use annotations to identify some particular aspect of an implementation, to
        request additional, perhaps non-standard features, to describe parallelism constraints,
        etc.</para>
      <para>When a <tag>p:pipeinfo</tag> appears as a descendant of <tag>p:inline</tag>, it has no
        special semantics; in that context it <rfc2119>must</rfc2119> be treated literally as part
        of the document to be provided on that port. The <tag>p:pipeinfo</tag> element has no
        special semantics when it appears in documents that flow through the pipeline. </para>
    </section>
    <section xml:id="extension-attributes">
      <title>Extension attributes</title>
      <para><termdef xml:id="dt-extension-attribute">An element from the XProc namespace
            <rfc2119>may</rfc2119> have any attribute not from the XProc namespace, provided that
          the expanded-QName of the attribute has a non-null namespace URI. Such an attribute is
          called an <firstterm>extension attribute</firstterm>.</termdef>
      </para>
      <para>The presence of an extension attribute must not cause the connections between steps to
        differ from the connections that would arise in the absence of the attribute. They must not
        cause the processor to fail to signal an error that would be signaled in the absence of the
        attribute.</para>
      <para>A processor which encounters an extension attribute that it does not implement
          <rfc2119>must</rfc2119> behave as if the attribute was not present.</para>
    </section>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<programlisting>&lt;p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="1.0"&gt;
&lt;p:input port="source"/&gt;
&lt;p:output port="result"/&gt;

&lt;p:xslt&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:document href="http://example.com/stylesheets/doc.xsl"/&gt;
  &lt;/p:input&gt;
&lt;/p:xslt&gt;

&lt;/p:declare-step&gt;

</programlisting>

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

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

<programlisting>&lt;p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="1.0"&gt;
&lt;p:input port="source"/&gt;
&lt;p:output port="result"/&gt;

&lt;p:xslt&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:document href="http://example.com/stylesheets/doc.xsl"/&gt;
  &lt;/p:input&gt;
  &lt;p:with-param name="mode" select="'debug'"/&gt;
&lt;/p:xslt&gt;

&lt;/p:declare-step&gt;

</programlisting>

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

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

<programlisting>&lt;p:pipeline xmlns:p="http://www.w3.org/ns/xproc" version="1.0"&gt;

&lt;p:xslt&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:document href="http://example.com/stylesheets/doc.xsl"/&gt;
  &lt;/p:input&gt;
  &lt;p:with-param name="mode" select="'debug'"/&gt;
&lt;/p:xslt&gt;

&lt;/p:pipeline&gt;

</programlisting>

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

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

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

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

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

<para>Consider the
example in <xref linkend="ex.parameter"/>.</para><example xml:id="ex.parameter">
<title>A Parameter Example</title>
<programlisting>&lt;p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
	    version="1.0"
	    name="main"&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:with-param name="output-type" select="'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 steps
          don't bother to declare parameter inputs, or provide explicit connections for them, and
          “the right thing” usually happens.</para><section xml:id="cv.param"><title>The c:param
            element</title><para>A <tag>c:param</tag> represents a parameter on a parameter
            input.</para>
          <e:rng-pattern name="VocabParam"/>
          <para>The <tag class="attribute">name</tag> attribute of the <tag>c:param</tag> must have
            the lexical form of a QName.</para>
<para>If the <tag class="attribute">namespace</tag>
            attribute is specified, then the expanded name of the parameter is constructed from the
            specified namespace and the <tag class="attribute">name</tag> value. <error code="D0025">It is a <glossterm>dynamic error</glossterm> if the <tag class="attribute">namespace</tag> attribute is specified, the <tag class="attribute">name</tag>
              contains a colon, and the specified namespace is not the same as the in-scope
              namespace binding for the specified prefix.</error>
          </para>
<para>If the <tag class="attribute">namespace</tag> attribute is not specified, and
            the <tag class="attribute">name</tag> contains a colon, then the expanded name of the
            parameter is constructed using the <tag class="attribute">name</tag> value and the
            namespace declarations in-scope on the <tag>c:param</tag> element.</para>
<para>If the
              <tag class="attribute">namespace</tag> attribute is not specified, and the <tag class="attribute">name</tag> does not contain a colon, then the expanded name of the
            parameter is in no namespace.</para>
<para>Any namespace-qualified attribute names that
            appear on the <tag>c:param</tag> element are ignored. <error code="D0014">It is a
                <glossterm>dynamic error</glossterm> for any unqualified attribute names other than
                “<literal>name</literal>”, “<literal>namespace</literal>”, or
                “<literal>value</literal>” to appear on a <tag>c:param</tag>
          element.</error></para></section>

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

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

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


</section>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

</section>


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

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

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

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

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

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

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

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

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

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

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

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

<section xml:id="opt-param-bindings"><title>Namespaces on variables, options, and
          parameters</title><para>Variable, option and parameter values carry with them not only
          their literal or computed string value but also a set of namespaces. To see why this is
          necessary, consider the following
          step:</para><programlisting>&lt;p:delete xmlns:p="http://www.w3.org/ns/xproc"&gt;
  &lt;p:with-option name="match" select="'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 a
          variable, option or parameter value are computed as follows:</para><orderedlist>
          <listitem>
            <para>If the <tag class="attribute">select</tag> attribute was used to specify the value
              and it consisted of a single <literal>VariableReference</literal> (per <biblioref linkend="xpath"/> or <biblioref linkend="xpath2"/>, as appropriate), then the
              namespace bindings from the referenced option or variable are used.</para>
          </listitem>
          <listitem>
            <para>If the <tag class="attribute">select</tag> attribute was used to specify the value
              and it evaluated to a node-set, then the in-scope namespaces from the first node in
              the selected node-set (or, if it's not an element, its parent) are used.</para>
            <para>The expression is evaluated in the appropriate context, See <xref linkend="xpath-context"/>.</para>
          </listitem>
          <listitem>
            <para>Otherwise, the in-scope namespaces from the element providing the value are used.
              (For options specified using <link linkend="option-shortcut">syntactic
                shortcuts</link>, the step element itself is providing the value.)</para>
          </listitem>
        </orderedlist><para>The default namespace is never included in the namespace bindings for a
          variable, option or parameter value. Unqualified names are always in
          no-namespace.</para>
<para>Unfortunately, in more complex situations, there may be no
          single variable, option or parameter that can reliably be expected to have the correct set
          of namespace bindings. Consider this
          pipeline:</para><programlisting>&lt;p:pipeline type="ex:delete-in-div"
	    version="1.0"
	    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:option name="divchild" required="true"/&gt;

&lt;p:delete&gt;
  &lt;p:with-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 xmlns:p="http://www.w3.org/ns/xproc"
                  xmlns:ex="http://example.org/ns/ex"
		  xmlns:html="http://www.w3.org/1999/xhtml"
    divchild="html:p[@class='delete']"/&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:variable</tag>,
            <tag>p:with-option</tag> or <tag>p:with-param</tag> to provide explicit bindings.</para>
        <e:rng-pattern name="Namespaces"/>
        <para>The namespace bindings specified by a <tag>p:namespaces</tag> element are determined
          as follows:</para><orderedlist>
          <listitem>
            <para>If the <tag class="attribute">binding</tag> attribute is specified, it
                <rfc2119>must</rfc2119> contain the name of a single <glossterm baseform="in-scope-bindings">in-scope binding</glossterm>. The namespace bindings
              associated with that binding are used. <error code="S0020">It is a <glossterm>static
                  error</glossterm> if the <tag class="attribute">binding</tag> attribute on
                  <tag>p:namespaces</tag> is specified and its value is not the name of an
                  <glossterm baseform="in-scope-bindings">in-scope binding</glossterm>.</error>
            </para>
          </listitem>
          <listitem>
            <para>If the <tag class="attribute">element</tag> attribute is specified, it
                <rfc2119>must</rfc2119> contain an XPath expression which identifies a single
              element node (the input connection for this expression is the same as the connection
              for the <tag>p:option</tag> or <tag>p:with-param</tag> which contains it). The
              in-scope namespaces of that node are used.</para>
            <para>The expression is evaluated in the appropriate context, See <xref linkend="xpath-context"/>.</para>
            <para><error code="D0009">It is a <glossterm>dynamic error</glossterm> if the <tag class="attribute">element</tag> attribute on <tag>p:namespaces</tag> is specified
                and it does not identify a single element node.</error>
            </para>
          </listitem>
          <listitem>
            <para>If neither <tag class="attribute">binding</tag> nor <tag class="attribute">element</tag> is specified, the in-scope namespaces on the <tag>p:namespaces</tag>
              element itself are used.</para>
          </listitem>
        </orderedlist><para>Irrespective of how the set of namespaces are determined, the <tag class="attribute">except-prefixes</tag> attribute can be used to exclude one or more
          namespaces. The value of the except-prefixes attribute <rfc2119>must</rfc2119> be a
          sequence of tokens, each of which <rfc2119>must</rfc2119> be a prefix bound to a namespace
          in the in-scope namespaces of the <tag>p:namespaces</tag> element. All bindings of
          prefixes to each of the namespaces thus identified are excluded. <error code="S0051">It is
            a <glossterm>static error</glossterm> if the <tag class="attribute">except-prefixes</tag> attribute on <tag>p:namespaces</tag> does not contain a list of
            tokens or if any of those tokens is not a prefix bound to a namespace in the in-scope
            namespaces of the <tag>p:namespaces</tag> element.</error>
        </para>
<para><error code="S0041">It is a <glossterm>static error</glossterm> to specify both
              <tag class="attribute">binding</tag> and <tag class="attribute">element</tag> on the
            same <tag>p:namespaces</tag> element.</error>
        </para>
<para>If a <tag>p:variable</tag>, <tag>p:with-option</tag> or <tag>p:with-param</tag>
          includes one or more <tag>p:namespaces</tag> elements, then the union of all the
          namespaces specified on those elements are used as the bindings for the variable, option
          or parameter value. In this case, the in-scope namespaces on the <tag>p:variable</tag>,
            <tag>p:with-option</tag> or <tag>p:with-param</tag> are ignored. <error code="D0013">It
            is a <glossterm>dynamic error</glossterm> if the specified namespace bindings are
            inconsistent; that is, if the same prefix is bound to two different namespace
            names.</error></para>
<para>For example, this would allow the preceding example to
          work:</para><programlisting>&lt;p:pipeline type="ex:delete-in-div"
	    version="1.0"
	    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:option name="divchild" required="true"/&gt;

&lt;p:delete&gt;
  &lt;p:with-option name="match" select="concat('h:div/',$divchild)"&gt;
    &lt;p:namespaces xmlns:html="http://www.w3.org/1999/xhtml"/&gt;
  &lt;/p:with-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 (the binding for <literal>html:</literal> is explicitly
          provided and the binding for <literal>h:</literal> is in-scope). </para><note>
          <para>The use of <tag>p:namespaces</tag> here, when all of the bindings are provided with
            explicit namespace declarations, is unnecessary. The bindings could simply be placed on
            the parent <tag>p:with-option</tag> element. We use <tag>p:namespaces</tag> here only to
            make the example parallel to the one which follows.</para>
        </note><para>The preceding solution has the weakness that it depends on knowing the bindings
          that will be used by the caller. A more flexible solution would use the <tag class="attribute">binding</tag> attribute to copy the bindings from the caller's option
          value.</para><programlisting>&lt;p:pipeline type="ex:delete-in-div"
	    version="1.0"
            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:option name="divchild" required="true"/&gt;

&lt;p:delete&gt;
  &lt;p:with-option name="match" select="concat('h:div/',$divchild)"&gt;
    &lt;p:namespaces binding="divchild"/&gt;
    &lt;p:namespaces xmlns:h="http://www.w3.org/1999/xhtml"/&gt;
  &lt;/p:with-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> or pipeline. It declares the inputs, outputs, and options for all steps
        of that type.</para>
      <e:rng-pattern name="DeclareStep"/>
      <para>The value of the <tag class="attribute">type</tag> can be from any namespace provided
        that the expanded-QName of the value has a non-null namespace URI. <error code="S0025">It is
          a <glossterm>static error</glossterm> if the expanded-QName value of the <tag class="attribute">type</tag> attribute is in no namespace or in the XProc
          namespace.</error> Except as described in <xref linkend="versioning-considerations"/>, the
        XProc namespace <rfc2119>must not</rfc2119> be used in the type of steps. Neither users nor
        implementers may define additional steps in the XProc namespace.</para>
<para>Irrespective of
        the context in which the <tag>p:declare-step</tag> occurs, there are initially no option or
        variable names in-scope inside a <tag>p:declare-step</tag>. That is, <tag>p:option</tag> and
          <tag>p:variable</tag> elements can refer to values declared by their preceding siblings,
        but not by any of their ancestors.</para>

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

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

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

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

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

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

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

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

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

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

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

<para>Consider this example:</para>

<programlisting>&lt;p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="1.0"&gt;
  &lt;p:output port="result"/&gt;
  &lt;p:serialization port="result" indent="true"/&gt;

  &lt;p:identity xmlns:a="http://example.com/a"
              xmlns:b="http://example.com/b"
              xmlns:c="http://example.com/c"&gt;
    &lt;p:input port="source"&gt;
      &lt;p:inline exclude-inline-prefixes="a b"&gt;
        &lt;doc&gt;
          &lt;b:part/&gt;
        &lt;/doc&gt;
      &lt;/p:inline&gt;
    &lt;/p:input&gt;
  &lt;/p:identity&gt;

&lt;/p:declare-step&gt;
</programlisting>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<programlisting>&lt;p:identity name="readcsv"&gt;
  &lt;p:input port="source"&gt;
    &lt;p:data href="stateabbr.csv"/&gt;
  &lt;/p:input&gt;
&lt;/p:identity&gt;
</programlisting>

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

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

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

<programlisting>&lt;p:identity name="readpng"&gt;
  &lt;p:input port="source"&gt;
    &lt;p:data href="icon.png" content-type="image/png"/&gt;
  &lt;/p:input&gt;
&lt;/p:identity&gt;

&lt;p:add-attribute name="makeimg" match="img" attribute-name="src"&gt;
  &lt;p:input port="source"&gt;&lt;p:inline&gt;&lt;img/&gt;&lt;/p:inline&gt;&lt;/p:input&gt;
  &lt;p:with-option name="attribute-value"
		 select="concat('data:image/png;base64,',/*/node())"&gt;
    &lt;p:pipe step="readpng" port="result"/&gt;
  &lt;/p:with-option&gt;
&lt;/p:add-attribute&gt;
</programlisting>

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

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

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

</section>


    <section xml:id="p.empty"><title>p:empty</title><para>A <tag>p:empty</tag> connects to an
          <glossterm>empty sequence</glossterm> of documents.</para>
      <e:rng-pattern name="Empty"/>
    </section>
    <section xml:id="p.documentation"><title>p:documentation</title><para>A
          <tag>p:documentation</tag> contains human-readable documentation.</para>
      <e:rng-pattern name="Documentation"/>
      <para>There are no constraints on the content of the <tag>p:documentation</tag> element.
        Documentation is ignored by pipeline processors. See <xref linkend="documentation"/>.
      </para></section>
    <section xml:id="p.pipeinfo"><title>p:pipeinfo</title><para>A <tag>p:pipeinfo</tag> contains
        ancillary information for steps in the pipeline.</para>
      <e:rng-pattern name="PipeInfo"/>
      <para>There are no constraints on the content of the <tag>p:pipeinfo</tag> element, see <link linkend="annotations"/>.</para></section>
  </section>
  <section xml:id="errors">
    <title>Errors</title>
    <para>Errors in a pipeline can be divided into two classes: static errors and dynamic
      errors.</para>
    <section xml:id="static-errors">
      <title>Static Errors</title>
      <para><termdef xml:id="dt-static-error">A <firstterm>static error</firstterm> is one which can
          be detected before pipeline evaluation is even attempted.</termdef> Examples of static
        errors include cycles and incorrect specification of inputs and outputs. </para>
      <para>Static errors are fatal and must be detected before any steps are evaluated.</para>
      <para>For a complete list of static errors, see <xref linkend="app.static-errors"/>.</para>
    </section>
    <section xml:id="dynamic-errors">
      <title>Dynamic Errors</title>
      <para>A <termdef xml:id="dt-dynamic-error">A <firstterm>dynamic error</firstterm> is one which
          occurs while a pipeline is being evaluated.</termdef> Examples of dynamic errors include
        references to URIs that cannot be resolved, steps which fail, and pipelines that exhaust the
        capacity of an implementation (such as memory or disk space).</para>
      <para>If a step fails due to a dynamic error, failure propagates upwards until either a
          <tag>p:try</tag> is encountered or the entire pipeline fails. In other words, outside of a
          <tag>p:try</tag>, step failure causes the entire pipeline to fail.</para>
      <para>For a complete list of dynamic errors, see <xref linkend="app.dynamic-errors"/>.</para>
    </section>
    <section xml:id="step-errors">
      <title>Step Errors</title>
      <para>Several of the steps in the standard and option step library can generate dynamic
        errors.</para>
      <para>For a complete list of the dynamic errors raised by builtin pipeline steps, see <xref linkend="app.step-errors"/>.</para>
    </section>
  </section>
  <?oxygen RNGSchema="../schema/dbspec.rnc" type="compact"?><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 section describes the standard XProc steps. A machine-readable
description of these steps may be found in
<link xlink:href="http://www.w3.org/2008/xproc-1.0.xpl">xproc-1.0.xpl</link>.
</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 to compute an option value, the XPath
context is as defined in <link linkend="xpath-context"/>.</para>

<para>When a step specifies a particular version of a technology,
implementations <rfc2119>must</rfc2119> implement that
version or a subsequent version that is backwards compatible with that
version. At user-option, they may implement other non-backwards
compatible versions.</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 matched elements is
copied to the output with the addition of the specified attribute
with the specified value.
</para>

<p:declare-step type="p:add-attribute">
  <p:input port="source"/>
  <p:output port="result"/>
  <p:option name="match" required="true" e:type="XSLTMatchPattern"/>
  <p:option name="attribute-name" required="true" e:type="xsd:QName"/>
  <p:option name="attribute-prefix" e:type="xsd:NCName"/>
  <p:option name="attribute-namespace" e:type="xsd:anyURI"/>
  <p:option name="attribute-value" required="true" e:type="xsd:string"/>
</p:declare-step>

<para>The value of the <option>match</option> option
<rfc2119>must</rfc2119> be an XSLTMatchPattern. <error code="C0023">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
<rfc2119>must</rfc2119> be a <type>QName</type>.
If the lexical value does not contain a colon, then the <tag class="attribute">attribute-namespace</tag> may be used to specify the
namespace of the attribute. In that case, the <tag class="attribute">attribute-prefix</tag> may be specified to suggest a
prefix for the attribute name. <error code="D0034">It is a
<glossterm>dynamic error</glossterm> to specify a new namespace or
prefix if the lexical value of the specified name contains a
colon.</error>
The corresponding expanded name is used to construct the attribute.</para>

<para>The value of the <option>attribute-value</option> option
<rfc2119>must</rfc2119> be a legal attribute value according to XML.</para>

<para>If an attribute with the same name as the expanded name
from the <option>attribute-name</option> option exists on the matched
element, the value specified in
the <option>attribute-value</option> option is used to set the
value of that existing attribute.  That is, the value of the
existing attribute is changed to the <option>attribute-value</option>
value. </para>

<note><para>If multiple attributes need to be set on the same
element(s), the <tag>p:set-attributes</tag> step can be used to set them
all at once.</para>
</note>

<para>This step cannot be used to add namespace declarations. <error code="C0059">It is a <glossterm>dynamic error</glossterm> if the QName
value in the <option>attribute-name</option> option uses the prefix
“<literal>xmlns</literal>”
or any other prefix that resolves to the namespace name
“<uri>http://www.w3.org/2000/xmlns/</uri>”.
</error> Note, however, that while namespace declarations cannot be
added explicitly by this step, adding an attribute whose name is in a
namespace for which there is no namespace declaration in scope on the
matched element may result in a namespace binding being added by <xref linkend="namespace-fixup"/>.</para>

<para>If an attribute named
<tag class="attribute">xml:base</tag> is added or changed, the base URI
of the element <rfc2119>must</rfc2119> also be amended accordingly.</para>

</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 or corrected on 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" select="'false'" e:type="xsd:boolean"/>
   <p:option name="relative" select="'true'" e:type="xsd:boolean"/>
</p:declare-step>
 
 <para>The value of the <option>all</option> option
<rfc2119>must</rfc2119> be a boolean.</para>
 
 <para>The value of the <option>relative</option> option
<rfc2119>must</rfc2119> be a boolean.</para>

<para><error code="C0058">It is a <glossterm>dynamic error</glossterm>
if the <option>all</option> and <option>relative</option> options are
<emphasis>both</emphasis> <literal>true</literal>.</error></para>

<para>The <tag>p:add-xml-base</tag> step modifies its input as follows:</para>

<itemizedlist>
<listitem>
<para>For the document element: force the element to have an <tag class="attribute">xml:base</tag>
attribute with the document's [base URI] property's value as its value.</para>
</listitem>
<listitem>
<para>For other elements:</para>
<itemizedlist>
<listitem>
<para>If the <option>all</option> option has the value
<literal>true</literal>, force the element to have an <tag class="attribute">xml:base</tag> attribute with the element's [base
URI] value as its value.</para>
</listitem>
<listitem>
<para>If the element's [base URI] is different from the its parent's
[base URI], force the element to have an <tag class="attribute">xml:base</tag> attribute with the following
value: if the value of the <option>relative</option> option is
<literal>true</literal>, a string which, when resolved against the
parent's [base URI], will give the element's [base URI], otherwise the
element's [base URI].</para>
</listitem>
<listitem>
<para>Otherwise, if there is an <tag class="attribute">xml:base</tag> attribute present, remove it.
</para>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>
</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" e:type="xsd:boolean"/>
   <p:option name="fail-if-not-equal" select="'false'" e:type="xsd:boolean"/>
</p:declare-step>
 
 <para>The value of the <option>fail-if-not-equal</option> option <rfc2119>must</rfc2119> 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:option name="limit" select="0" e:type="xsd:integer"/>
</p:declare-step>

<para>If the <tag class="attribute">limit</tag> option is specified
and is greater than zero, the <tag>p:count</tag> step will count at most
that many documents. This provides a convenient mechanism to discover,
for example, if a sequence consists of more than 1 document, without
requiring every single document to be buffered before processing can
continue.</para>
</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 deleted items removed, 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" e:type="XSLTMatchPattern"/>
</p:declare-step>

<para>The value of the <option>match</option> option <rfc2119>must</rfc2119> be an
XSLTMatchPattern. A match pattern may match multiple items to be
deleted.</para>

<para>If an element is selected by the <option>match</option> option, the
entire subtree rooted at that element is deleted.</para>

<para>This step cannot be used to remove namespaces. <error code="C0062">It is a <glossterm>dynamic error</glossterm> if the
<option>match</option> option matches a namespace node.</error>
Also, note that deleting an attribute named
<tag class="attribute">xml:base</tag> does not change the base URI
of the element on which it occurred.</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" required="true" e:type="xsd:anyURI"/>
  <p:option name="include-filter" e:type="RegularExpression"/>
  <p:option name="exclude-filter" e:type="RegularExpression"/>
</p:declare-step>
 
<para>The value of the <option>path</option> option
<rfc2119>must</rfc2119> be an <type>anyURI</type>. It is interpreted
as an IRI reference. If it is relative, it is made absolute against
the base URI of the element on which it is specified
(<tag>p:with-option</tag> or <tag>p:directory-list</tag> in the case of a
<link linkend="option-shortcut">syntactic shortcut</link> value).</para>

<para><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 <rfc2119>must</rfc2119> 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>
</para>
 
<para>If present, the value of the <option>include-filter</option>
or <option>exclude-filter</option>
option <rfc2119>must</rfc2119> be a regular expression as specified in <biblioref linkend="xpath-functions"/>, section 7.61 “<literal>Regular Expression
Syntax</literal>”.</para>

<para>If the <option>include-filter</option> pattern matches a
directory entry's name, the entry is included in the output. If the
<option>exclude-filter</option> pattern matches a directory entry's name,
the entry is excluded in the output. If both options are provided, the
include filter is processed first, then the exclude filter.</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
<tag class="attribute">name</tag> attribute is the last segment
of the directory path (that is, the directory's (local) name).</para>

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

<para>Its contents are determined as follows, based on the entries in
the directory identified by the directory path. 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>

<itemizedlist>
<listitem>
<para>A <tag>c:directory</tag> is produced for each subdirectory not
determined to be special.</para>
</listitem>
<listitem>
<para xml:id="cv.file">A <tag>c:file</tag> is produced for each file
not determined to be special.</para>
<e:rng-pattern name="VocabFile"/>
</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 are <glossterm>implementation-defined</glossterm>.</impl>
</para>
<e:rng-pattern name="VocabOther"/>
</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 it
appears 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>
are <glossterm>implementation-defined</glossterm>.</impl></para>

</section>

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

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

<para>The <code>p:error</code> step generates a <glossterm role="unwrapped">dynamic error</glossterm> using the input provided
to the step.</para>

<p:declare-step type="p:error">
  <p:input port="source" primary="false"/>
  <p:output port="result" sequence="true"/>
  <p:option name="code" required="true" e:type="xsd:QName"/>
  <p:option name="code-prefix" e:type="xsd:NCName"/>
  <p:option name="code-namespace" e:type="xsd:anyURI"/>
</p:declare-step>

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

<para>This step uses the document provided on its input as the content
of the error raised. An instance of the
<tag>c:errors</tag> element will be produced on the error output port, as is
always the case for <glossterm baseform="dynamic error" role="unwrapped">dynamic errors</glossterm>.
The error generated can be caught by a <tag>p:try</tag> just like any
other dynamic error.</para>

<para>For authoring convenience, the <tag>p:error</tag> step is
declared with a single, primary output port. With respect to
<glossterm baseform="connection">connections</glossterm>, this port behaves like
any other output port even though nothing can ever
appear on it since the step always fails.</para>

<para>For example, given the following invocation:</para>
<programlisting>
<![CDATA[<p:error xmlns:my="http://www.example.org/error"
         name="bad-document" code="my:unk12">
   <p:input port="source">
     <p:inline>
       <message>The document element is unknown.</message>
     </p:inline>
   </p:input>
</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"><message>The document element is unknown.</message>
</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"/>
  &serialization-options-for-escape-markup;
</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"&amp;gt;
&amp;lt;p&gt;This is a chunk of XHTML.&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/description&gt;
</programlisting>

<note>
<para>The result of this step is an XML document that contains the
Unicode characters that are the characters that result from escaping
the input. It is not encoded characters in a serialized octet stream,
therefore, the serialization options related to encoding characters
(<option>byte-order-mark</option>, <option>encoding</option>, and
<option>normalization-form</option>) do not apply. They are omitted
from the standard serialization options on this step.</para>
</note>

<para>By default, this step <rfc2119>must not</rfc2119> generate an
XML declaration in the escaped result.</para>

</section>

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

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

<para>The <code>p:filter</code> step selects portions of the source document
based on a (possibly dynamically constructed) XPath select expression.</para>

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

<para>This step behaves just like an <tag>p:input</tag> with 
a <tag class="attribute">select</tag> expression except that the select
expression is computed dynamically.</para>

</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 over HTTP or 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"/>
  &serialization-options;
</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 is 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>An HTTP request is represented by a <tag>c:request</tag> element.</para>

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

<para><error code="C0006">It is a <glossterm>dynamic error</glossterm> if the
<tag class="attribute">method</tag> is not specified on a <tag>c:request</tag>.
</error>
<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
<tag class="attribute">method</tag> 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> (the value is not case-sensitive).
If the <code>href</code>
attribute is not absolute, it will be resolved against the base URI of
the element on which it is occurs.</para>

<note><para>In the case of simple “GET” requests, implementors are encouraged
to support as many protocols as practical. In particular, pipeline authors may
attempt to use <tag>p:http-request</tag> to load documents with computed
URIs using the <literal>file:</literal> scheme.</para></note>

<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 according to the selected
authentication method.</para>

<para>For the purposes of avoiding an authentication challenge, if the
<code>send-authorization</code> attribute has the value
<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 <code>send-authorization</code> attribute is absent or
has the value
<literal>false</literal>, then the first request is sent without an
<code>Authorization</code> header.</para>

<para>If the initial response to the request is an
authentication challenge, the <code>auth-method</code>,
<code>username</code>, <code>password</code> and any relevant data from
the challenge 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>Appropriate values for the <code>auth-method</code> attribute
are “Basic” or “Digest” but other values are allowed. 
If the authentication method is “Basic” or “Digest”, authentication
is handled as per <biblioref linkend="rfc2617"/>.
<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></para>

<para><error code="C0003">It
is a <glossterm>dynamic error</glossterm> if a <option>username</option>
or <option>password</option> is specified without specifying an
<option>auth-method</option>, if
the requested
<option>auth-method</option> 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 <xref linkend="c.response_body"/>.</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.</para>

<para>The <tag>p:http-request</tag> step allows users to specify
independently values that are not always independent. For example,
some combinations of <tag>c:header</tag> values
(e.g., <literal>Content-Type</literal>)
may be inconsistent
with values that the step and/or protocol implementation must set. In
a few cases, the step provides more than one mechanism to specify what
is actually a single value (e.g., the boundary string in multipart
messages).
<error code="C0020">It is a
<glossterm>dynamic error</glossterm> if the the user specifies a value
or values that are inconsistent with each other or with the requirements
of the step or protocol.</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>
<rfc2119>must</rfc2119> 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 <code>boundary</code> attribute is required and is used to
provide a multipart boundary marker. The implementation must use this
boundary marker and must prefix the value with the string
“<literal>--</literal>” when formulating the multipart message. <error code="C0002">It is a <glossterm>dynamic error</glossterm> if the value
starts with the string “<literal>--</literal>”.</error></para>

<para>If the boundary is also specified as a parameter in the
<option>content-type</option> option, then the parameter value specified
and the <option>boundary</option> value specified <rfc2119>must</rfc2119>
be the same. If the boundary is specified in both the <option>boundary</option>
option and the <option>content-type</option> option then the two values
<rfc2119>must</rfc2119> be the same.</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 the request body or decoding the body element's content 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
or text, the content must already be base64-encoded.</para>

<para>The <code>encoding</code> attribute controls the decoding of the
element content for formulating the body. A value of
<literal>base64</literal> indicates the element's content is a base64
encoded string whose byte stream should be sent as the message body.
<impl>An implementation may support encodings other than
<literal>base64</literal> but these encodings and their names are
<glossterm>implementation-defined</glossterm>.</impl>
<error code="C0052">It is a <glossterm>dynamic
error</glossterm> if the encoding specified is not supported by the
implementation.</error></para>

<note>
<para>The <tag>p:http-request</tag> step provides only a single set of
serialization options for XML media types. There's no direct support
for sending a multipart message with two XML parts encoded
differently.</para>
</note>

<para>For each body or body part, the <code>id</code> attribute
specifies the value of the <code>Content-ID</code> header;
the <code>description</code> attribute specifies the
value of the <code>Content-Description</code> header;
and the <code>disposition</code> attribute specifies the value
of the <code>Content-Disposition</code> header.
</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
“<literal>base64</literal>”, 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"

<?xml version='1.0'?>
<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 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
 <xref linkend="c.response_body"/>.</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
<xref linkend="c.response_body"/>.</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 xml:id="redirects">
<title>Redirects</title>

<para>One possible response from an HTTP request is a redirect,
indicated by a status code in the three-hundred range. The precise
semantics of the 3xx return codes are laid out by section
<citetitle>10.3 Redirection 3xx</citetitle> in <biblioref linkend="rfc2616"/>.
</para>

<para>The <tag>p:http-request</tag> step <rfc2119>should</rfc2119> follow
redirect requests (in a manner consistent with <biblioref linkend="rfc2616"/>)
if they are returned by the server.
</para>
</section>

<section xml:id="cookies">
<title>Cookies</title>

<para>With one exception, in version 1.0 of XProc, the
<tag>p:http-request</tag> step does not provide any standard
mechanisms for managing cookies. <impl>Pipeline authors that need to
preserve cookies across several <tag>p:http-request</tag> calls in the
same pipeline or across multiple invocations of the same or different
pipelines will have to rely on
<glossterm>implementation-defined</glossterm> mechanisms.</impl>
</para>

<para>The exception arises in the case of redirection. If a redirect
response includes cookies, those cookies <rfc2119>should</rfc2119> be
forwarded as appropriate to the redirected location when the
redirection is followed.</para>

<para>This behavior will allow the <tag>p:http-request</tag> step to
interoperate with web services that use cookies as part of an
authentication protocol.</para>

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

<note>
<para>Although it is technically possible for any of the individual
parts of a multipart message to <emphasis>also</emphasis> be
multipart, XProc does not provide a standard representation for such
messages. <impl>The interpretation of a multipart message inside
another multipart message is
<glossterm>implementation-dependent</glossterm>.</impl></para>
</note>

<para>The result of the <tag>p:http-request</tag> step is an XML
document. For media types (images, binaries, etc.) that can't be
represented as a sequence of Unicode characters, the response is
encoded as <literal>base64</literal>
and then returned as text children of the <tag>c:body</tag> element.
If the content is base64-encoded, the <tag class="attribute">encoding</tag> attribute on <tag>c:body</tag> must
be set to “<literal>base64</literal>”.</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
(per <biblioref linkend="unicodetr17"/>) or
is recognized as a non-XML media type whose contents are encoded as a
sequence of Unicode characters (e.g. it has a character parameter or
the definition of the media type is such that it requires Unicode),
the content of the constructed <tag>c:body</tag> element is the translation
of the text into a sequence of Unicode characters.</para>

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

<para>In a <tag>c:body</tag> in a response, the
<tag class="attribute">content-type</tag> attribute <rfc2119>must</rfc2119>
be an exact copy of the value returned in the
<literal>Content-Type</literal> header. That is, it must reflect the
content type actually returned, not any override value that may have been
specified, and it must include any parameters returned by the server.</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 encoded as (escaped) text or
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: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:request&gt;
</programlisting>
<para>and if the response was an XHTML document, the result document would be:</para>
<programlisting>&lt;c: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='http://www.w3.org/2001/05/P3P/p3p.xml'"/&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="'4640a109;42380ddc'"/&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: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>

<para>If the implementation supports passing PSVI annotations between
steps, the <tag>p:identity</tag> step <rfc2119>must</rfc2119> preserve
any annotations that appear in the input.</para>

</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 into the <port>source</port>
port's document relative to the 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" sequence="true"/>
   <p:output port="result"/>
   <p:option name="match" select="'/*'" e:type="XSLTMatchPattern"/>
   <p:option name="position" required="true" e:type="first-child|last-child|before|after"/>
</p:declare-step>

<para>The value of the <option>match</option> option
<rfc2119>must</rfc2119> be an XSLTMatchPattern. <error code="C0023">It
is a <glossterm>dynamic error</glossterm> if that pattern matches
anything other than element, text, processing-instruction, or comment nodes.</error>
Multiple matches are
allowed, in which case multiple copies of the <port>insertion</port>
documents will occur. If no elements match, then the document is
unchanged.</para>

<para>The value of the <option>position</option> option <rfc2119>must</rfc2119> 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 anything other than an element node and
the value of the <option>position</option> option is
“<literal>first-child</literal>” or
“<literal>last-child</literal>”.</error></para>

<para>As the inserted elements are part of the output of the step they
are not considered in determining matching elements. If an empty sequence
appears on the <port>insertion</port> port, the result will be the same
as the source.</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 matched
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" select="'xml:id'" e:type="xsd:QName"/>
  <p:option name="attribute-prefix" e:type="xsd:NCName"/>
  <p:option name="attribute-namespace" e:type="xsd:anyURI"/>
  <p:option name="label" select="'concat(&quot;_&quot;,$p:index)'" e:type="XPathExpression"/>
  <p:option name="match" select="'*'" e:type="XSLTMatchPattern"/>
  <p:option name="replace" select="'true'" e:type="xsd:boolean"/>
</p:declare-step>

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

<para>The value of the <option>label</option> option is an XPath
expression used to generate the value of the attribute label.</para>

<para>The value of the <option>match</option> option
<rfc2119>must</rfc2119> be an XSLTMatchPattern. <error code="C0023">It
is a <glossterm>dynamic error</glossterm> if that expression matches
anything other than element nodes.</error></para>

<para>The value of the <option>replace</option>
<rfc2119>must</rfc2119> be a boolean value and is used to indicate
whether existing attribute values are replaced.</para>

<para>This step operates by generating attribute labels for each
element matched. For every matched element, the expression is
evaluated with the context node set to the matched element. An
attribute is added to the matched element using the attribute name is
specified the <option>attribute</option> option and the string value
of result of evaluating the expression. If the attribute already
exists on the matched element, the value is replaced with the string
value only if the <option>replace</option> option has the value of
<literal>true</literal>.</para>

<para>If this step is used to add or change the value
of an attribute named “<literal>xml:base</literal>”, the base URI
of the element <rfc2119>must</rfc2119> also be amended accordingly.</para>

<para>An implementation must bind the variable
“<literal>p:index</literal>” in the static context of each evaluation
of the XPath expression to the position of the element in the sequence
of matched elements. In other words, the first element (in document
order) matched gets the value “<literal>1</literal>”, the second gets
the value “<literal>2</literal>”, the third, “<literal>3</literal>”,
etc.</para>

<para>The result of the p:label-elements step is the input document with the 
attribute labels associated with matched elements.  All other non-matching content
remains the same.</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" e:type="xsd:anyURI"/>
  <p:option name="dtd-validate" select="'false'" e:type="xsd:boolean"/>
</p:declare-step>

<para>The value of the <option>href</option> option
<rfc2119>must</rfc2119> be an <type>anyURI</type>. It is interpreted
as an IRI reference. If it is relative, it is made absolute against
the base URI of the element on which it is specified
(<tag>p:with-option</tag> or <tag>p:load</tag> in the case of a <link linkend="option-shortcut">syntactic shortcut</link> value).</para>

<para>The value of the <option>dtd-validate</option> option
<rfc2119>must</rfc2119> be a boolean.</para>

<para>The <tag>p:load</tag> step is the same as <tag>p:document</tag>
with two additions:</para>

<orderedlist>
<listitem>
<para>The URI to be accessed can be constructed dynamically by the
pipeline.</para>
</listitem>
<listitem>
<para>The <tag>p:load</tag> step has an option to invoke DTD validation.
</para>
</listitem>
</orderedlist>

<para>When <option>dtd-validate</option> is <literal>false</literal>,
<tag>p:load</tag> processing is the same as <tag>p:document</tag>
processing on the computed <option>href</option> value.</para>

<para>When <option>dtd-validate</option> is <literal>true</literal>,
<tag>p:load</tag> processing is the same as <tag>p:document</tag>
processing on the computed <option>href</option> value but
<rfc2119>must</rfc2119> use a validating parser. <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>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>
</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" e:type="XSLTMatchPattern"/>
  <p:option name="base-uri" e:type="xsd:anyURI"/>
</p:declare-step>

<para>The value of the <option>match</option> option <rfc2119>must</rfc2119> be an
XSLTMatchPattern.
<error code="C0023">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
<rfc2119>must</rfc2119> be an <type>anyURI</type>. It is interpreted
as an IRI reference. If it is relative, it is made absolute against
the base URI of the element on which it is specified
(<tag>p:with-option</tag> or <tag>p:make-absolute-uris</tag> in the case of
a <link linkend="option-shortcut">syntactic shortcut</link>
value).</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" e:type="xsd:anyURI"/>
   <p:option name="to" e:type="xsd:anyURI"/>
   <p:option name="apply-to" select="'all'" e:type="all|elements|attributes"/>
</p:declare-step>
 
<para>The value of the <option>from</option> option
<rfc2119>must</rfc2119> be an <type>anyURI</type>. 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
<rfc2119>must</rfc2119> be an <type>anyURI</type>. It
<rfc2119>should</rfc2119> be empty or absolute, but will not be
resolved in any case.</para>

<para>The value of the <option>apply-to</option> option
<rfc2119>must</rfc2119> be one of “<literal>all</literal>”,
“<literal>elements</literal>”, or “<literal>attributes</literal>”.
If the value is “<literal>elements</literal>”, only elements will be
renamed, if the value is “<literal>attributes</literal>”, only attributes
will be renamed, if the value is “<literal>all</literal>”, both elements
and attributes will be renamed.</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, 
as appropriate, in the input whose namespace name is the same as the value of the
<option>from</option> option, in the output its namespace name is</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, as appropriate,
   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>apply-to</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" e:type="xsd:QName"/>
   <p:option name="wrapper-prefix" e:type="xsd:NCName"/>
   <p:option name="wrapper-namespace" e:type="xsd:anyURI"/>
</p:declare-step>

<para>The value of the <option>wrapper</option> option
<rfc2119>must</rfc2119> be a <type>QName</type>. If the lexical value
does not contain a colon, then the <tag class="attribute">wrapper-namespace</tag>
may be used to specify the namespace of the wrapper. In that case, the
<tag class="attribute">wrapper-prefix</tag> may be specified to suggest a
prefix for the wrapper element.
<error code="D0034">It is a <glossterm>dynamic error</glossterm>
to specify a new namespace or prefix if the lexical value of the specified
name contains a colon.</error></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 <tag>c:param-set</tag> document.</para>

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

<para>Each parameter passed to the step is converted into a
<tag>c:param</tag> element. The step resolves duplicate parameters in
the normal way (see <link linkend="parameter-inputs"/>) so at most one
parameter with any given name will appear in the result.
The resulting <tag>c:param</tag> elements are wrapped in a 
<tag>c:param-set</tag> and the parameter set document is written
to the <port>result</port> port.
<impl>The
order in which <tag>c:param</tag> elements occur in the <tag>c:param-set</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:param</tag> element <rfc2119>must</rfc2119> be used. Each
<tag class="attribute">name</tag> <rfc2119>must</rfc2119> 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:with-param</tag> settings <rfc2119>must</rfc2119> include a
<tag class="attribute">port</tag> attribute, per the last paragraph of <xref linkend="p.with-param"/>.</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" e:type="XSLTMatchPattern"/>
  <p:option name="new-name" required="true" e:type="xsd:QName"/>
  <p:option name="new-prefix" e:type="xsd:NCName"/>
  <p:option name="new-namespace" e:type="xsd:anyURI"/>
</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 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
<type>QName</type>.
If the lexical value does not contain a colon, then the <tag class="attribute">new-namespace</tag> may be used to specify the
namespace of the new name. In that case, the <tag class="attribute">new-prefix</tag> may be specified to suggest a
prefix for the new name. <error code="D0034">It is a
<glossterm>dynamic error</glossterm> to specify a new namespace or
prefix if the lexical value of the specified name contains a
colon.</error>
</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>If the <option>match</option> option matches an attribute and if
the element on which it occurs already has an attribute whose expanded
name is the same as the expanded name of the specified
<option>new-name</option>, then the results is as if the current
attribute named “<replaceable>new-name</replaceable>” was deleted before
renaming the matched attribute.</para>

<para>With respect to attributes named “<literal>xml:base</literal>”, the
following semantics apply: renaming an <emphasis>from</emphasis> 
“<literal>xml:base</literal>” <emphasis>to</emphasis> something else has
no effect on the underlying base URI of the element; however,
if an attribute is renamed <emphasis>from</emphasis> something else
<emphasis>to</emphasis> “<literal>xml:base</literal>”, the base URI
of the element <rfc2119>must</rfc2119> also be amended accordingly.</para>

<para>If the pattern matches processing instructions, then it is the
processing instruction target that is renamed. <error code="C0013">It
is a <glossterm>dynamic error</glossterm> if the pattern matches
a processing instruction and the new name has a non-null namespace.</error>
</para>

</section>

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

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

<para>The <code>p:replace</code> step replaces matching nodes 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" e:type="XSLTMatchPattern"/>
</p:declare-step>
 
<para>The value of the <option>match</option> option
<rfc2119>must</rfc2119> be an XSLTMatchPattern. <error code="C0023">It
is a <glossterm>dynamic error</glossterm> if that pattern matches
anything other than element, text, processing-instruction, or comment
nodes. </error> Multiple matches are allowed, in which case multiple
copies of the <port>replacement</port> document will occur.</para>

<para>Every node 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 a node 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" e:type="XSLTMatchPattern"/>
</p:declare-step>
 
 <para>The value of the <option>match</option> option <rfc2119>must</rfc2119> 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>

<para>This step must not copy namespace declarations.  If the attributes
copied from the <port>attributes</port> use namespaces, prefixes, or 
prefixes bound to different namespaces, the document produced on the
<port>result</port> output port will require
<link linkend="namespace-fixup">namespace fixup</link>.</para>

<para>If an attribute named
<tag class="attribute">xml:base</tag> is added or changed, the base URI
of the element <rfc2119>must</rfc2119> also be amended accordingly.</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="initial-only" select="'false'" e:type="xsd:boolean"/>
  <p:option name="test" required="true" e:type="XPathExpression"/>
</p:declare-step>
 
 <para>The value of the <option>test</option> option <rfc2119>must</rfc2119> 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>If the <option>initial-only</option> option is true, then when
the first document that does not satisfy the test expression is
encountered, it <emphasis>and all the documents that follow
it</emphasis> are written to the <port>not-matched</port> port.
In other words, it only writes the initial series of matched
documents (which may be empty) to the <port>matched</port> port.
All other documents are written to the <port>not-matched</port> port,
irrespective of whether or not they match.</para>

<para>The <link linkend="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
(<code>position()</code>) is the position of that document within the
sequence and the context size (<code>last()</code>) 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>

<para>If the implementation supports passing PSVI annotations between
steps, the <tag>p:split-sequence</tag> step <rfc2119>must</rfc2119> preserve
any annotations that appear in the input.</para>

</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. 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" required="true" e:type="xsd:anyURI"/>
  &serialization-options;
</p:declare-step>

<para>The value of the <option>href</option> option
<rfc2119>must</rfc2119> be an <type>anyURI</type>. If it is relative,
it is made absolute against the base URI of the element on which it is
specified (<tag>p:with-option</tag> or <tag>p:store</tag> in the case
of a <link linkend="option-shortcut">syntactic shortcut</link>
value).</para>

<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.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" e:type="XSLTMatchPattern"/>
   <p:option name="replace" required="true" e:type="XPathExpression"/>
</p:declare-step>

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

<para>The value of the <option>replace</option> option <rfc2119>must</rfc2119> 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 with the matching node as the XPath context node.
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.
If the attribute is named “<tag class="attribute">xml:base</tag>”, the base URI
of the element <rfc2119>must</rfc2119> also be amended accordingly.</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.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" e:type="xsd:anyURI"/>
  <p:option name="content-type" select="'application/xml'" e:type="xsd:string"/>
  <p:option name="encoding" e:type="xsd:string"/>
  <p:option name="charset" e:type="xsd:string"/>
</p:declare-step>
 
<para>The value of the <option>namespace</option> option
<rfc2119>must</rfc2119> be an <type>anyURI</type>. 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 a default
namespace. Elements that are in no namespace in the unescaped content
will be placed into this namespace unless there is an in-scope namespace
declaration that specifies a different namespace (or explicitly undeclares
the default namespace).</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>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>
<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>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 character set may be specified as a parameter on the
<option>content-type</option> or via the separate
<option>charset</option> option. If it is specified in both places,
the value of the <option>charset</option> option
<rfc2119>must</rfc2119> be used.</para>

<para>If the specified
<option>encoding</option> is <literal>base64</literal>,
then the character set
<rfc2119>must</rfc2119> be specified.
<error code="C0010">It is a <glossterm>dynamic error</glossterm>
if an encoding of <literal>base64</literal> is specified and
the character set is not specified or if the specified
character set is not supported by the implementation.</error>
</para>

<para>The octet-stream that results from decoding the
text <rfc2119>must</rfc2119> be interpreted using the character encoding named by
the value of the <option>charset</option> option
to produce a sequence of Unicode characters to parse.</para>

<para>If no <option>encoding</option> is specified, the character set
is ignored, irrespective of where it was specified.</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&gt;
&lt;p xmlns="http://www.w3.org/1999/xhtml"&gt;This is a chunk.&lt;/p&gt;
&lt;p xmlns="http://www.w3.org/1999/xhtml"&gt;This is a another chunk.&lt;/p&gt;
&lt;/description&gt;
</programlisting>
</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" e:type="XSLTMatchPattern"/>
</p:declare-step>

 <para>The value of the <option>match</option> option <rfc2119>must</rfc2119> 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 might 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" e:type="xsd:QName"/>
   <p:option name="wrapper-prefix" e:type="xsd:NCName"/>
   <p:option name="wrapper-namespace" e:type="xsd:anyURI"/>
   <p:option name="match" required="true" e:type="XSLTMatchPattern"/>
   <p:option name="group-adjacent" e:type="XPathExpression"/>
</p:declare-step>

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

<para>The value of the <option>match</option> option
<rfc2119>must</rfc2119> be an XSLTMatchPattern. <error code="C0023">It
is a <glossterm>dynamic error</glossterm> if the pattern matches
anything other than document, element, text, processing instruction, and comment
nodes.</error>
</para>

<para>The value of the <option>group-adjacent</option> option
<rfc2119>must</rfc2119> be an XPathExpression.</para>

<para>If the node matched is the document node (<code>match="/"</code>),
the result is a new document where the document element is a new
element node whose QName is the value specified in the
<option>wrapper</option> option. That new element contains copies of
all of the children of the original document node.</para>

<para>When the match pattern does not match the document node,
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. The <tag>p:wrap</tag> step performs a "deep" wrapping, the children
of the matching node and their descendants are processed and wrappers
are added to all matching nodes.
</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, non-matching 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" e:type="xsd:QName"/>
   <p:option name="wrapper-prefix" e:type="xsd:NCName"/>
   <p:option name="wrapper-namespace" e:type="xsd:anyURI"/>
   <p:option name="group-adjacent" e:type="XPathExpression"/>
</p:declare-step>

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

<para>The value of the <option>group-adjacent</option> option
<rfc2119>must</rfc2119> 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 <link linkend="xpath-context">XPath context</link> for the
<option>group-adjacent</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
(<code>position()</code>) is the position of that document within the
sequence and the context size (<code>last()</code>) is the total
number of documents in the sequence.
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" select="'false'" e:type="xsd:boolean"/>
  <p:option name="fixup-xml-lang" select="'false'" e:type="xsd:boolean"/>
</p:declare-step>

<para>The value of the <option>fixup-xml-base</option> option <rfc2119>must</rfc2119> 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 <rfc2119>must</rfc2119> 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"/>
  <p:output port="result" primary="true"/>
  <p:output port="secondary" sequence="true"/>
  <p:option name="initial-mode" e:type="xsd:QName"/>
  <p:option name="template-name" e:type="xsd:QName"/>
  <p:option name="output-base-uri" e:type="xsd:anyURI"/>
  <p:option name="version" e:type="xsd:string"/>
</p:declare-step>
 
<para>If present, the value of the <option>initial-mode</option>
option <rfc2119>must</rfc2119> be a <type>QName</type>.</para>
 
<para>If present, the value of the <option>template-name</option>
option <rfc2119>must</rfc2119> be a <type>QName</type>.</para>
 
<para>If present, the value of the <option>output-base-uri</option>
option <rfc2119>must</rfc2119> be an <type>anyURI</type>. If it is
relative, it is made absolute against the base URI of the element on
which it is specified (<tag>p:with-option</tag> or <tag>p:xslt</tag> in the
case of a <link linkend="option-shortcut">syntactic shortcut</link>
value).</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. Any
parameters passed on the <port>parameters</port> port are used to
define top-level stylesheet parameters. 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 used as the
primary input document. The whole sequence is also the default
collection.
If no documents are provided on the <port>source</port> port,
the primary input document is undefined and the default collection
is empty.
<error code="C0039">It is a
<glossterm>dynamic error</glossterm> if a sequence of documents (including
an empty sequence) 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>

<para>If XSLT 2.0 is used, the outputs of this step
<rfc2119>may</rfc2119> include PSVI annotations.</para>


<para>The static and initial dynamic contexts of the XSLT processor
are the contexts defined in <xref linkend="step-xpath-context-10"/>
for an XSLT 1.0 processor and
<xref linkend="step-xpath-context-20"/> for an XSLT 2.0 processor
with the following adjustments.</para>

<para>The dynamic context is augmented as follows:</para>

<variablelist>
<varlistentry>
<term>Context item</term>
<listitem>
<para>The first document that appears on the <port>source</port> port.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Variable values</term>
<listitem>
<para>Any parameters
passed on the <port>parameters</port> port are available as variable bindings
to the XSLT processor.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Function implementations</term>
<listitem>
<para>The function implementations provided by the XSLT processor.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Default collection</term>
<listitem>
<para>The sequence of documents provided on the <port>source</port> port.
</para>
</listitem>
</varlistentry>
</variablelist>
</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:output port="exit-status"/>
  <p:option name="command" required="true" e:type="xsd:string"/>
  <p:option name="args" select="''" e:type="xsd:string"/>
  <p:option name="cwd" e:type="xsd:string"/>
  <p:option name="source-is-xml" select="'true'" e:type="xsd:boolean"/>
  <p:option name="result-is-xml" select="'true'" e:type="xsd:boolean"/>
  <p:option name="wrap-result-lines" select="'false'" e:type="xsd:boolean"/>
  <p:option name="errors-is-xml" select="'false'" e:type="xsd:boolean"/>
  <p:option name="wrap-error-lines" select="'false'" e:type="xsd:boolean"/>
  <p:option name="path-separator" e:type="xsd:string"/>
  <p:option name="failure-threshold" e:type="xsd:integer"/>
  <p:option name="arg-separator" select="' '" e:type="xsd:string"/>
  
  <!-- plus the serialization options -->
  &serialization-options;
</p:declare-step>  

<para>The values of the <option>command</option>, <option>args</option>,
<option>cwd</option>, <option>path-separator</option>, and
<option>arg-separator</option> options <rfc2119>must</rfc2119> be strings.</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>. The processor does not interpolate the values
of the <option>command</option> or <option>args</option> (for example,
expanding references to environment variables).
<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>path-separator</option> option is specified,
every occurrence of the character identified as the
<option>path-separator</option> character that occurs in the
<option>command</option>, <option>args</option>, or
<option>cwd</option> will be replaced by the platform-specific path
separator character. <error code="C0063">It is a <glossterm>dynamic
error</glossterm> if the <option>path-separator</option> option is
specified and is not exactly one character long.</error>
</para>

<para>The value of the <option>args</option> option is a string. In
order to support passing more than one argument to a command, the
<option>args</option> string is broken into a sequence of values.
The <option>arg-separator</option> option specifies the character
that is used to separate values; by default it is a single space
<error code="C0066">It is a <glossterm>dynamic error</glossterm> if
the <option>arg-separator</option> option is specified and is not
exactly one character long.</error>
</para>

<para>The following examples of <tag>p:exec</tag> are equivalent. The
first uses the default <option>arg-separator</option>:</para>

<programlisting>&lt;p:exec command="someCommand" args="arg1 arg2 arg3"/&gt;
</programlisting>

<para>The second specifies an alternate separator:</para>

<programlisting>&lt;p:exec command="someCommand" args="arg1,arg2,arg3"
	arg-separator=","/&gt;
</programlisting>

<para>If one of the arguments contains a space (e.g., a filename that
contains a space), then you must specify an alternate separator.</para>

<para>The <port>source</port> port is declared to accept a sequence so that
  it can be empty. If no document appears on the <port>source</port> port, then the
  command receives nothing on standard input. If a document does arrive on the <port>source</port> port,
  it will
be passed to the command as its standard input. <error code="D0006">It is a <glossterm>dynamic error</glossterm> if
more than one document appears on the <port>source</port> port of the <tag>p:exec</tag> step.</error>
  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 <port>exit-status</port> port always returns a single
<tag>c:result</tag> element which contains the system exit status that
the process returned. <impl>The specific exit status values returned by
a process invoked with <tag>p:exec</tag> are
<glossterm>implementation-dependent</glossterm>.</impl></para>

<para>If a <option>failure-threshold</option> value is supplied, and the
exit status is greater than that threshold, then the <tag>p:exec</tag>
step <rfc2119>must</rfc2119> fail.
<error code="C0064">It is a <glossterm>dynamic
error</glossterm> if the exit code from the command is greater than
the specified <option>failure-threshold</option> value.</error>
This failure, like any step failure,
can be captured with a <tag>p:try</tag>.</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" e:type="xsd:string"/>
  <p:option name="algorithm" required="true" e:type="xsd:QName"/>
  <p:option name="match" required="true" e:type="XSLTMatchPattern"/>
  <p:option name="version" e:type="xsd:string"/>
</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:
“crc”, “md”, or “sha”.</para>

<para>If a <tag class="attribute">version</tag> is not specified, the
default version is algorithm-defined. For “<literal>crc</literal>” it
is 32, for “<literal>md</literal>” it is 5, for “<literal>sha</literal>”
it is 1.</para>

<para>A hash is constructed from the string specified in the
<option>value</option> option using the specified algorithm and version.
Implementations <rfc2119>must</rfc2119> support 
<biblioref linkend="bib.crc"/>,
<biblioref linkend="rfc1321"/>, and <biblioref linkend="bib.sha"/>
hashes. <impl>It is
<glossterm>implementation-defined</glossterm> what other algorithms are
supported.</impl>
The resulting hash <rfc2119>should</rfc2119> be returned as a string of
hexadecimal characters.
</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>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 (if more than one node
matches, the <emphasis>same</emphasis> hash value is used in each match).
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.
If the attribute is named “<tag class="attribute">xml:base</tag>”, the base URI
of the element <rfc2119>must</rfc2119> also be amended accordingly.</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
<biblioref linkend="bib.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" e:type="XSLTMatchPattern"/>
  <p:option name="version" e:type="xsd:integer"/>
</p:declare-step>

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

<para>If the <option>version</option> is specified, that version of
UUID must be computed. <error code="C0060">It is a <glossterm>dynamic
error</glossterm> if the processor does not support the specified
<option>version</option> of the UUID algorithm.</error> <impl>If the
<option>version</option> is not specified, the version of UUID
computed is
<glossterm>implementation-defined</glossterm>.</impl></para>

<para>Implementations <rfc2119>must</rfc2119> support version 4 UUIDs.
<impl>Support for other versions of UUID, and the mechanism by which
the necessary inputs are made available for computing other versions,
is <glossterm>implementation-defined</glossterm>.</impl>
</para>
 
<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 (if more than one node matches, the
<emphasis>same</emphasis> UUID is used in each match). 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. If the attribute is named “<tag class="attribute">xml:base</tag>”, the base URI of the element
<rfc2119>must</rfc2119> also be amended accordingly.</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-attribute-values" select="'false'" e:type="xsd:boolean"/>
  <p:option name="dtd-id-idref-warnings" select="'false'" e:type="xsd:boolean"/>
  <p:option name="assert-valid" select="'true'" e:type="xsd:boolean"/>
</p:declare-step>
 
<para>The values of the <option>dtd-attribute-values</option> and
<option>dtd-id-idref-warnings</option> options
<rfc2119>must</rfc2119> be booleans.</para>

<para>If the root element of the schema is <tag>c:data</tag> or
has a <tag class="attribute">c:content-type</tag> attribute that specifies
a text content type or a media type that the implementation recognizes,
then the step <rfc2119>should</rfc2119> treat the
text node descendants of the element as a
<biblioref linkend="relaxng-compact-syntax"/> document for validation.</para>

<para>If the <option>dtd-attribute-values</option> option is
<literal>true</literal>, then the attribute value defaulting conventions of
<biblioref linkend="relaxng-dtd-compat"/> are also applied.</para>

<para>If the <option>dtd-id-idref-warnings</option> option is
<literal>true</literal>, then the validator <rfc2119>should</rfc2119> 
treat a schema that is incompatible with the ID/IDREF/IDREFs feature
of <biblioref linkend="relaxng-dtd-compat"/> as if the document
was invalid.
</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"/>. The output of this step
<rfc2119>may</rfc2119> include PSVI annotations.</para>

<para><impl>Support for <biblioref linkend="relaxng-dtd-compat"/> is
<glossterm>implementation defined</glossterm>.</impl></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="parameters" kind="parameter"/>
  <p:input port="source" primary="true"/>
  <p:input port="schema"/>
  <p:output port="result" primary="true"/>
  <p:output port="report" sequence="true"/>
  <p:option name="phase" select="'#ALL'" e:type="xsd:string"/>
  <p:option name="assert-valid" select="'true'" e:type="xsd:boolean"/>
</p:declare-step>

<para><error code="C0054">It is a <glossterm>dynamic error</glossterm>
if the <option>assert-valid</option> option is <literal>true</literal>
and any Schematron assertions fail.</error></para>

<para>The value of the <option>phase</option> option identifies the
Schematron validation phase with which validation begins.</para>

<para>The <port>parameters</port> port provides name/value pairs which
correspond to Schematron external variables.</para>

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

<para>Schematron assertions and reports, if any,
<rfc2119>must</rfc2119> appear on the <port>report</port> port. The
output <rfc2119>should</rfc2119> be in <citetitle>Schematron
Validation Report Language</citetitle> (SVRL).</para>

<para>The output of this step
<rfc2119>may</rfc2119> include PSVI annotations.</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="use-location-hints" select="'false'" e:type="xsd:boolean"/>
  <p:option name="try-namespaces" select="'false'" e:type="xsd:boolean"/>
  <p:option name="assert-valid" select="'true'" e:type="xsd:boolean"/>
  <p:option name="mode" select="'strict'" e:type="strict|lax"/>
</p:declare-step>
 
<para>The values of the <option>use-location-hints</option>,
<option>try-namespaces</option>, and 
<option>assert-valid</option>
options
 <rfc2119>must</rfc2119> be boolean.</para>
 
<para>The value of the <option>mode</option> option
<rfc2119>must</rfc2119> 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. These schemas must
be used in preference to any schema locations provided by schema
location hints encountered during schema validation, that is, schema
locations supplied for <code>xs:import</code> or
<code>xsi:schema-location</code>, or determined by
schema-processor-defined namespace-based strategies, for the
namespaces covered by the documents available on the schemas port.</para>

<para>If <code>xs:include</code> elements occur within the supplied
schema documents, they are treated like any other <link linkend="external-docs">external documents</link>. <impl>It is
<glossterm>implementation-defined</glossterm> if the documents supplied
on the <port>schemas</port> port are considered when resolving
<code>xs:include</code> elements in the schema documents provided.</impl>
</para>

<para>The <option>use-location-hints</option> and
<option>try-namespaces</option> options allow the pipeline author to
control how the schema processor should attempt to locate schema
documents necessary but not provided on the <port>schema</port>
port. Any schema documents provided on the <port>schema</port> port
<rfc2119>must</rfc2119> be used in preference to schema documents
located by other means.</para>

<para>If the <option>use-location-hints</option> option is
“<literal>true</literal>”, the processor <rfc2119>should</rfc2119>
make use of schema location hints to locate schema documents. If the
option is “<literal>false</literal>”, the processor
<rfc2119>should</rfc2119> ignore any such hints.</para>

<para>If the <option>try-namespaces</option> option is
“<literal>true</literal>”, the processor <rfc2119>should</rfc2119>
attempt to dereference the namespace URI to locate schema documents.
If the
option is “<literal>false</literal>”, the processor
<rfc2119>should not</rfc2119> dereference namespace URIs.</para>

<para>The <option>mode</option> option allow the pipeline author to
control how schema validation begins. The “<literal>strict</literal>”
mode means that the document element must be declared and
schema-valid, otherwise it will be treated as invalid. The
“<literal>lax</literal>” mode means that the
absence of a declaration for the document element does not itself
count as an unsuccessful outcome of validation.</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> If the <option>assert-valid</option>
option is <literal>false</literal>, it is not an error for the document
to be invalid. In this case, if the implementation does not
support the PSVI, <tag>p:validate-with-xml-schema</tag> is essentially
just an “identity” step, but if the implementation <emphasis>does</emphasis>
support the PSVI, then the resulting document will have additional type
information (at least for the subtrees that are valid).</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>
</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" e:type="xsd:string"/>
</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:param-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>
<error code="C0061">It is a
<glossterm>dynamic error</glossterm> if the name of any encoded parameter
name is not a valid <type>xs:NCName</type>.</error> In other words, this
step can only decode simple name/value pairs where the names do not contain
colons or any characters that cannot be used in XML names.
</para>

<para>The order of the <tag>c:param</tag> elements in the result is the same
as the order of the encoded parameters, reading from left to right.</para>

<para>If any parameter name occurs more than once in the encoded string,
the resulting parameter set will contain a <tag>c:param</tag> for
each instance. However, only one of these will actually be used if the
parameter set is passed to another step on its <glossterm>parameter
input port</glossterm>.</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" e:type="XSLTMatchPattern"/>
</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 of name/value pairs.
When parameters are encoded into name/value pairs,
<emphasis>only</emphasis> the local name of each parameter is used.
The namespace name is ignored and no prefix or colon appears in the name.
</para>

<para>The parameters are encoded in document order. That is, the first
parameter appears first in the resulting string, the second parameter
second, etc. reading from left to right.</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.
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"/>
  <p:output port="result" sequence="true"/>
</p:declare-step>

<para>If a sequence of documents is provided on the
<port>source</port> port, the first document is used as the
initial context item. The whole sequence is also the default
collection. If no documents are provided on the <port>source</port> port,
the initial context item is undefined and the default collection
is empty.</para>

<para>The <port>query</port> port must receive a single document:</para>

<itemizedlist>
<listitem>
<para>If the document root element is <tag xml:id="cv.query">c:query</tag>, the text
descendants of this element are considered the query.</para>
<e:rng-pattern name="VocabQuery"/>
</listitem>

<listitem>
<para>If the document root element is in the XQueryX namespace, the
document is treated as an XQueryX-encoded query. <impl>Support for
XQueryX is <glossterm>implementation-defined</glossterm>.</impl>
</para>
</listitem>

<listitem>
<para>If the document root element is <tag>c:data</tag> and either
does not have a <tag class="attribute">content-type</tag> attribute or
has a <tag class="attribute">content-type</tag> attribute that
specifies a text content type or a media type that the implementation
recognizes, then the text descendants of this element are considered
the query.</para>
</listitem>

<listitem>
<para>If the document root element is not <tag>c:data</tag> but
has a <tag class="attribute">c:content-type</tag> attribute that specifies
a text content type or a media type that the implementation recognizes,
then the text descendants of this element are considered
the query.</para>
</listitem>
<listitem>
<para><impl>Otherwise, the interpretation of the query
is <glossterm>implementation-defined</glossterm>.</impl>
</para>
</listitem>
</itemizedlist>

<para>The result of the <tag>p:xquery</tag> step must be a sequence of
documents. <error code="C0057">It is a <glossterm>dynamic
error</glossterm> if the sequence that results from evaluating the XQuery contains
items other than documents and elements.</error> Any elements that appear
in the result sequence will be treated as documents with the element as their
document element.</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>

<para>The output of this step
<rfc2119>may</rfc2119> include PSVI annotations.</para>

<para>The static context of the XQuery processor is augmented in the following 
way:</para>

<variablelist>
<varlistentry>
<term>Statically known default collection type</term>
<listitem>
<para><literal>document()*</literal></para>
</listitem>
</varlistentry>
<varlistentry>
<term>Statically known namespaces:</term>
<listitem>
<para>Unchanged from the implementation defaults. No namespace declarations
in the XProc pipeline are automatically exposed in the static context.
</para>
</listitem>
</varlistentry>
</variablelist>

<para>The dynamic context of the XQuery processor is augmented in the following
way:</para>

<variablelist>
<varlistentry>
<term>Context item</term>
<listitem>
<para>The first document that appears on the <port>source</port> port.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Context position</term>
<listitem>
<para><literal>1</literal>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Context size</term>
<listitem>
<para><literal>1</literal>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Variable values</term>
<listitem>
<para>Any parameters passed on the <port>parameters</port> port
augment any implementation-defined variable bindings known to the XQuery
processor. The parameter values are passed to the XQuery processor as
values of type <type>xs:untypedAtomic</type>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Function implementations</term>
<listitem>
<para>The function implementations provided by the XQuery processor.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Current dateTime</term>
<listitem>
<para><impl>The point in time returned as the current dateTime is
<glossterm>implementation-defined</glossterm>.</impl></para>
</listitem>
</varlistentry>
<varlistentry>
<term>Implicit timezone</term>
<listitem>
<para><impl>The implicit timezone is <glossterm>implementation-defined</glossterm>.
</impl>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Available documents</term>
<listitem>
<para><impl>The set of available documents (those that may be retrieved with a URI)
is <glossterm>implementation-dependent</glossterm>.</impl>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Available collections</term>
<listitem>
<para><impl>The set of available collections
is <glossterm>implementation-dependent</glossterm>.</impl>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Default collection</term>
<listitem>
<para>The sequence of documents provided on the <port>source</port> port.
</para>
</listitem>
</varlistentry>
</variablelist>

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

<para>The following pipeline applies XInclude processing and schema
validation before using XQuery:</para>

<example xml:id="ex.c.xquery">
<title>A Sample Pipeline Document</title>
<programlisting>&lt;p:pipeline xmlns:p="http://www.w3.org/ns/xproc" version="1.0"&gt;

&lt;p:xinclude/&gt;

&lt;p:validate-with-xml-schema name="validate"&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:xquery&gt;
   &lt;p:input port="query"&gt;
      &lt;p:data href="countp.xq" /&gt;
   &lt;/p:input&gt;
&lt;/p:xquery&gt;

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

<para>Where <filename>countp.xq</filename> might contain:</para>

<programlisting>&lt;count&gt;{count(.//p)}&lt;/count&gt;</programlisting>

</section>
</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>href</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"/>
  <p:output port="result" primary="false"/>
  <p:option name="href" required="true" e:type="xsd:anyURI"/>
  <p:option name="content-type" e:type="xsd:string"/>
</p:declare-step>
 
<para>The value of the <option>href</option> option
<rfc2119>must</rfc2119> be an <type>anyURI</type>. If it is relative,
it is made absolute against the base URI of the element on which it is
specified (<tag>p:with-option</tag> or <tag>p:xsl-formatter</tag> in the
case of a <link linkend="option-shortcut">syntactic shortcut</link>
value).</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>

<variablelist>
<varlistentry>
<term><option>byte-order-mark</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a boolean.
If it's not specified, the default varies by encoding: for UTF-16 it's
true, for all others, it's false.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>cdata-section-elements</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a list of
<type>QName</type>s. They are interpreted as elements name.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>doctype-public</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a string.
The public identifier of the doctype.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>doctype-system</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be an
<type>anyURI</type>. The system identifier of the doctype. It need not
be absolute, and is not resolved.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>encoding</option></term>
<listitem>
<para>A character set name. <impl>If no <option>encoding</option> is
specified, the encoding used is <glossterm>implementation
defined</glossterm>. If the <option>method</option> is
“<literal>xml</literal>” or “<literal>xhtml</literal>”, the
implementation defined encoding <rfc2119>must</rfc2119> be either
UTF-8 or UTF-16.</impl></para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>escape-uri-attributes</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a
boolean. It is ignored unless the specified method is
“<literal>xhtml</literal>” or “<literal>html</literal>”.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>include-content-type</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a boolean.
It is ignored unless the specified method is
“<literal>xhtml</literal>” or “<literal>html</literal>”.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>indent</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a
boolean.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>media-type</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a string. It
specifies the media type (MIME content type). If not specified, the
default varies according to the <option>method</option>:</para>

<variablelist>
<varlistentry><term><literal>xml</literal></term>
<listitem><simpara><literal>application/xml</literal></simpara></listitem>
</varlistentry>
<varlistentry><term><literal>html</literal></term>
<listitem><simpara><literal>text/html</literal></simpara></listitem>
</varlistentry>
<varlistentry><term><literal>xhtml</literal></term>
<listitem><simpara><literal>application/xhtml+xml</literal></simpara></listitem>
</varlistentry>
<varlistentry><term><literal>text</literal></term>
<listitem><simpara><literal>text/plain</literal></simpara></listitem>
</varlistentry>
</variablelist>

<para><impl>For methods other than <literal>xml</literal>, <literal>html</literal>,
<literal>xhtml</literal>, and <literal>text</literal>; the
<option>media-type</option> is <glossterm>implementation defined</glossterm>.
</impl></para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>method</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a
<type>QName</type>. It specifies the serialization method.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>normalization-form</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> 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.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>omit-xml-declaration</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a
boolean.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>standalone</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be an NMTOKEN,
one of the enumerated values <code>true</code>, <code>false</code>, or
<code>omit</code>.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>undeclare-prefixes</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a
boolean.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>version</option></term>
<listitem>
<para>The value of this option <rfc2119>must</rfc2119> be a
string.</para>
</listitem>
</varlistentry>
</variablelist>

<para>In order to be consistent with the rest of this specification,
boolean values for the serialization parameters must use one of the
XML Schema lexical forms for boolean: "true", "false", "1", or "0".
This is different from the <biblioref linkend="xml-serialization"/>
  specification which 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 is 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>
</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 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 xmlns="http://docbook.org/ns/docbook" 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>

<section xml:id="normative-references">
<title>Normative References</title>

<bibliolist>
<bibliomixed xml:id="use-cases"><abbrev>XProc Requirements</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xproc-requirements/">XML
Processing Model Requirements and Use Cases</citetitle>.
Alex Milowski, editor. W3C Working Draft 11 April 2006.
</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 (Fifth Edition)</citetitle>. Tim Bray,
Jean Paoli, C. M. Sperberg-McQueen, et. al.
editors. W3C Recommendation 26 November 2008.</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 (Third Edition)</citetitle>. Tim Bray,
Dave Hollander, Andrew Layman, et. al.,
editors. W3C Recommendation 8 December 2009.</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-datamodel"><abbrev>XQuery 1.0 and XPath 2.0 Data
Model (XDM)</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xpath-datamodel/">XQuery 1.0 and
XPath 2.0 Data Model (XDM)</citetitle>.
Mary Fernández, Ashok Malhotra, Jonathan Marsh, <foreignphrase>et. al.</foreignphrase>, 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 xlink:href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=52348">ISO/IEC 19757-2:2008(E)
Document Schema Definition Language (DSDL) -- Part 2:
Regular-grammar-based
validation -- RELAX NG</citetitle>
2008.
</bibliomixed>

<bibliomixed xml:id="relaxng-compact-syntax"><abbrev>RELAX NG
Compact Syntax</abbrev>ISO/IEC JTC 1/SC 34.
<citetitle>ISO/IEC 19757-2:2003/Amd 1:2006 Document Schema Definition
Languages (DSDL) — Part 2: Grammar-based validation — RELAX NG AMENDMENT 1
Compact Syntax</citetitle>
2006.
</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 19757-3:2006(E) Document Schema Definition
Languages (DSDL) — Part 3: Rule-based validation — Schematron</citetitle>
2006.
</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:
Datatypes 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 2006.</bibliomixed>

<bibliomixed xml:id="xml-base"><abbrev>XML Base</abbrev>
<citetitle xlink:href="http://www.w3.org/TR/xmlbase/">XML Base
(Second Edition)</citetitle>.
Jonathan Marsh and Richard Tobin, editors.
W3C Recommendation. 28 January 2009.</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>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="rfc1321"><abbrev>MD5</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc1321.txt">RFC 1321:
The MD5 Message-Digest Algorithm</citetitle>.
R. Rivest. Network Working Group, IETF, April 1992.</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, 1993.</bibliomixed>

<bibliomixed xml:id="rfc2119"><abbrev>RFC 2119</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc2119.txt">Key words for use in RFCs to Indicate Requirement Levels</citetitle>.
S. Bradner.
Network Working Group, IETF,
Mar 1997.
</bibliomixed>

<bibliomixed xml:id="rfc2396"><abbrev>RFC 2396</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc2396.txt">Uniform Resource Identifiers (URI): Generic Syntax</citetitle>.
T. Berners-Lee, R. Fielding, and L. Masinter.
Network Working Group, IETF,
Aug 1998.
</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 (IRIs)</citetitle>.
M. Duerst and M. Suignard, editors.
Internet Engineering Task Force. January, 2005.</bibliomixed>

<bibliomixed xml:id="unicodetr17"><abbrev>Unicode TR#17</abbrev>
<citetitle xlink:href="http://unicode.org/reports/tr17/">Unicode Technical
Report #17: Character Encoding Model</citetitle>.
Ken Whistler, Mark Davis, and Asmus Freytag, authors.
The Unicode Consortium. 11 November 2008.</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>

<bibliomixed xml:id="bib.uuid"><abbrev>UUID</abbrev>
<citetitle xlink:href="http://www.itu.int/ITU-T/studygroups/com17/oid.html">ITU
X.667: Information technology - Open Systems Interconnection -
Procedures for the operation of OSI Registration Authorities:
Generation and registration of Universally Unique Identifiers (UUIDs)
and their use as ASN.1 Object Identifier components</citetitle>.
2004.</bibliomixed>

<bibliomixed xml:id="bib.sha"><abbrev>SHA1</abbrev>
<citetitle xlink:href="http://www.itl.nist.gov/fipspubs/fip180-1.htm">Federal Information Processing Standards Publication 180-1: Secure Hash Standard</citetitle>.
1995.</bibliomixed>

</bibliolist>
</section>

<section xml:id="informative-references">
<title>Informative References</title>

<bibliolist>
<bibliomixed xml:id="rfc4122"><abbrev>RFC 4122</abbrev>
<citetitle xlink:href="http://www.ietf.org/rfc/rfc4122.txt">RFC 4122:
A Universally Unique IDentifier (UUID) URN Namespace</citetitle>.
P. Leach and M. Mealling, editors.
Internet Engineering Task Force. July, 2005.</bibliomixed>

<bibliomixed xml:id="bib.crc"><abbrev>CRC32</abbrev>
“32-Bit Cyclic Redundancy Codes for Internet Applications”,
<citetitle>The International Conference on Dependable Systems and Networks:
459</citetitle>. <biblioid class="doi">10.1109/DSN.2002.1028931</biblioid>.
P. Koopman. June 2002.
</bibliomixed>
</bibliolist>
</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>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>ancestors</glossterm><glossdef><para>The <firstterm>ancestors</firstterm> of a step, if it has
          any, are its <glossterm>container</glossterm> and the ancestors of its
          container.</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
            <glossterm>subpipeline</glossterm>. </para></glossdef></glossentry><glossentry><glossterm>bag-merger</glossterm><glossdef><para>The <firstterm>bag-merger</firstterm> of two or more bags
        (where a bag is an unordered list or, equivalently, something like a set except that it may
        contain duplicates) is a bag constructed by starting with an empty bag and adding each
        member of each of the input bags in turn to it. It follows that the cardinality of the
        result is the sum of the cardinality of all the input bags.</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>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>compound step</glossterm><glossdef><para>A <firstterm>compound step</firstterm> is a step that
          contains a <glossterm>subpipeline</glossterm>.</para></glossdef></glossentry><glossentry><glossterm>connection</glossterm><glossdef><para>A <firstterm>connection</firstterm> associates an input
          or output port with some data source.</para></glossdef></glossentry><glossentry><glossterm>contained
            steps</glossterm><glossdef><para>The steps that occur directly within, or within
          non-step wrappers directly within, a step are called that step's <firstterm>contained
            steps</firstterm>. In other words, “container” and “contained steps” are inverse
          relationships.</para></glossdef></glossentry><glossentry><glossterm>container</glossterm><glossdef><para>A compound step or multi-container step is a
            <firstterm>container</firstterm> for the steps directly within it or within non-step
          wrappers directly within it.</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, an undefined default readable port and no in-scope
          bindings.</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> is a
          context-dependent collection of information available within subpipelines.</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>in-scope bindings</glossterm><glossdef><para>The
                <firstterm>in-scope bindings</firstterm> are a set of name-value pairs, based on
                <glossterm>option</glossterm> and <glossterm>variable</glossterm>
              bindings.</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 to which it connects.</para></glossdef></glossentry><glossentry><glossterm>last step</glossterm><glossdef><para>The <firstterm>last step</firstterm> in a subpipeline is its
          last step in document order.</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>multi-container
            step</glossterm><glossdef><para>A <firstterm>multi-container
            step</firstterm> is a step that contains several alternate <glossterm baseform="subpipeline">subpipelines</glossterm>. </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 or
            <type>xs:untypedAtomic</type>.</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 or
            <type>xs:untypedAtomic</type>.</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
            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>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>readable
                ports</glossterm><glossdef><para>The <firstterm>readable
                ports</firstterm> are a set of step name/port name pairs.</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:with-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>step type exports</glossterm><glossdef><para>The <firstterm>step type exports</firstterm> of an
        XProc element, against the background of a set of URIs of resources already visited (call
        this set <emphasis>Visited</emphasis>), are defined by cases.</para></glossdef></glossentry><glossentry><glossterm>subpipeline</glossterm><glossdef><para>Sibling steps (and the connections between them) form a
            <firstterm>subpipeline</firstterm>.</para></glossdef></glossentry><glossentry><glossterm>variable</glossterm><glossdef><para>A <firstterm>variable</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 or
            <type>xs:untypedAtomic</type>.</para></glossdef></glossentry><glossentry><glossterm>visible</glossterm><glossdef><para>If two names are in the same scope, we say that they
          are <firstterm>visible</firstterm> to each other. </para></glossdef></glossentry></glosslist></appendix>
  <appendix xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" 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 xmlns="http://docbook.org/ns/docbook" xml:id="errors-list">
<title>List of Error Codes</title>

<para>The following error codes are defined by this specification.</para>

<section xml:id="app.static-errors">
<title>Static Errors</title>

<para>The following <glossterm baseform="static-error">static errors</glossterm>
are defined:</para>

<?static-error-list?>
</section>

<section xml:id="app.dynamic-errors">
<title>Dynamic Errors</title>

<para>The following <glossterm baseform="dynamic-error">dynamic errors</glossterm>
are defined:</para>

<?dynamic-error-list?>
</section>

<section xml:id="app.step-errors">
<title>Step Errors</title>

<para>The following <glossterm baseform="dynamic-error">dynamic errors</glossterm>
can be raised by steps in this specification:</para>

<?step-error-list?>
</section>
</appendix>
  <appendix xmlns="http://docbook.org/ns/docbook" 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>
  <appendix xml:id="handling-imports">
    <title>Handling Circular and Re-entrant Library Imports (Non-Normative)</title>
    <para>When handling imports, an implementation needs to be able to detect the following
      situations, and distinguish them from cases where multiple import chains produce genuinely
      conflicting step definitions:</para>
    <orderedlist>
      <listitem>
        <para>Circular imports: A imports B, B imports A.</para>
      </listitem>
      <listitem>
        <para>Re-entrant imports: A imports B and C, B imports D, C imports D.</para>
      </listitem>
    </orderedlist>
    <para>One way to achieve this is as follows:</para>
    <para><termdef xml:id="dt-step-type-exports">The <firstterm>step type exports</firstterm> of an
        XProc element, against the background of a set of URIs of resources already visited (call
        this set <emphasis>Visited</emphasis>), are defined by cases.</termdef></para>
    <para>The <link linkend="dt-step-type-exports">step type exports</link> of an XProc element are
      as follows:</para>
    <variablelist>
      <varlistentry>
        <term>p:pipeline, p:declare-step</term>
        <listitem>
          <para>A singleton bag containing the <code>type</code> of the element</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>p:library</term>
        <listitem>
          <para>The <glossterm>bag-merger</glossterm> of the <glossterm>step type
              exports</glossterm> of all the element's children</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>p:import</term>
        <listitem>
          <para>Let <emphasis>RU</emphasis> be the actual resolved URI of the resource identified by
            the <code>href</code> of the element. If <emphasis>RU</emphasis> is a member of
              <emphasis>Visited</emphasis>, then an empty bag, otherwise update
              <emphasis>Visited</emphasis> by adding <emphasis>RU</emphasis> to it, and return the
              <glossterm>step type exports</glossterm> of the document element of the retrieved
            representation</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>all other elements</term>
        <listitem>
          <para>An empty bag</para>
        </listitem>
      </varlistentry>
    </variablelist>
    <para>The changes to <emphasis>Visited</emphasis> mandated by the <code>p:import</code> case
      above are persistent, not scoped. That is, not only the recursive processing of the imported
      resource but also subsequent processing of siblings and ancestors must be against the
      background of the updated value. In practice this means either using a side-effected global
      variable, or not only passing <emphasis>Visited</emphasis> as an argument to any recursive or
      iterative processing, but also <emphasis>returning</emphasis> its updated value for subsequent
      use, along with the bag of step types.</para>
    <para>Given a pipeline library document with actual resolved URI <emphasis>DU</emphasis>, <error code="S0036">it is a <glossterm>static error</glossterm> if the <glossterm>step type
          exports</glossterm> of the document element of the retrieved representation, against the
        background of a singleton set containing <emphasis>DU</emphasis> as the initial
          <emphasis>Visited</emphasis> set, contains any duplicates.</error></para>
    <para>Given a top-level pipeline document with actual resolved URI <emphasis>DU</emphasis>,
        <error code="S0036">it is a <glossterm>static error</glossterm> if the
          <glossterm>bag-merger</glossterm> of the <glossterm>step type exports</glossterm> of the
        document element of the retrieved representation with the <glossterm>step type
          exports</glossterm> of its children, against the background of a singleton set containing
          <emphasis>DU</emphasis> as the initial <emphasis>Visited</emphasis> set, contains any
        duplicates.</error></para>
    <para>Given a non-top-level <code>p:pipeline</code> or <code>p:declare-step</code> element,
        <error code="S0036">it is a <glossterm>static error</glossterm> if the
          <glossterm>bag-merger</glossterm> of the <glossterm>step type exports</glossterm> of its
        parent with the <glossterm>step type exports</glossterm> of its children, against the
        background of a copy of the <emphasis>Visited</emphasis> set of its parent as the initial
          <emphasis>Visited</emphasis> set, contains any duplicates.</error></para>
    <para>The phrase "a copy of the <emphasis>Visited</emphasis> set" in the preceding paragraph is
      meant to indicate that checking of non-top-level <code>p:pipeline</code> or
        <code>p:declare-step</code> elements does <emphasis>not</emphasis> have a persistent impact
      on the checking of its parent. The contrast is that whereas changes to
        <emphasis>Visited</emphasis> pass both up <emphasis>and</emphasis> down through
        <code>p:import</code>, they pass only <emphasis>down</emphasis> through
        <emphasis>p:pipeline</emphasis> and <emphasis>p:declare-step</emphasis>.</para>
    <para><termdef xml:id="dt-bag-merger">The <firstterm>bag-merger</firstterm> of two or more bags
        (where a bag is an unordered list or, equivalently, something like a set except that it may
        contain duplicates) is a bag constructed by starting with an empty bag and adding each
        member of each of the input bags in turn to it. It follows that the cardinality of the
        result is the sum of the cardinality of all the input bags.</termdef></para>
  </appendix>
  <appendix xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0-extension w3c-xproc" xml:id="parallelism">
<title>Sequential steps, parallelism, and side-effects</title>

<para>XProc imposes as few constraints on the order in which steps
must be evaluated as possible and almost no constraints on parallel
execution.</para>

<para>In the simple, and we believe overwhelmingly common case, inputs
flow into the pipeline, through the pipeline from one step to the
next, and results are produced at the end. The order of the steps is
constrained by the input/output connections between them.
Implementations are free to execute them in a purely sequential
fashion or in parallel, as they see fit. The results are the same in
either case.</para>

<para>This is not true for pipelines which rely on side effects, such
as the state of the filesystem or the state of the web. Consider
the following pipeline:</para>

<programlisting>&lt;p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
	    version="1.0"
	    name="main"&gt;

  &lt;p:xslt name="generate-stylesheet"&gt;
    &lt;p:input port="source"&gt;
      &lt;p:document href="someURI"/&gt;
    &lt;/p:input&gt;
    &lt;p:input port="stylesheet"&gt;
      &lt;p:document href="someOtherURI"/&gt;
    &lt;/p:input&gt;
  &lt;/p:xslt&gt;

  &lt;p:store name="save-xslt" href="gen-style.xsl"/&gt;

  &lt;p:xslt name="style"&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="gen-style.xsl"/&gt;
    &lt;/p:input&gt;
  &lt;/p:xslt&gt;
&lt;/p:pipeline&gt;
</programlisting>

<para>There's no guarantee that “style” step will execute after the
“save-xslt” step. In this case, the solution is straightforward. Even
if you need the saved stylesheet, you don't need to rely on it in your
pipeline:</para>

<programlisting>&lt;p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
	    version="1.0"
	    name="main"&gt;

  &lt;p:xslt name="generate-stylesheet"&gt;
    &lt;p:input port="source"&gt;
      &lt;p:document href="someURI"/&gt;
    &lt;/p:input&gt;
    &lt;p:input port="stylesheet"&gt;
      &lt;p:document href="someOtherURI"/&gt;
    &lt;/p:input&gt;
  &lt;/p:xslt&gt;

  &lt;p:store name="save-xslt" href="gen-style.xsl"/&gt;

  &lt;p:xslt name="style"&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:pipe step="generate-stylesheet" port="result"/&gt;
    &lt;/p:input&gt;
  &lt;/p:xslt&gt;
&lt;/p:pipeline&gt;
</programlisting>

<para>Now the result is independent of the implementation strategy.</para>

<para>Implementations are free to invent additional control structures
using <tag>p:pipeinfo</tag> and
<link linkend="extension-attributes">extension attributes</link> to provide
greater control over parallelism in their implementations.</para>

</appendix>
  <appendix xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0-extension w3c-xproc" xml:id="xproc-media-type">
<title>The <code>application/xproc+xml</code> 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 <xref linkend="rfc3023"/> or its successors.
</para>
  </listitem>
  </varlistentry>
  </variablelist>
</listitem>
</varlistentry>

<varlistentry>
<term>Encoding considerations:</term>
<listitem>
<para>By virtue of XProc content being XML, it has the same
considerations when sent as <quote><code>application/xproc+xml</code></quote>
as does XML. See <xref linkend="rfc3023"/>, Section 3.2.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Security considerations:</term>
<listitem>
<para>Several XProc elements may refer to arbitrary URIs.
In this case, the security issues of <xref linkend="rfc2396"/>, section 7,
should be considered.</para>

<para>In addition, because of the extensibility features of XProc, it
is possible that “application/xproc+xml” may describe content that has
security implications beyond those described here. However, only in
the case where the processor recognizes and processes the additional
content, or where further processing of that content is dispatched to
other processors, would security issues potentially arise. And in that
case, they would fall outside the domain of this registration
document.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Interoperability considerations:</term>
<listitem>
<para>This specification describes processing semantics that dictate
behavior that must be followed when dealing with, among other things,
unrecognized elements.</para>

<para>Because XProc is extensible, conformant "application/xproc+xml"
processors can expect that content received is well-formed XML, but it
cannot be guaranteed that the content is valid XProc or that the
processor will recognize all of the elements and attributes in the
document.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>Published specification:</term>
<listitem>
<para>This media type registration is for XProc documents as described by
this specification which is located at
<link xlink:href="http://www.w3.org/TR/xproc"/>.</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>Norman Walsh, <email>Norman.Walsh@MarkLogic.com</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 World Wide Web
Consortium's XML Processing Model Working Group. The W3C has change control
over these specifications.</para>
</listitem>
</varlistentry>
</variablelist>
</section>

<section xml:id="fragid">
<title>Fragment Identifiers</title>

<para>For documents labeled as
<quote><code>application/xproc+xml</code></quote>,
the fragment
identifier notation is exactly that for
<quote><code>application/xml</code></quote>,
as specified in <xref linkend="rfc3023"/> or its successors.</para>
</section>
</appendix>
</specification>
