<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/try-catch-003.xml"
        name="try-catch-003.xml"
        expected="pass">
   <t:info>
      <t:title>try-catch-003</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2026-07-20</t:date>
            <t:author>
               <t:name>Norm Tovey-Walsh</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Created test.</p>
            </t:description>
         </t:revision>
      </t:revision-history>
   </t:info>
   <t:description xmlns="http://www.w3.org/1999/xhtml">
      <p>Tests that an error code raised by a static error in an XSLT stylsheet is reported correctly.</p>
   </t:description>
   <t:pipeline>
      <p:declare-step xmlns:cx="http://xmlcalabash.com/ns/extensions"
                      xmlns:err="http://www.w3.org/ns/xproc-error"
                      xmlns:ex="http://example.com/ns/step"
                      xmlns:p="http://www.w3.org/ns/xproc"
                      version="3.0">
         <p:output port="result"/>
         <p:try>
            <p:xslt>
               <p:with-input port="stylesheet" href="../documents/xslt-static-error.xsl"/>
               <p:with-input port="source" href="../documents/xslt-static-error.xsl"/>
            </p:xslt>
            <p:catch>
               <p:identity/>
            </p:catch>
         </p:try>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
         <s:ns prefix="c" uri="http://www.w3.org/ns/xproc-step"/>
         <s:ns prefix="cx" uri="http://xmlcalabash.com/ns/extensions"/>
         <s:pattern>
            <s:rule context="/">
               <s:assert test="c:errors">The document is wrong</s:assert>
            </s:rule>
         </s:pattern>
         <s:pattern>
            <s:rule context="/c:errors">
               <s:assert test="count(c:error) = 1">Wrong number of errors</s:assert>
               <s:assert test="c:error/@code = 'err:XC0093'">Wrong error code</s:assert>
               <s:assert test="c:error/@cause = 'fnerr:XTSE0090'">Wrong error cause</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="try-catch-003.xml">
      <c:errors xmlns:c="http://www.w3.org/ns/xproc-step"
                xmlns:cx="http://xmlcalabash.com/ns/extensions"
                xmlns:err="http://www.w3.org/ns/xproc-error"
                xmlns:fnerr="http://www.w3.org/2005/xqt-errors"
                xmlns:p="http://www.w3.org/ns/xproc">
         <c:error name="!xslt"
                  type="p:xslt"
                  code="err:XC0093"
                  href="file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/extra-suite/test-suite/tests/try-catch-003.xml"
                  line="30"
                  column="17"
                  cause="fnerr:XTSE0090">
            <cx:input-location href="file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/extra-suite/test-suite/documents/xslt-static-error.xsl"
                               line="7"
                               column="40"/>
            <cx:message>Failed to compile stylesheet: Attribute @spoon is not allowed on element &lt;xsl:template&gt;.</cx:message>
            <cx:explanation>It is a dynamic error if a static error occurs during the static 
analysis of the XSLT stylesheet. (Underlying exception was: net.sf.saxon.s9api.SaxonApiException: 
Errors were reported during stylesheet compilation)</cx:explanation>
            <cx:cause>Errors were reported during stylesheet compilation</cx:cause>
            <cx:stack-trace>
               <cx:stack-frame type="p:xslt" name="!xslt"/>
               <cx:stack-frame type="p:group" name="!group"/>
            </cx:stack-trace>
         </c:error>
      </c:errors>
   </t:result>
</t:test>
