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

   <xs:restriction xmlns:xs="http://www.w3.org/2001/XMLSchema" base="xs:string"/>

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

      for $c in $def/(* except xs:annotation) return (
         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/>