Re: Variables/Parameters and Scoping

/ Alessandro Vernet <avernet@orbeon.com> was heard to say:
| On 5/18/06, Alex Milowski <alex@milowski.org> wrote:
|> <p:let default="input-1">
|>
|>     <!-- binds the 'x' parameter for the contained steps -->
|>     <p:parameter name="x" value="blue"/>
|>
|>     <!-- selects from the default input and binds it to 'y' -->
|>     <p:parameter name="y" select="/doc/title"/>
|
| Alex,
|
| Does this mean that if you want 'x' to be based on 'input-1' and 'y'
| on 'input-2' then you need to nested <p:let>? As in:

I don't think so. Alex's original example included

   <!-- selects from the specified input and binds it to 'z' -->
   <p:parameter name="z" input='input-2' select="/doc/@created"/>

I think the default on p:let is just a convenience. I'd propose
dropping it.

| What about just having:
|
| <p:step>
|    <p:with-parm name="a"
|            select="expression on input-1" labelref="input-1"/>
|    <p:with-parm name="b"
|            select="expression on input-2" labelref="input-2"/>
| </p:step>

I think the p:let proposal has the feature that it provides a binding
that applies to a group of steps, not just a single step.

| This would not allow an expression that uses *both* input-1 and
| input-2, hence the proposal of introducing a function instead of the
| 'labelref' attribute (similar to the instance() function introduced by
| XForms):
|
|    <p:step>
|        <p:with-parm name="a" select="expression using
|            label('input-1') and label('input-2')"/>
|    </p:step>

One of the reasons that I favor the approach of naming the document
with a separate attribute is that it prevents expressions with this
level of complexity.

I think it's easy to explain and implement how an expression should be
applied to a single document. Allowing expressions to access arbitrary
documents makes things quite a bit trickier. Either every expression
has to begin with a label('') function or one of the documents has to
be identified as the initial context document. The former is tedious
and the latter is confusing since it won't necessarily be obvious from
the expression which context is the default.

I think I prefer the following semantics:

  <p:with-param name="someName" document="someLabel" select="someExpression"/>

Sets the parameter $someName to the result of evaluating
someExpression with the document identified by someLabel as the
context node.

  <p:with-param name="otherName" select="otherExpression"/>

Sets the parameter $otherName to the result of evaluating
otherExpression with the context node set to an empty document node.

In this case, each individual expression is easy to understand and
implement and there's nothing that prevents a user from building
compound expressions if they need them:

  <p:variable name="a1" document="input-1" select="expr1"/>
  <p:variable name="a2" document="input-2" select="expr2"/>
  <p:with-param name="a" select="expression using $a1 and $a2"/>

                                        Be seeing you,
                                          norm

-- 
Norman Walsh
XML Standards Architect
Sun Microsystems, Inc.

Received on Friday, 19 May 2006 19:30:19 UTC