Hello,
if I am not mistaken, the following code demonstrates a bug. The code extracts from a schema a type definition, referenced by an element declaration. The second line determines the element whose type definition is sought.
In mode 1, the type definition is not found, in mode 2 it is found. With Saxon, modes 1 and 2 are successful.
Strangely, at least with my XSD the error occurs only if the type to be found is xs:simpleType - it does not occur if it is xs:complexType.
Kind regards,
Hans-Juergen
===================================
declare variable $schemas := /*;
declare variable $elem := ($schemas//xs:element[@type eq 't:Room'])[1];
declare variable $mode := 1;
declare function local:getTypeDef($elem as element(xs:element)) as element()? {
  let $type := $elem/@type
  return
  if (empty($type)) then $elem/(xs:simpleType, xs:complexType) else
  let $qname := resolve-QName($type, $elem)
  let $lname := local-name-from-QName($qname)
  let $uri := namespace-uri-from-QName($qname)
  return
     if (empty($uri)) then
        let $actSchemas := $schemas[not(@targetNamespace)]
        return $actSchemas/(xs:complexType, xs:simpleType)[@name eq $lname]
     else
        if ($mode eq 1) then
           $schemas[@targetNamespace eq $uri]/(xs:complexType, xs:simpleType)[@name eq $lname]
        else
           let $actSchemas := $schemas[@targetNamespace eq $uri]
           let $types := $actSchemas/(xs:complexType, xs:simpleType)
           return $types[@name eq $lname]
};
<typeDef>{
  local:getTypeDef($elem)
}</typeDef>Â Â
==============================================