<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/cx-while-001.xml"
        name="cx-while-001.xml"
        expected="pass">
   <t:info>
      <t:title>cx-while-001</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2025-01-18</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>Test cx:while</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:p="http://www.w3.org/ns/xproc"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      version="3.0">
         <p:output port="result"/>
         <cx:while test="xs:integer(/doc/@count) lt 5">
            <p:with-input>
               <doc count="3"/>
            </p:with-input>
            <p:add-attribute attribute-name="count" attribute-value="{xs:integer(/doc/@count) + 1}"/>
         </cx:while>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
         <s:ns prefix="fn" uri="http://www.w3.org/2005/xpath-functions"/>
         <s:pattern>
            <s:rule context="/">
               <s:assert test="doc">The result isn’t doc.</s:assert>
            </s:rule>
         </s:pattern>
         <s:pattern>
            <s:rule context="/doc">
               <s:assert test="@count = 5">The count is wrong.</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="cx-while-001.xml">
      <doc xmlns:cx="http://xmlcalabash.com/ns/extensions"
           xmlns:err="http://www.w3.org/ns/xproc-error"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           count="5"/>
   </t:result>
</t:test>
