Lists

RELAX NG supports the description of text nodes as lists of whitespace-separated values using the list pattern. This is the only pattern that transforms the structure of the document at validation time by splitting text values into lists of values. The benefit of doing so is that within a list pattern, all the patterns that constrain data values can be combined with the compositors, which lets you constrain the combination of these values.

If you use a list pattern without defining cardinality, you may not get what you expect. An attribute defined as:

<attribute name="see-also">
 <list>
  <data type="token"/>
 </list>
</attribute>

or, using the compact syntax:

attribute see-also {list {token}}

doesn’t match a list of tokens (such as see-also="0345442695 0449220230 0449214044 0061075647 0061075612“) but rather only a list of exactly one token (such as see-also="0345442695“). This is because the list pattern splits the text value into a list of values. This list is then evaluated against the patterns that are included within the list pattern. If you want a list of any number of token s, use a zeroOrMore pattern to express that:

<attribute name="see-also">
 <list>
  <zeroOrMore>
   <data type="token"/>
  </zeroOrMore>
 </list>
</attribute>

Here’s the compact syntax:

attribute see-also {list {token*}}

This definition treats the see-also attribute as a list of tokens and doesn’t add any other constraints (this result is of course different when there are more datatypes). You can use other compositors ...

Get RELAX NG now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.