choose/when

The last time we talked about this at a telcon, the minutes[1] record
three options:

1. The status quo:

  <p:choose name="version">
    <p:input port="source">
      <p:pipe step="prevstep" port="result"/>
    </p:input>

    <p:when test="/*[@version = 1]">
      <p:output port="result">
        <p:pipe step="v1valid" port="result"/>
      </p:output>

      <p:step type="p:validate" name="v1valid">...</p:step>
    </p:when>

    <p:when test="/*[@version = 2]">
      <p:input port="source">
        <p:pipe step="v2valid" port="result"/>
      </p:input>
      <p:output port="result">
        <p:pipe step="v2valid" port="result"/>
      </p:output>

      <p:step type="p:validate" name="v2valid">...</p:step>
    </p:when>
  </p:choose>

(Yes, I've needlessly repeated the input on both the choose and the
second when in order to expose the general case)

2. A nested context with test on the when:

  <p:choose name="version">
    <p:xpath-context>
      <p:pipe step="prevstep" port="result"/>
    </p:xpath-context>

    <p:when test="/*[@version = 1]">
      <p:output port="result">
        <p:pipe step="v1valid" port="result"/>
      </p:output>

      <p:step type="p:validate" name="v1valid">...</p:step>
    </p:when>

    <p:when test="/*[@version = 2]">
      <p:xpath-context>
        <p:pipe step="prevstep" port="result"/>
      </p:xpath-context>
      <p:output port="result">
        <p:pipe step="v2valid" port="result"/>
      </p:output>

      <p:step type="p:validate" name="v2valid">...</p:step>
    </p:when>
  </p:choose>

3. A nested context with test on the context:

  <p:choose name="version">
    <p:xpath-context>
      <p:pipe step="prevstep" port="result"/>
    </p:xpath-context>

    <p:when>
      <p:xpath-context test="/*[@version = 1]">
        <p:pipe step="prevstep" port="result"/>
      </p:xpath-context>
      <p:output port="result">
        <p:pipe step="v1valid" port="result"/>
      </p:output>

      <p:step type="p:validate" name="v1valid">...</p:step>
    </p:when>

    <p:when>
      <p:xpath-context test="/*[@version = 2]">
        <p:pipe step="prevstep" port="result"/>
      </p:xpath-context>
      <p:output port="result">
        <p:pipe step="v2valid" port="result"/>
      </p:output>

      <p:step type="p:validate" name="v2valid">...</p:step>
    </p:when>
  </p:choose>

It seems to me that one problem with option 3 is that it requires the
user to provide the xpath-context element in each and every when in
order to have a place to hang the test attribute.

On that basis, I think the real choice is between options 1 and 2
unless someone has a third option that I've forgotten to list.

Let's pick one tomorrow!

                                        Be seeing you,
                                          norm

[1] http://www.w3.org/XML/XProc/2006/12/21-minutes.html#item05

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

Received on Wednesday, 24 January 2007 17:04:41 UTC