Skip to main content
Participating Frequently
April 26, 2011
Answered

General Rule: How to specify optional elements?

  • April 26, 2011
  • 2 replies
  • 694 views

Hello,

I'm trying to construct a general for which all elements are optional, BUT at least one must be included. For example, the content could be a caution, warning, note, or para. No specific element is required, but at least one of them must be present. How do I do that?

Thank you,

Joan

This topic has been closed for replies.
Correct answer MarttiP

Joan,

try this:

(warning | caution | note | para )+

BR,

Martti

2 replies

Inspiring
April 26, 2011

Joan,

  You want to require one of four different types of elements, but what can follow the first element depends on which type it is. Your general rule therefore could be a choice of four possibilities, each of which starts with a different one of your four types. However, since notes and paras are treated identically, you can get by with three groups in a pattern such as:

   (starts with a warning) | (starts with a caution) | (starts with a note or a para)

  One possibility is:

  (warning+, caution*, (note | para)*) | (caution+, (note | para)*) | (note | para)+

  If you didn't want to require that one of these four elements occur, you could use simply:

  warning*, caution*, (note | para)*

which does enforce that any warnings occur at the beginning and that any cautions follow any warnings and precede notes and paras.

      --Lynne

JoanDTDAuthor
Participating Frequently
April 26, 2011

Hi, Lynne,

Wow, thanks for the very complete answer. I'm looking forward to

trying it out, but I have to admit, I'm a little intimidated trying to

read and understand that rule!

Before I received your answer I posted another question, but you may

have already answered it.

Thanks again for your help.

Best regards,

Joan

MarttiPCorrect answer
Inspiring
April 26, 2011

Joan,

try this:

(warning | caution | note | para )+

BR,

Martti

JoanDTDAuthor
Participating Frequently
April 26, 2011

Thanks Martti. In my haste, I oversimplified the real problem.

What I really want:

- Warnings are optional, but if there are any, they must be first.

- Cautions are optional, but if there are any, they must be after any warnings (if any). i.e. gen. rule: warning*, caution*

- Notes and paras are optional, and they can be in any order after the warnings and cautions.

- At least one of the above is required.

Valid: warning

Valid: caution

Valid: note

Valid: para

Valid: warning1, warning 2, caution1, note, para, note

Not valid: warning1, caution, note, warning2

Thanks again for your help.

Joan