<?xml-stylesheet type="text/xsl" href="/style/testcase.xsl"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite"
        xmlns:p="http://www.w3.org/ns/xproc"
        xmlns:c="http://www.w3.org/ns/xproc-step"
        xmlns:err="http://www.w3.org/ns/xproc-error"
	ignore-whitespace-differences="true">	
<t:title>Test try/catch #003</t:title>

<t:input port='source'>
<document>
<title>Some Title</title>
<para>Some paragraph.</para>
</document>
</t:input>

<t:pipeline>
<p:declare-step version='1.0' xmlns:p="http://www.w3.org/ns/xproc"
		name="main">
<p:input port="parameters" kind="parameter"/>
<p:input port="source">
  <p:inline><irrelevant/></p:inline>
</p:input>
<p:output port="result"/>

<p:try>
  <p:group>
    <p:xslt>
      <p:input port="stylesheet">
	<p:inline>
	  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
			  version="1.0">
	    <xsl:template match="/">
	      <xsl:message terminate="yes">
		<xsl:text>This XSLT stylesheet always fails</xsl:text>
	      </xsl:message>
	    </xsl:template>
	  </xsl:stylesheet>
	</p:inline>
      </p:input>
    </p:xslt>
  </p:group>
  <p:catch name="catch">
    <p:choose>
      <p:when test="//c:error[contains(.,'This XSLT stylesheet always fails')]">
	<p:xpath-context>
	  <p:pipe step="catch" port="error"/>
	</p:xpath-context>
	<p:identity>
	  <p:input port="source">
	    <p:inline>
	      <message>Catch caught XSLT failure.</message>
	    </p:inline>
	  </p:input>
	</p:identity>
      </p:when>
      <p:otherwise>
	<p:identity>
	  <p:input port="source">
	    <p:inline>
	      <message>Catch caught XSLT failure, but not the message.</message>
	    </p:inline>
	  </p:input>
	</p:identity>
      </p:otherwise>
    </p:choose>
  </p:catch>
</p:try>
</p:declare-step>
</t:pipeline>

<t:output port='result'>
  <message>Catch caught XSLT failure.</message>
</t:output>

</t:test>

