Re: How to use p:compare

Norm,

On 18 Sep 2008, at 20:26, Norman Walsh wrote:
> What's the easiest way to write a step that compares two documents and
> returns one of them if they're the same? If they're different, it
> throws an error


Sorry, I see what you want to do from the subject. I guess that the  
problem with:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" name="pipe">
<p:input port="source">
   <p:inline><doc>A</doc></p:inline>
</p:input>
<p:input port="alternate">
   <p:inline><doc>A</doc></p:inline>
</p:input>
<p:output port="result"/>

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

<p:identity>
   <p:input port="source">
     <p:pipe step="pipe" port="source" />
   </p:input>
</p:identity>
</p:declare-step>

is that there's no guarantee that the <p:identity> step will be done  
before the <p:compare> step. It works in Calabash (for some definition  
of 'works'; the error that's given when the documents aren't the same  
isn't particularly helpful). So you probably need to do:

<p:choose>
   <p:when test=". = 'true'">
     <p:xpath-context>
       <p:pipe step="comparison" port="result" />
     </p:xpath-context>
     <p:identity>
       <p:input port="source">
         <p:pipe step="pipe" port="source" />
       </p:input>
     </p:identity>
   </p:when>
   <p:otherwise>
     <p:identity>
       <p:input port="source">
         <p:pipe step="comparison" port="result" />
       </p:input>
     </p:identity>
   </p:otherwise>
</p:choose>

(By the way, Calabash errored when I had the <p:xpath-context> in the  
<p:choose> instead of the <p:when>, which it shouldn't have done.)

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

Received on Thursday, 18 September 2008 20:53:47 UTC