Express a recursive reference in a set of recurring ordered elements
<p>I'm trying to write a RelaxNG schema that has the following rules:</p>

<ol>
<li>A <code>line</code> element can contain zero or more <code>a</code> and <code>b</code> elements.</li>
<li>Every <code>a</code> element must have a corresponding <code>b</code> element and
vice-versa.</li>
<li><code>a</code> elements must always precede their matching <code>b</code> elements.</li>
</ol>

<p>So, the following should all be considered valid:</p>

<pre><code>&lt;line&gt;&lt;a/&gt;&lt;b/&gt;&lt;/line&gt;

&lt;line&gt;&lt;a/&gt;&lt;a/&gt;&lt;b/&gt;&lt;b/&gt;&lt;/line&gt;

&lt;line&gt;&lt;a/&gt;&lt;a/&gt;&lt;b/&gt;&lt;a/&gt;&lt;b/&gt;&lt;b/&gt;&lt;/line&gt;
</code></pre>

<p>Meanwhile, the following are all invalid:</p>

<pre><code>&lt;line&gt;&lt;b/&gt;&lt;a/&gt;&lt;/line&gt;

&lt;line&gt;&lt;a/&gt;&lt;a/&gt;&lt;b/&gt;&lt;/line&gt;

&lt;line&gt;&lt;a/&gt;&lt;/line&gt;

&lt;line&gt;&lt;b/&gt;&lt;/line&gt;
</code></pre>

<p>How can this be expressed in RelaxNG? My first thought was to create a recursive reference, like so:</p>

<pre><code>element line { pair* }+

pair = a, pair?, b

a = element a { empty }
b = element b { empty }
</code></pre>

<p>However, Jing considers this a "bad recursive reference to 'pair'". I can't for the life of me figure out how to solve this! Any ideas?</p>