RE: Conditional Logic . . . what am I missing?

Hi Christopher,

The main purpose of p:use-when is to allow creating more interoperable pipelines. Suppose you have to rely on some extension step that is available in processor X, but not in processor Y (or it is available in Y, but under a different step type). With p:use-when, you can then do something like this:

<p:pipeline>
  ...
  <ex:stepx p:use-when="p:system-property('p:product-name')='X'">
    ...
  </ex:stepx>
  <ex:stepy p:use-when="p:system-property('p:product-name')='Y'">
    ...
  </ex:stepy>
</p:pipeline>

The use-when expressions are evaluated statically before the pipeline is executed. The effect of use-when is that all elements where the use-when expression evaluates to false will be excluded from the pipeline document.

Regards,
Vojtech

--
Vojtech Toman
Consultant Software Engineer
EMC | Information Intelligence Group
vojtech.toman@emc.com
http://developer.emc.com/xmltech

> -----Original Message-----
> From: Christopher.R.Ball [mailto:christopher.r.ball@gmail.com]
> Sent: Wednesday, May 02, 2012 1:58 AM
> To: Romain Deltour
> Cc: xproc-dev@w3.org
> Subject: Re: Conditional Logic . . . what am I missing?
> 
> Thanks for the clarification.
> 
> But then could you help me understand the purpose of @use-when? I am
> not
> getting the point of a seemingly conditional attribute that "must
> contain an XPath expression that can be evaluated statically"?
> 
> Christopher
> 
> On 5/1/2012 6:41 PM, Romain Deltour wrote:
> > I don't think you're overlooking something. The p:choose with an
> identity in the otherwise branch is a common pattern.
> >
> > Romain.
> >
> > On 1 mai 2012, at 22:51, Christopher.R.Ball wrote:
> >
> >> I need to conditionally include an element in a pipeline and was
> rather surprised that my only option is to use<p:choose>.
> >>
> >> I would have thought I should be able to use 'use-when' but that
> seems to only take static values (which makes me wonder about what it
> is for).
> >>
> >> So I am having to use this:
> >>
> >>    <p:choose>
> >>    <p:when test="$informative-matches = 0">
> >>    <p:insert match="entity/other-searches" position="last-child">
> >>    <p:input port="insertion" select="/entity/music-search"/>
> >>    </p:insert>
> >>    </p:when>
> >>    <p:otherwise>
> >>    <p:identity/>
> >>    </p:otherwise>
> >>    </p:choose>
> >>
> >>
> >> When all I really want is this:
> >>
> >>
> >>    <p:insert match="entity/other-searches" position="last-child"
> >>    use-when"$informative-matches = 0">
> >>    <p:input port="insertion" select="/entity/music-search"/>
> >>    </p:insert>
> >>
> >> Hopefully, I am overlooking something obvious ;)
> >>
> >> Regards,
> >>
> >> Christopher
> >>
> 
> 

Received on Wednesday, 2 May 2012 06:53:05 UTC