Try/catch 004

Test is expected to pass.

Options

NameInitializer
error0

The pipeline

<p:declare-step xmlns:cx="http://xmlcalabash.com/ns/extensions"
                xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:t="http://xproc.org/ns/testsuite/3.0" name="main" version="3.0">
   <p:option name="error"/>
   <p:output port="result">
      <p:pipe step="try" port="finally"/>
   </p:output>
   <p:try name="try">
      <p:group>
         <p:choose>
            <p:when test="$error = 0">
               <p:identity>
                  <p:with-input port="source">
                     <p:inline>
                        <doc>try succeeded</doc>
                     </p:inline>
                  </p:with-input>
               </p:identity>
            </p:when>
            <p:when test="$error = 1">
               <p:error code="cx:error">
                  <p:with-input port="source">
                     <p:empty/>
                  </p:with-input>
               </p:error>
            </p:when>
            <p:otherwise>
               <p:error code="cx:error2">
                  <p:with-input port="source">
                     <p:empty/>
                  </p:with-input>
               </p:error>
            </p:otherwise>
         </p:choose>
      </p:group>
      <p:catch code="cx:error">
         <p:identity>
            <p:with-input port="source">
               <p:inline>
                  <doc>caught cx:error</doc>
               </p:inline>
            </p:with-input>
         </p:identity>
      </p:catch>
      <p:catch>
         <p:identity>
            <p:with-input port="source">
               <p:inline>
                  <doc>caught any</doc>
               </p:inline>
            </p:with-input>
         </p:identity>
      </p:catch>
      <p:finally>
         <p:output port="finally" primary="false">
            <p:pipe step="fident" port="result"/>
         </p:output>
         <p:identity name="fident">
            <p:with-input port="source">
               <p:inline>
                  <doc>finally</doc>
               </p:inline>
            </p:with-input>
         </p:identity>
      </p:finally>
   </p:try>
</p:declare-step>

Result

<doc xmlns:cx="http://xmlcalabash.com/ns/extensions"
     xmlns:t="http://xproc.org/ns/testsuite/3.0">finally</doc>

Schematron checks

<s:schema xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://purl.oclc.org/dsdl/schematron" xmlns:t="http://xproc.org/ns/testsuite/3.0"
          queryBinding="xslt2">
   <s:ns prefix="c"
         uri="http://www.w3.org/ns/xproc-step"/>
   <s:pattern>
      <s:rule context="/*">
         <s:assert test="self::doc">The pipeline root is not doc.</s:assert>
         <s:assert test=". = 'finally'">The result isn't "finally"</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

10 Jun 2021, Achim Berndzen
Added attribute 'queryBinding' to schematron's schema.
24 Sep 2017, Norman Walsh
Port my test suite; add documentation and schemas