Re: The |result port for p:compare?

James Garriss <james@garriss.org> writes:

> using:  Calabash 0.6.0
>
> When I use a pipeline with a p:compare step, Calabash gives this error:
> Input |result unbound on pipeline step named main and no default binding
> available.
>
> I can make the error go away by inserting this:
>
> <p:input port="|result"/>

Hmm. The fact that Calabash doesn't reject that is a bug.

> But when I look at the spec
> (http://www.w3.org/TR/2008/WD-xproc-20080814/#c.compare), I don¹t see this
> port mentioned.
>
> What am I missing? 

The input ports named "|name" (and output ports named "name|") are an
internal detail in Calabash, they aren't supposed to show up in your
pipeline.

> PS Here¹s my pipeline:

So I'm guessing it looked like this before you added the |result
binding:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" name="main">
    <p:input port="source" primary="true">
        <p:document href="Bookstore.xml"/>
    </p:input>
    <p:input port="alternate">
        <p:document href="BookStoreDupe.xml"/>
    </p:input>
    <p:output port="result"/>
    <p:compare fail-if-not-equal="true">
        <p:input port="source">
            <p:pipe step="main" port="source"/>
        </p:input>
        <p:input port="alternate">
            <p:pipe step="main" port="alternate"/>
        </p:input>
    </p:compare>
</p:declare-step>

The problem here is that the output port of p:compare is not primary. So
it doesn't automaticaly get bound to the main pipeline's "result" port.

This will work:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" name="main">
    <p:input port="source" primary="true">
        <p:document href="Bookstore.xml"/>
    </p:input>
    <p:input port="alternate">
        <p:document href="BookStoreDupe.xml"/>
    </p:input>
    <!-- VVV -->
    <p:output port="result">
      <p:pipe step="compare" port="result"/>
    <p:output>
    <!-- ^^^ -->
    <p:compare name="compare" fail-if-not-equal="true">
        <p:input port="source">
            <p:pipe step="main" port="source"/>
        </p:input>
        <p:input port="alternate">
            <p:pipe step="main" port="alternate"/>
        </p:input>
    </p:compare>
</p:declare-step>

Now you're probably thinking, what the heck is wrong with these people?
Well, the thing is, the output from compare is a c:result, not the identity
transform. So your pipeline as defined above will produce 

  <c:result>true</c:result>

or it will fail. That's probably not what you had in mind. You
probably wanted something like this:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" name="main">
    <p:input port="source" primary="true">
        <p:document href="Bookstore.xml"/>
    </p:input>
    <p:input port="alternate">
        <p:document href="BookStoreDupe.xml"/>
    </p:input>
    <p:output port="result">

    <p:compare name="compare" fail-if-not-equal="true">
        <p:input port="source">
            <p:pipe step="main" port="source"/>
        </p:input>
        <p:input port="alternate">
            <p:pipe step="main" port="alternate"/>
        </p:input>
    </p:compare>

    <p:choose>
      <p:when test=". = 'true'">
        <p:xpath-context>
          <p:pipe step="compare" port="result" />
        </p:xpath-context>
       <p:identity>
         <p:input port="source">
           <p:pipe step="main" port="source" />
         </p:input>
       </p:identity>
     </p:when>
     <p:otherwise>
       <!-- it doesn't really matter what you put here, since compare will
            fail if it isn't true. -->
       <p:identity>
         <p:input port="source">
           <p:pipe step="comparison" port="result" />
         </p:input>
       </p:identity>
     </p:otherwise>
   </p:choose>
</p:declare-step>

This step acts like the identity step on one of its inputs, if and only if
the two inputs are the same.

I admit it's less than elegant.

                                        Be seeing you,
                                          norm

-- 
Norman Walsh <ndw@nwalsh.com> | Talk as if you were making your will:
http://nwalsh.com/            | the fewer the words the less the
                              | litigation.-- Gracián

Received on Friday, 19 September 2008 13:17:48 UTC