Re: Variables and parameters

Hi,

Norm Walsh wrote:
> / Jeni Tennison <jeni@jenitennison.com> was heard to say:
> | A more flexible alternative would be to say that labelled documents are
> | referencable as variables within the XPath expressions used to set parameters
> | or variables.
> 
> Yes, but it puts variables/parameters and input/output labels all into
> the same "symbol space" which worries me a bit.

It doesn't worry me. I think we want parameters and I/O labels to be in
the same symbol space anyway so that we can support a directed syntax 
should we want to in the future.

> | This is more flexible because it means that you can refer to more than one
> | document within the XPath expression.
> 
> Indeed. Is that valuable enough to justify the added complexity?

I think it's simpler. The explanation goes:

   The select attribute of p:param, p:variable, p:step/p:input and
   p:pipeline/p:output holds an XPath expression that provides the value
   of the parameter, variable, input or output. The value of a parameter
   must be a string; it is set to the string value of the result of
   evaluating the XPath expression. The value of an input or output must
   be a node set containing only root (document) nodes [1]; it is an
   error if the XPath evaluates to anything else.

   When evaluating an XPath expression, the context node and the context
   position are undefined: it is an error if the expression references
   them [2]. The variable bindings for the expression are determined by
   variable binding elements that precede the expression. These are:

   - p:pipeline/p:input binds the variable with the name specified in the
     name attribute to a node set containing the root (document) nodes
     passed as that input.

   - p:pipeline/p:param binds the variable with the name specified in the
     name attribute to the (string) value passed as the value of the
     parameter, or to the string value of the result of evaluating the
     XPath in the select attribute if no value is passed for the
     parameter.

   - p:pipeline/p:variable binds the variable with the name specified in
     the name attribute to the result of evaluating the XPath in the
     select attribute.

   - p:step, p:choose, p:for-each, ... bind multiple variables: one for
     each of the <p:output> elements they contain. The variable's name is
     given in the label attribute of <p:output> and its value is a node
     set of root (document) nodes, determined by the component.

This seems to me to be more coherent and less complex for the user than
having to identify a single document to provide the context for an
XPath expression each time you set a variable. It also has the advantage 
that it becomes very easy to perform XPaths over outputs and inputs that 
hold sequences of documents rather than single documents, for example to 
test whether any document contained a particular element:

   <p:when test="$documents//figure">
     ...
   </p:when>

or to filter sequences of documents:

   <p:for-each select="$documents[/chapter]">
     ...
   </p:for-each>

Cheers,

Jeni

[1] Since we're using XPath 1.0, we ought to talk about node sets of 
root nodes rather than sequences of document nodes.

[2] I think we'll want to set the context node and context position 
differently within a <p:for-each>.

-- 
Jeni Tennison
http://www.jenitennison.com

Received on Monday, 22 May 2006 10:40:10 UTC