title: schema-element() for SequenceType on xsl:variable with literal result element
body: <p>I'm trying to understand how <code>schema-element()</code> works when used as a <code>SequenceType</code> with literal result elements. This is my stylesheet</p>
  
  <pre><code>&lt;xsl:stylesheet
    version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"&gt;
  
    &lt;xsl:import-schema&gt;
      &lt;xs:schema&gt;
        &lt;xs:element name="foo"&gt;
          &lt;xs:complexType&gt;
            &lt;xs:attribute name="bar"/&gt;
          &lt;/xs:complexType&gt;
        &lt;/xs:element&gt;
      &lt;/xs:schema&gt;
    &lt;/xsl:import-schema&gt;
  
    &lt;xsl:variable name="test" as="schema-element(foo)"&gt;
      &lt;foo bar="baz"/&gt;
    &lt;/xsl:variable&gt;
  
    &lt;xsl:template match="/"&gt;
      &lt;xsl:sequence select="$test"/&gt;
    &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Saxon-EE 9.4.0.4 (in Oxygen 14.1) is giving me the following compilation error <code>Required item type of value of variable $test is schema-element(foo); supplied value has item type element(foo, {http://www.w3.org/2001/XMLSchema}untyped)</code></p>
  
  <p>According to <a href="http://books.google.com/books?id=OnqLX4RgOkIC" rel="nofollow">XSLT 2.0 and XPath 2.0 Programmer's Reference</a> </p>
  
  <blockquote>
    <p>When the construct «schema-element(N)» … is used in a SequenceType,
    then N must be the name of a global element … declaration in an
    imported schema.</p>
  </blockquote>
  
  <p>elsewhere in the same source</p>
  
  <blockquote>
    <p>«as="schema-element(EVENT)"» indicates that [a parameter] must be an element node validated as being
    either an EVENT or an element in the substitution group of EVENT.</p>
  </blockquote>
  
  <p>It seems like <code>&lt;foo bar="baz"/&gt;</code> should validate as a <code>foo</code> element by the imported schema. <code>@xsl:type</code> seems like it would help, but only if I had a named complex type in my imported schema. What am I missing or doing wrong?</p>