0

我有三个具有不同属性值的 p 的源代码,我试图使元素的任意顺序以及一个强制性元素 p class='paragraph1'。即任意数量的第 1 段、第 2 段和第 3 段,以任何顺序排列,但必须至少有一个第 1 段。

下面我尝试了RNC中的interleave选项,但我失败了一个错误“元素“p”可以出现在“interleave”的多个操作数中”这是因为同一个元素声明了多次。但这在使用任何其他方法的 RelaxNG 中是否可行?

资源

<body>
<h1 class="title">title</h1>
<h2 class="subtitle">subtitle</h2>
<p class="paragraph2">Para text 2</p>
<p class="paragraph1">para text 1</p>
<p class="paragraph3">Para text 2</p>
</body>

RNC

start = element body { h1?, h2?, (p.paragraph1+ & p.paragraph2? & 
 p.paragraph3?) }
 h1 = element h1 { text & attribute class { string } }
 h2 = element h2 { text & attribute class { string } }
 p.paragraph1 = element p { text & attribute class { string "paragraph1" } }
 p.paragraph2 = element p { text & attribute class { string "paragraph2" } }
 p.paragraph3 = element p { text & attribute class { string "paragraph3" } }
4

0 回答 0