<?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 038 (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 of variables 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">
         <p:output port="result"/>
         
         <p:xquery version="3.1"
            parameters="map{'variable' : (xs:string('text'),
               xs:normalizedString('text'),
               xs:token('text'),
               xs:language('en'),
               xs:NMTOKEN('text'),
               xs:Name('name'),
               xs:NCName('name')
              )}" >
            <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";
                  declare variable $variable external;
                  
                  &lt;tests>
                     &lt;string-test>{{$variable[1] instance of xs:string}}&lt;/string-test>
                     &lt;normalized-string-test>{{$variable[2] instance of xs:normalizedString}}&lt;/normalized-string-test>
                     &lt;token-test>{{$variable[3] instance of xs:token}}&lt;/token-test>
                     &lt;language-test>{{$variable[4] instance of xs:language}}&lt;/language-test>
                     &lt;NMTOKEN-test>{{$variable[5] instance of xs:NMTOKEN}}&lt;/NMTOKEN-test>
                     &lt;name-test>{{$variable[6] instance of xs:Name}}&lt;/name-test>
                     &lt;ncname-test>{{$variable[7] instance of xs:NCName}}&lt;/ncname-test>
                  &lt;/tests>
               </p:inline>
            </p:with-input>
         </p:xquery>
      </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="tests/string-test/text()='true'">$variable[1] is not xs:string</s:assert>
               <s:assert test="tests/normalized-string-test/text()='true'">$variable[2] is not xs:normalizedString</s:assert>
               <s:assert test="tests/token-test/text()='true'">$variable[3] is not xs:token</s:assert>
               <s:assert test="tests/language-test/text()='true'">$variable[4] is not xs:language</s:assert>
               <s:assert test="tests/NMTOKEN-test/text()='true'">$variable[5] is not xs:NMTOKEN</s:assert>
               <s:assert test="tests/name-test/text()='true'">$variable[6] is not xs:Name</s:assert>
               <s:assert test="tests/ncname-test/text()='true'">$variable[7] is not xs:NCName</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
</t:test>