<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/message-007b.xml"
        name="message-007b.xml"
        expected="pass">
   <t:info>
      <t:title>message-007b</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2026-01-31</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 another AVT issue.</p>
   </t:description>
   <t:pipeline>
      <p:declare-step 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:p="http://www.w3.org/ns/xproc"
                      xmlns:s="http://purl.oclc.org/dsdl/schematron"
                      version="3.0">
         <p:import href="https://xmlcalabash.com/ext/library/pipeline-messages.xpl"/>
         <p:output port="result"/>
         <p:identity>
            <p:with-input>
               <doc/>
            </p:with-input>
         </p:identity>
         <p:try name="dep">
            <p:output port="result"/>
            <!-- This sets code to the value of the 'bang' element, so '', so lexical error -->
            <p:error code="{Q{}bang}"/>
            <p:catch>
               <p:output port="result"/>
               <p:identity message="Element is {node-name(/*)}"/>
            </p:catch>
         </p:try>
         <cx:pipeline-messages name="messages" p:depends="dep" level="info"/>
         <p:wrap-sequence wrapper="wrapper">
            <p:with-input pipe="result@dep result@messages"/>
         </p:wrap-sequence>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
         <s:ns prefix="cx" uri="http://xmlcalabash.com/ns/extensions"/>
         <s:ns prefix="c" uri="http://www.w3.org/ns/xproc-step"/>
         <s:pattern>
            <s:rule context="/">
               <s:assert test="wrapper">The document root is not correct.</s:assert>
               <s:assert test="wrapper/c:errors">No errors element</s:assert>
               <s:assert test="wrapper/cx:messages">No messages element</s:assert>
            </s:rule>
         </s:pattern>
         <s:pattern>
            <s:rule context="wrapper/cx:messages">
               <s:assert test="cx:message[@level='INFO' and contains(@message, 'Element is c:errors')]">No message output.</s:assert>
            </s:rule>
         </s:pattern>
         <s:pattern>
            <s:rule context="wrapper/c:errors/c:error">
               <s:assert test="@code = 'err:XD0036'">Error code is wrong</s:assert>
               <s:assert test="cx:message = 'Value “” cannot be converted to type “xs:NCName”.'">Message is wrong</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="message-007b.xml">
      <wrapper>
         <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">
            <c:error name="!expression_IC330524"
                     type="cx:expression"
                     code="err:XD0036"
                     href="file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/extra-suite/test-suite/tests/message-007b.xml"
                     line="38"
                     column="36">
               <cx:message>Value “” cannot be converted to type “xs:NCName”.</cx:message>
               <cx:explanation>It is a dynamic error if the supplied or defaulted value of a variable 
or option cannot be converted to the required type.</cx:explanation>
               <cx:stack-trace>
                  <cx:stack-frame type="cx:expression" name="!expression_IC330524"/>
                  <cx:stack-frame type="p:group" name="!group"/>
               </cx:stack-trace>
            </c:error>
         </c:errors>
         <cx:messages xmlns:cx="http://xmlcalabash.com/ns/extensions">
            <cx:message date="2026-07-21T06:16:14+00:00"
                        level="INFO"
                        message="Element is c:errors"/>
         </cx:messages>
      </wrapper>
   </t:result>
</t:test>
