The documents attribute

Another feature of patterns is the documents attribute, introduced in the 2016 edition of the standard. It affords the convenience of applying rules to the "subordinate" documents located at the URIs derived by evaluating documents in the context of the instance document root, for example:

<sch:pattern documents="/element/@secondary">
  <sch:rule context="/">
    <sch:report test="root"/>
  </sch:rule>
</sch:pattern>

Here, each document located at the URIs in /element/@secondary would have the rule applied to it, and any root element root reported.

There are two issues with this shifting of context to other documents, which the standard arguably underspecifies. One is that it is only implicit that the rules in that pattern should only apply to the subordinate documents retrieved (which is what XQS assumes) and not also to the instance document itself. The other (an edge case, but possible) is whether pattern variables should be in scope when evaluating the documents attribute [41]; XQS assumes that they are.



[41] As in <pattern documents='/subordinate/documents[not(@path = $these)]'>, where $these is defined as a variable within that pattern.