0

I have source with three p with different attribute values, I tried to make arbitrary order of elements along with one mandatory element p class='paragraph1'. That is any number of paragraph1, paragraph2 and pharagraph3 in any order but there must be at least one paragraph1.

Below I tried the interleave option in RNC, but I failed with an error "the element "p" can occur in more than one operand of "interleave"" This is because the same element declared more than one time. But is this possible in RelaxNG using any other method?

Source

<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" } }
VSe
  • 919
  • 2
  • 13
  • 29
  • 1
    So I think actually this is something you can’t express in RelaxNG, because you’re running into the same limitation described in https://stackoverflow.com/questions/11786196/can-relaxng-specify-an-unordered-set-of-elements-with-the-same-name-but-differe and explained in the RelaxNG spec at https://www.oasis-open.org/committees/relax-ng/spec-20011203.html#interleave-restrictions. The gist of it is, to avoid hitting this limitation you can’t all the the p elements to be unordered—you must instead specify and ordering for them – sideshowbarker May 22 '17 at 12:10
  • Can you update your question to be very explicit about exactly what you want the schema to express? I *think* you’re saying you want to allow any number of paragraph1, paragraph2, and paragraph3 in any order, but there must be at least one paragraph1. Is that correct? And to be clear, this is different from what you were trying to do in https://stackoverflow.com/questions/44015970/control-attribute-values-order-in-relaxng, right? I mean because in that question, you wanted ordering: “paragraph1 should always come first and paragraph2 should come after paragraph1”. – sideshowbarker May 23 '17 at 13:40
  • Its any number of paragraph1, pharagraph2 and pharagraph3 in any order but must have at least one paragraph1. I tried that with schematron ` There must be 1 p element with paragraph1. ` Its working fine when have it as a separate schematron file. But when i try to embed the schematron rule in RNC its not validating. – VSe May 24 '17 at 04:22
  • 1
    If you’re trying with jing I think jing ignores the embedded schematron rules. I believe you have to do a separate pass to check them. See the steps in the answer at https://stackoverflow.com/questions/23906793/command-line-validator-supporting-relax-ng-schemas-with-embedded-iso-schematron/23910250#23910250 Basically what it comes down to is tthat there’s no value to embedding the schematron rules in the RelaxNG schema. Instead just maintain them in a separate file (as it sounds like you’re already doing). – sideshowbarker May 24 '17 at 04:32

0 Answers0