Re: Inputs and outputs

/ Norman Walsh <Norman.Walsh@Sun.COM> was heard to say:
| I think this also helps us with the choose statement:

My original post had some bugs. Here's a fixed version:

<p:pipeline>
  <!-- accept a document, a schema, and a stylesheet. -->
  <!-- validate, transform, and return the result -->
  <p:declare-input-port port="document" name="xmlfile"/>
  <p:declare-input-port port="schema" name="xsdfile"/>
  <p:declare-input-port port="stylesheet" name="xslfile"/>
  <p:declare-output-port port="result" name="output"/>

  <p:step kind="validate">
    <p:input port="document" from="xmlfile"/>
    <p:input port="schema" from="xsdfile"/>
    <p:output port="result" name="validxml"/>
  </p:step>

  <p:choose>
    <p:declare-input-port port="testdocument" from="validxml"/>
    <p:declare-input-port port="stylein" from="xslfile"/>
    <p:declare-output-port port="result" name="xformed"/>

    <p:when test="/book">
      <p:step kind="xslt">
        <p:input port="document" from="testdocument"/>
        <p:input port="stylesheet" from="stylein"/>
        <p:output port="result" to="xformed"/>
      </p:step>
    </p:when>

    <p:when test="/html">
      <p:step kind="xslt">
        <p:input port="document" from="testdocument"/>
        <p:input port="stylesheet" href="html.xsl"/>
        <p:output port="result" to="xformed"/>
      </p:step>

      <p:step kind="bitbucket">
        <p:input port="document" from="stylein"/>
      </p:step>
    </p:when>
  </p:choose>

  <p:step kind="identity">
    <p:input port="document" from="xformed"/>
    <p:output port="result" to="output"/>
  </p:step>
<p:pipeline>

What I fixed:

  - I used the pipeline's stylesheet port :-)

  - I changed the references to the p:choose so that none of them
    refers to anything outside the p:choose (except the declarations
    at the top). I want it to be an error to point outside the choose.

  - In order to consume the stylein in the second when, I explicitly
    send it to the bit bucket.

Here's another possibility:

<p:pipeline name="pipe">
  <!-- accept a document, a schema, and a stylesheet. -->
  <!-- validate, transform, and return the result -->
  <p:declare-input-port port="document"/>
  <p:declare-input-port port="schema"/>
  <p:declare-input-port port="stylesheet"/>
  <p:declare-output-port port="result" ref="identity.result"/>

  <p:step kind="validate">
    <p:input port="document" ref="pipe.document"/>
    <p:input port="schema" ref="pipe.schema"/>
    <p:output port="result"/>
  </p:step>

  <p:choose name="choice">
    <p:declare-input-port port="testdocument" ref="validate.result"/>
    <p:declare-input-port port="stylein" ref="pipe.stylesheet"/>
    <p:declare-output-port port="result"/>

    <p:when test="/book">
      <p:step kind="xslt">
        <p:input port="document" ref="choice.testdocument"/>
        <p:input port="stylesheet" ref="choice.stylein"/>
        <p:output port="result" ref="choice.result"/>
      </p:step>
    </p:when>

    <p:when test="/html">
      <p:step kind="xslt">
        <p:input port="document" ref="choice.testdocument"/>
        <p:input port="stylesheet" href="html.xsl"/>
        <p:output port="result" ref="choice.result"/>
      </p:step>

      <p:step kind="bitbucket">
        <p:input port="document" ref="choice.stylein"/>
      </p:step>
    </p:when>
  </p:choose>

  <p:step kind="identity">
    <p:input port="document" ref="choice.result"/>
    <p:output port="result"/>
  </p:step>
<p:pipeline>

I've switched to Richard's naming style, which is my 60/40 favorite at
the moment, though I'd use "/" instead of ".".

I've used "ref" consistently instead of "from" and "to". On the one
hand, inputs come "from" somewhere and outputs go "to" somewhere, so
the different names are a useful hint. On the other hand, they're just
refs and using "ref" consistently might lead to fewer typos.

                                        Be seeing you,
                                          norm

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

Received on Thursday, 20 July 2006 21:02:45 UTC