<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        features="xquery_3_1"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <t:info>
      <t:title>p:xquery 041 (AB)</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2026-10-29</t:date>
            <t:author>
               <t:name>Achim Berndzen</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 types in xquery result are set correctly (Part 3)</p>
   </t:description>
   <t:pipeline>
      <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" 
         xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0"
         exclude-inline-prefixes="#all">
         <p:output port="result" sequence="true" serialization="map{'indent' : true()}"/>
         
         <p:xquery version="3.1" >
            <p:with-input port="source">
               <p:empty />
            </p:with-input>
            <p:with-input port="query" xml:base="http://xquery-uri">
               <p:inline content-type="text/plain">
                  declare namespace xs ="http://www.w3.org/2001/XMLSchema";
                  (xs:string('text'), (:1:)
                  xs:normalizedString('text'), (:2:)
                  xs:token('text'), (:3:)
                  xs:language('en'), (:4:)
                  xs:NMTOKEN('text'), (:5:)
                  xs:Name('name'), (:6:)
                  xs:NCName('name') (:7:)
                  )
               </p:inline>
            </p:with-input>
         </p:xquery>
         
         <p:for-each>
            <p:choose>
               <p:when test="p:iteration-position()=1">
                  <p:identity>
                     <p:with-input><string-test>{. instance of xs:string}</string-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=2">
                  <p:identity>
                     <p:with-input><normalizedString-test>{. instance of xs:normalizedString}</normalizedString-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=3">
                  <p:identity>
                     <p:with-input><token-test>{. instance of xs:token}</token-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=4">
                  <p:identity>
                     <p:with-input><language-test>{. instance of xs:language}</language-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=5">
                  <p:identity>
                     <p:with-input><NMTOKEN-test>{. instance of xs:NMTOKEN}</NMTOKEN-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=6">
                  <p:identity>
                     <p:with-input><Name-test>{. instance of xs:Name}</Name-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:when test="p:iteration-position()=7">
                  <p:identity>
                     <p:with-input><NCName-test>{. instance of xs:NCName}</NCName-test></p:with-input>
                  </p:identity>
               </p:when>
               <p:otherwise>
                  <p:identity>
                     <p:with-input><unidentified-value /></p:with-input>
                  </p:identity>
               </p:otherwise>
            </p:choose>
         </p:for-each>
         <p:wrap-sequence wrapper="tests" />
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema queryBinding="xslt2"
                xmlns:s="http://purl.oclc.org/dsdl/schematron"
                xmlns="http://www.w3.org/1999/xhtml">
         <s:pattern>
            <s:rule context="/">
               <s:assert test="tests">Root element is not 'tests'.</s:assert>
               <s:assert test="count(tests/unidentified-value)=0">There are identified values. Please check pipeline.</s:assert>
               <s:assert test="tests/string-test/text()='true'">document[1] is not xs:string</s:assert>
               <s:assert test="tests/normalizedString-test/text()='true'">document[2] is not xs:normalizedString</s:assert>
               <s:assert test="tests/token-test/text()='true'">document[3] is not xs:token</s:assert>
               <s:assert test="tests/language-test/text()='true'">document[4] is not xs:language</s:assert>
               <s:assert test="tests/NMTOKEN-test/text()='true'">document[5] is not xs:NMTOKEN</s:assert>
               <s:assert test="tests/Name-test/text()='true'">document[6] is not xs:Name</s:assert>
               <s:assert test="tests/NCName-test/text()='true'">document[7] is not xs:NCName</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
</t:test>