<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="nw-ns-008.xml"
        name="nw-ns-008.xml"
        expected="pass">
   <t:info>
      <t:title>nw-ns-008</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2026-02-25</t:date>
            <t:author>
               <t:name>Norm Tovey-Walsh</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Initial commit</p>
            </t:description>
         </t:revision>
      </t:revision-history>
   </t:info>
   <t:description xmlns="http://www.w3.org/1999/xhtml">
      <p>Tests for a non-XProc binding for p:.
<a href="https://codeberg.org/xmlcalabash/xmlcalabash3/issues/561">h/t Amanda Galtman</a>.
</p>
   </t:description>
   <t:pipeline>
      <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="3.1">
         <p:input port="source">
            <p:inline>1</p:inline>
         </p:input>
         <p:output port="result"/>
         <p:try>
            <p:error><!-- Note: The with-option element re-binds the 'p' prefix
            to a namespace different from the standard XProc one. -->
               <p-alias:with-option xmlns:p="http://my-ns"
                                    xmlns:p-alias="http://www.w3.org/ns/xproc"
                                    name="code"
                                    select="'p:my-error-code'"/>
               <p:with-input>
                  <error-document>An error occurred.</error-document>
               </p:with-input>
            </p:error>
            <p:catch>
               <p:identity/>
            </p:catch>
         </p:try>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns="http://www.w3.org/1999/xhtml"
                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="err" uri="my-ns"/>
         <s:pattern>
            <s:rule context="/">
               <s:assert test="c:errors">Not an error document</s:assert>
               <s:assert test="count(c:errors/c:error) = 1">Incorrect number of errors reported</s:assert>
            </s:rule>
         </s:pattern>
         <s:pattern>
            <s:rule context="c:error">
               <s:assert test="namespace-uri-from-QName(resolve-QName(@code, .))                                = 'http://my-ns'">Error code is in wrong namespace</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="nw-ns-008.xml">
      <c:errors xmlns:_1="http://my-ns"
                xmlns:c="http://www.w3.org/ns/xproc-step"
                xmlns:cx="http://xmlcalabash.com/ns/extensions"
                xmlns:fnerr="http://www.w3.org/2005/xqt-errors"
                xmlns:p="http://www.w3.org/ns/xproc">
         <c:error name="!error"
                  type="p:error"
                  code="_1:my-error-code"
                  href="file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/3.0-test-suite/test-suite/tests/nw-ns-008.xml"
                  line="30"
                  column="18">
            <cx:input-location href="file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/3.0-test-suite/test-suite/tests/nw-ns-008.xml"/>
            <cx:message>(no message for error)</cx:message>
            <error-document>An error occurred.</error-document>
            <cx:stack-trace>
               <cx:stack-frame type="p:error" name="!error"/>
               <cx:stack-frame type="p:group" name="!group"/>
            </cx:stack-trace>
         </c:error>
      </c:errors>
   </t:result>
</t:test>
