Example 1

Given Input Type XQuery Expression Expected Output Type
<!ELEMENT r (b*,c?,d)>
<!ELEMENT b EMPTY>
<!ELEMENT c EMPTY>
<!ELEMENT d EMPTY>
        <r>{for $y in child::* return <a>{$y}</a>}</r>  
        
<!ELEMENT r (a*)>
<!ELEMENT a (b|d)>
<!ELEMENT b EMPTY>
<!ELEMENT d EMPTY>

Explanation

The type-checker detects that: (1) an element "c" may occur as a child of root element "r" in the input, and that (2) for this element the expression will output an "a" element with an "c" child which is forbidden by the content model of "a" elements expected as output.

Full Trace

The full trace generated by the implementation for the example above: