<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/ab-declare-step-011.xml"
        name="ab-declare-step-011.xml"
        expected="pass">
   <t:info>
      <t:title>Declare-step-011 (AB)</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2021-06-10</t:date>
            <t:author>
               <t:name>Achim Berndzen</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Added attribute 'queryBinding' to schematron's schema.</p>
            </t:description>
         </t:revision>
         <t:revision>
            <t:date>2019-07-20</t:date>
            <t:author>
               <t:name>Achim Berndzen</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Fixed test by declaring xs-namespace.</p>
            </t:description>
         </t:revision>
         <t:revision>
            <t:date>2019-02-25</t:date>
            <t:author>
               <t:name>Achim Berndzen</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Added new tests for p:declare-step and p:import.</p>
            </t:description>
         </t:revision>
      </t:revision-history>
   </t:info>
   <t:description xmlns="http://www.w3.org/1999/xhtml">
      <p>Tests a step is visible to itself for recursive call.</p>
   </t:description>
   <t:pipeline>
      <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                      xmlns:x="http://dummy"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      version="3.0">
         <p:output port="result"/>
         <p:declare-step type="Q{http://dummy}step" name="step">
            <p:input port="source" sequence="true"/>
            <p:output port="result" sequence="true"/>
            <p:option name="counter" as="xs:integer" required="true"/>
            <p:choose>
               <p:when test="$counter = 0">
                  <p:identity/>
               </p:when>
               <p:otherwise>
                  <x:step counter="{$counter -1}" name="recursion">
                     <p:with-input>
                        <p:inline>
                           <element/>
                        </p:inline>
                        <p:pipe step="step" port="source"/>
                     </p:with-input>
                  </x:step>
               </p:otherwise>
            </p:choose>
         </p:declare-step>
         <x:step counter="3">
            <p:with-input>
               <p:empty/>
            </p:with-input>
         </x:step>
         <p:wrap-sequence wrapper="result"/>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
         <s:pattern>
            <s:rule context="/">
               <s:assert test="result">The document root is not 'result'.</s:assert>
               <s:assert test="count(result/*) = 3">Result does not have three children.</s:assert>
               <s:assert test="count(result/element)=3">Result does not have three 'element' children.</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="ab-declare-step-011.xml">
      <result>
         <element xmlns:x="http://dummy" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
         <element xmlns:x="http://dummy" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
         <element xmlns:x="http://dummy" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
      </result>
   </t:result>
</t:test>
