visit-each

Table of Contents

Declaration
Related GitHub issue(s)
Sample usage
Commentary

Element context(s)

This attribute is optional and selects items matched by a rule context for further evaluation.

Clause 5.5.21 (visit-each attribute)

The visit-each attribute contains an expression which selects a sequence of items for further evaluation.

The expression is evaluated against each item resulting from evaluation of the rule's context expression. If this sequence is non-empty, it becomes the context against which assertions are evaluated, in place of the rule's context. If it is empty, the rule is still considered to have fired.

Declaration

element rule {
        attribute flag { flagValue }?,
        rich,
        linkable,
        (foreign
         & inclusion*
         & ((attribute context { pathValue },
               attribute visit-each { pathValue }?,
               attribute id { xsd:ID }?,
               attribute abstract { "false" }?,
               title?,
               let*,
               (assert | report | extends | p)+)))
    }

Related GitHub issue(s)

Checking for substrings of the node values

Sample usage

Example 10. visit-each attribute

Validating this document:

<foo>foo bar blort foo bar</foo>

against a schema containing this rule:

<sch:rule context='foo' visit-each='fn:analyze-string(., "foo")/fn:match'>
  <sch:report test='.'><sch:name/> at index <sch:value-of select='string-length(string-join(preceding-sibling::fn:*))+1'/></sch:report>
</sch:rule>

produces SVRL output containing:

<svrl:fired-rule context="/foo" visit-each="analyze-string(., "foo")/fn:match"/>
<successful-report xmlns="http://purl.oclc.org/dsdl/svrl" location="Q{http://www.w3.org/2005/xpath-functions}root()/Q{http://www.w3.org/2005/xpath-functions}match[1]" test=".">
  <svrl:text>foo at index 1</svrl:text>
</successful-report>
<successful-report xmlns="http://purl.oclc.org/dsdl/svrl" location="Q{http://www.w3.org/2005/xpath-functions}root()/Q{http://www.w3.org/2005/xpath-functions}match[2]" test=".">
  <svrl:text>foo at index 15</svrl:text>
</successful-report>

Commentary

This attribute effectively allows the schema author to iterate over the sequence of items returned. While the rule context expression in the example above can (depending on the query language binding) be re-written as

/foo/analyze-string(., "foo")/fn:match

and produce the same result, visit-each enables the expression to be decomposed for clarity.