<?xml version="1.0" encoding="UTF-8"?>
<essay xml:lang="en" version="5.0" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:gal="http://norman.walsh.name/rdf/gallery#" xmlns:foaf="http://xmlns.com/foaf/0.1/">
<info>
    
    
    
    
    
    
    
    
<title>XProc parameters</title><biblioid class="uri">http://norman.walsh.name/2007/06/13/xprocParameters</biblioid>
<volumenum>10</volumenum>
<issuenum>58</issuenum>
<pubdate>2007-06-13T14:00:13-04:00</pubdate>
<date>$Date: 2007-06-13 15:52:50 -0400 (Wed, 13 Jun 2007) $</date>
<author>
      <personname>
<firstname>Norman</firstname>
	<surname>Walsh</surname>
</personname>
    </author>
<copyright>
      <year>2007</year>
      <holder>Norman Walsh</holder>
    </copyright>
<abstract>
<para>Dealing with command line options and parameters turns out to be trickier
than it looks.</para>
</abstract>
<dc:subject rdf:resource="http://norman.walsh.name/knows/taxonomy#XML"/>
<dc:subject rdf:resource="http://norman.walsh.name/knows/taxonomy#XProc"/>
</info>

<para xml:id="p1">The working group has spent a gruelling few weeks
(well, gruelling for the chair, at least) hashing out a story about
parameters. Herein, an overview of the decisions we made.
Fair warning: as of 13 June 2007, what's discussed
in this essay is not yet in any public working draft.<footnote>
      <para xml:id="p2">The
XProc WG works <link xlink:href="http://www.w3.org/2005/10/xml-processing-model-wg-charter.html#AEN117">in public</link>. You're welcome to
<link xlink:href="http://lists.w3.org/Archives/Public/public-xml-processing-model-wg/">follow along</link> and read
<link xlink:href="http://www.w3.org/XML/XProc/docs/langspec.html">the editor's
drafts</link>. In other words, I'm not giving away anything not already in the
public record, in case you were wondering.</para>
    </footnote></para>

<para xml:id="p3">Let's start with a little context: what's the whole deal with
options <emphasis>and</emphasis> parameters?</para>

<para xml:id="p4">Options are strings that you can pass to a step, like the <option>match</option>
expression on <tag>p:insert</tag> or the <option>href</option> URI on
<tag>p:load</tag>. They can be static values supplied by the pipeline author or
they can be computed dynamically (using XPath 1.0) in the pipeline. The names of
all the options are known in advance; usually declared as part of
<tag>p:declare-step</tag>. Options are lexically scoped.</para>

<para xml:id="p5">Parameters, like options, are name/value pairs that you can pass
to a step. Unlike options, the names of parameters aren't
(necessarily) known in advance to the pipeline author.</para>

<para xml:id="p6">Parameters exist to satisfy the use case of parameters passed to
an XSLT step. (They're also used by the XQuery step and may be used by additional
steps as well, including extension steps invented by others.)</para>

<para xml:id="p7">Stylesheets can have literally hundreds of parameters.
The <link xlink:href="http://docbook.sourceforge.net/">DocBook XSL
Stylesheets</link> have more than six hundred. The
working group is convinced that we need to support the use case where
an XSLT step is wrapped in a pipeline and then parameters are passed
to that pipeline (from the command line, for example) and forwarded
to the XSLT step.</para>

<para xml:id="p8">Consider the pipeline in <xref linkend="ex.pipe1"/>.</para>

<example xml:id="ex.pipe1">
<title>Simple XInclude and style pipeline</title>
<programlisting>&lt;p:pipeline name="main" xmlns:p="http://www.w3.org/2007/03/xproc"&gt;
&lt;p:input port="source"/&gt;
&lt;p:output port="result"/&gt;

&lt;p:xinclude/&gt;

&lt;p:xslt&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:document href="docbook.xsl"/&gt;
  &lt;/p:input&gt;
&lt;/p:xslt&gt;

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

<para xml:id="p9">From the user perspective, this simple pipeline represents a
natural evolution from running XSLT directly to running a small
pipeline that does XInclude and then runs XSLT. If we tell the user
that, as a consequence of putting the XSLT step inside the pipeline,
they can no longer pass any parameters to the XSLT step, I think it'll
be very difficult to get users to migrate to XProc.
If we tell them that they have to enumerate all six hundred
or so parameters, I think that'll be a non-starter as well.</para>

<para xml:id="p10">The story in the
<link xlink:href="http://www.w3.org/TR/2007/WD-xproc-20070405/">current
working draft</link> (dated 5 April 2007) is that parameters are
lexically scoped, like options, and they are <emphasis>all</emphasis>
passed to <emphasis>every</emphasis> step.</para>

<para xml:id="p11">Although this is simple, there are two significant problems:</para>

<orderedlist>
<listitem>
<para xml:id="p12">Always passing every in-scope parameter to every step might introduce
unwanted behavior in some steps. There isn't enough granularity of control.
It also makes it more complicated to pass the same parameter with two different values
to two different steps.</para>
</listitem>
<listitem>
<para xml:id="p13">It offers no mechanism for computing parameters dynamically. Given all the
power we've provided to compute and manipulate inputs to steps, it seems a little
odd that you can't compute the parameters you want to pass.</para>
</listitem>
</orderedlist>

<para xml:id="p14">A lot of discussion took place and a range of proposals were considered.
I'll leave
<link xlink:href="http://lists.w3.org/Archives/Public/public-xml-processing-model-wg/">the
mail archives</link> to tell the whole story and limit myself here to only what
was decided.</para>

<para xml:id="p15">First, we've added the notion of a parameter set, not unlike an
XSLT attribute set:</para>

<programlisting>&lt;p:parameter-set name="dbparams"&gt;
  &lt;p:parameter name="base.dir" value="/tmp/"/&gt;
  &lt;p:parameter name="html.ext" value=".htm"/&gt;
&lt;/p:parameter-set&gt;</programlisting>

<para xml:id="p16">Instead of using lexical scoping, we allow the step author to identify
which parameter sets they want:</para>

<programlisting>&lt;p:xslt&gt;
  &lt;p:use-parameter-set name="dbparams"/&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:document href="docbook.xsl"/&gt;
  &lt;/p:input&gt;
&lt;/p:xslt&gt;</programlisting>

<para xml:id="p17">Steps can use more than one parameter set and parameter sets can
be combined by placing a <tag>p:use-parameter-set</tag> inside a
<tag>p:parameter-set</tag>. What's more, you can place a
<tag>p:document</tag>, <tag>p:pipe</tag>, or <tag>p:inline</tag>
inside a <tag>p:parameter-set</tag> too. If you do that, you can load
a set of parameters, possibly a set computed by some other step.
(There's a small XML vocabulary for defining parameters that I won't
attempt to describe here.)</para>

<para xml:id="p18">Now we have a way for pipeline authors to construct sets of parameters
and use them on the steps where they're appropriate. So far so good. But what
about parameters passed to <emphasis>the pipeline</emphasis>, for example, on
the command line, through an API, or on a pipeline that's called from another
pipeline?</para>

<para xml:id="p19">The simplest answer to that question is to provide a name for those
parameters. The special parameter set name “<literal>#pipeline-parameters</literal>”
always refers to the set of parameters passed to the current <tag>p:pipeline</tag>.
</para>

<para xml:id="p20">In order to close the loop on allowing pipelines to perform
computations on sets of parameters, we provide a
<tag>p:parameters</tag> step which has no inputs and provides, on its
single output, all of the parameters passed to it. This step uses the
same XML vocabulary that <tag>p:parameter-set</tag> expects, so you
can read them, filter them, and write them back out to a new
set.</para>

<para xml:id="p21">That's the whole story and, though it may not be the simplest
possible story, experience suggests that's the simplest thing we can
think of which will solve the two most significant requirements for
arbitrary name/value pairs: control over the granularity of use and
the ability to compute them dynamically.</para>

<para xml:id="p22">So far unresolved is the question of what the default behavior should be.
Is the pipeline in <xref linkend="ex.pipe2"/> the same as the one in
<xref linkend="ex.pipe1"/>?</para>

<example xml:id="ex.pipe2">
<title>Pipeline with explicit parameters</title>
<programlisting>&lt;p:pipeline name="main" xmlns:p="http://www.w3.org/2007/03/xproc"&gt;
&lt;p:input port="source"/&gt;
&lt;p:output port="result"/&gt;

&lt;p:xinclude/&gt;

&lt;p:xslt&gt;
  &lt;p:use-parameter-set name="#pipeline-parameters"/&gt;
  &lt;p:input port="stylesheet"&gt;
    &lt;p:document href="docbook.xsl"/&gt;
  &lt;/p:input&gt;
&lt;/p:xslt&gt;

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

<para xml:id="p23">In other words, if no parameters are specified at all, should
the pipeline parameters be inferred, or should no parameters be
inferred?</para>

<para xml:id="p24">The arguments in favor of inferring the pipeline parameters appeal to
ease-of-use, syntactic simplicity, and user expectations. The arguments against
appeal to safety, security, and user expectations.</para>

<para xml:id="p25">I'm on the fence about this one, though I lean towards requiring the
explicit <tag>p:use-parameter-set</tag>. Today, anyway.</para>

</essay>

