Search code examples
dtddita

DITA DTD, allow same element after each other


I'm adding some elements to our DITA DTD (DTD customization based on dita 1.2)

What I want is to allow a p-element more then one time after each other inside the same entity element, but maximum four times.

Users must have one P-element, and maximum 4 in total, inside a textcont-element.

When using the DTD below I get:

sect.mod: Non deterministic content model. An instance of element p could simultaneously match two or more tokens in the content model.

<!ENTITY % textcont.content
  "(%p;,
  %p;?,
  %p;?,
  %p;?)
">

Is there a way to write this so I don't get the error - based on minimum 1 p-element, maximum 4 p-elements?

or do I have to use

<!ENTITY % textcont.content
  "(%p;,(%p;)*)">

Could it be that this is a limitation to building up the DTDs, regarding this?


Solution

  • The short answer is it's not easy to get what you want with DTD syntax.

    To limit a repetition to a specific number you have to do something like this:

    <!ELEMENT root 
       (p, 
         (p, 
           (p,
             (p)?)?)?)
    >
    
    <!ELEMENT p EMPTY >
    

    This works for your specific case but you can see that if your requirements are more complicated it starts to become unworkable.

    In general this kind of constraint is better done through Schematrons, which make it easy to check these sorts of constraints.