<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
  <t:info>
    <t:title>message-007i</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 version="3.0"
                    xmlns:err="http://www.w3.org/ns/xproc-error"
                    xmlns:cx="http://xmlcalabash.com/ns/extensions"
                    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
                    xmlns:c="http://www.w3.org/ns/xproc-step"
                    xmlns:s="http://purl.oclc.org/dsdl/schematron"
                    xmlns:p="http://www.w3.org/ns/xproc">
      <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"/>
        <p:error>
          <p:with-option name="code" select="QName('http://example.com/foo', 's:local')"/>
        </p:error>
        <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 queryBinding="xslt2"
              xmlns:s="http://purl.oclc.org/dsdl/schematron">
      <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:rule>
      </s:pattern>
      <s:pattern>
        <s:rule context="wrapper/c:errors/c:error">
          <s:assert test="namespace-uri-from-QName(resolve-QName(@code, .)) = 'http://example.com/foo'"
                    >Error code namespace is wrong.</s:assert>
          <s:assert test="local-name-from-QName(resolve-QName(@code, .)) = 'local'"
                    >Local name is wrong.</s:assert>
        </s:rule>
      </s:pattern>
    </s:schema>
  </t:schematron>
</t:test>
