Hello Michael,

it seems to me there is a strange XQuery bug concerning sequence type matching.

Summry: typeswitch cases using "element(elemName)", as well as "instance of element(elemName)" do not match when they should; but the equivalent comparison of node names matches, as it should.
But this, of course, only in a very special context, which is given by how the candidate is provided:
   $def/(* except xs:annotation)

For full example code see below.

Version: saxon9-3-0-5j

Kind regards,
-- Hans-Juergen

Output:
==========
<result>
   <xs:restriction xmlns:xs="http://www.w3.org/2001/XMLSchema" base="xs:string"/>
   <NOMATCH_TYPESWITCH/>
   <NOMATCH_INSTANCEOF/>
   <MATCH_NODENAME/>
</result>
==========

Code:
==========
declare namespace xs="http://www.w3.org/2001/XMLSchema";
let $def :=
   <xs:simpleType name="yogi">
      <xs:restriction base="xs:string"/>
   </xs:simpleType>
let $ref := $def/xs:restriction
return

   <result>{
      for $c in $def/(* except xs:annotation) return (
         $c,
         typeswitch($c)
         case element(xs:restriction) return <MATCH_TYPESWITCH/>
         default return <NOMATCH_TYPESWITCH/>
         ,
         if ($c instance of element(xs:restriction))
         then <MATCH_INSTANCEOF/>
         else <NOMATCH_INSTANCEOF/>
         ,
         if (node-name($c) eq node-name($ref))
         then <MATCH_NODENAME/>
         else <NOMATCH_NODENAME/>
      )     
   }</result>
==========