At 2009-03-22 17:56 +0000, Dusty Phillips wrote:
>I'm trying to define a relaxNG schema for a rather complicated 
>document and I'm getting confused. Basically, I'm not sure how to 
>interleave elements outside of a group.
>...
>Basically, I want a single schema that supports multiple documents, 
>something like this:

Thank you for supplying so many examples, as that made testing a result easier.

>The problem is that I think this requires the group containing type 
>and card_data to be in order;

It does not.  You can interleave with an interleaved group.

>If there isn't a solution, does this mean I'm designing a stupid 
>schema and should be looking at a smarter layout?

Not at all ... please consider the example below.  I hope this helps.

. . . . . . . . . . Ken

p.s. I'm not sure why you are making the input so free-form.  Back in 
the SGML days I believe we (the community of SGML users and document 
designers) ended up coming to the conclusion that if the order of 
elements is not important, impose one on the users so that they don't 
somehow get the misinterpretation that order is important.  If they 
are allowed to choose they order, they might think this gives them 
some control over the meaning.  So if there is a user-controlled 
semantic by their choice of order, then by all means give them that 
choice.  On the other hand, if there is no order to the information, 
then give the users a single order to enter it so they understand 
they can't assume order has any importance.  Just a thought for you 
to consider.

t:\ftemp>type dusty.rnc
start = element payment
    {
       ( cash & amount )
       |
       ( credit & amount )
    }

cash = element type { "Cash" }

credit =
    (
       element type { "Credit Card" }
     &
       element card_data { text }
    )

amount = element amount { text }
t:\ftemp>type dusty1.xml
<payment>
     <type>Cash</type>
     <amount>42.42</amount>
</payment>

t:\ftemp>call rnc dusty.rnc dusty1.xml

t:\ftemp>type dusty2.xml
<payment>
     <amount>42.42</amount>
     <type>Cash</type>
</payment>

t:\ftemp>call rnc dusty.rnc dusty2.xml

t:\ftemp>type dusty3.xml
<payment>
     <type>Credit Card</type>
     <amount>42.42</amount>
     <card_data>
         <!-- subelements for card number, name, etc -->
     </card_data>
</payment>

t:\ftemp>call rnc dusty.rnc dusty3.xml

t:\ftemp>type dusty4.xml
<payment>
     <card_data>
         <!-- subelements for card number, name, etc -->
     </card_data>
     <amount>42.42</amount>
     <type>Credit Card</type>
</payment>

t:\ftemp>call rnc dusty.rnc dusty4.xml

t:\ftemp>type dusty5bad.xml
<payment>
     <type>Cash</type>
     <amount>42.42</amount>
     <card_data>
         <!-- subelements for card number, name, etc -->
     </card_data>
</payment>

t:\ftemp>call rnc dusty.rnc dusty5bad.xml
t:\ftemp\dusty5bad.xml:4:16: error: element "card_data" not allowed 
in this context

t:\ftemp>


--
XSLT/XQuery/XSL-FO training in Los Angeles (New dates!) 2009-06-08
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:[email protected]
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/r/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/r/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Reply via email to