Re: Compute attribute value with set-attribute

It's kind of a shame that in situations the p:with-option select
expression doesn't require any context, the user is still required to
supply one.  For example:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc">

    <p:output port="result"/>

    <p:option name="option-a" select="'Hello'"/>
    <p:option name="option-b" select="'World!'"/>

    <p:add-attribute match="elem" attribute-name="a">
        <p:input port="source">
            <p:inline>
                <elem/>
            </p:inline>
        </p:input>
        <p:with-option name="attribute-value"
select="concat($option-a, ' ', $option-b)">
            <p:empty/>
        </p:with-option>
    </p:add-attribute>

</p:declare-step>

This is a potential gotcha for pipeline writers. On the face of it,
p:empty is superfluous. A solution would be to allow XProc
implementations to conditionally ignore the lack of context when it
doesn't need it.

This is just an idea; I'm not sure if it's actually a good one.  In
practice, I doubt this problem will happen much, since steps generally
have a default readable port available.  And the current approach has
the virtue of consistency, even if it is more verbose.

-James



On Tue, Apr 7, 2009 at 9:27 AM, Florent Georges <fgeorges@gmail.com> wrote:
> 2009/4/7 ? wrote:
>
>> In the first example, you have to use p:empty because there is no
>> default readable port in p:add-attribute (because you are using
>> p:declare-step with no input port for the top-level pipeline).
>
>  Thanks!  I think I got it now.  I think I mixed up the source for
> the step and for the with-option.  The following example shows the
> difference between both:
>
>    <p:identity>
>       <p:input port="source">
>          <p:inline>
>             <what>world</what>
>          </p:inline>
>       </p:input>
>    </p:identity>
>
>    <p:add-attribute match="elem" attribute-name="a">
>       <p:input port="source">
>          <p:inline>
>             <elem/>
>          </p:inline>
>       </p:input>
>       <p:with-option name="attribute-value" select="
>           concat('Hello, ', what, '!')"/>
>    </p:add-attribute>
>
>    ==>
>
>    <elem a="Hello, world!"/>
>
>  Thanks!  Regards,
>
> --
> Florent Georges
> http://www.fgeorges.org/
>
>

Received on Tuesday, 7 April 2009 15:30:34 UTC