Just RELAX-NG in the heat

Yow, it's hot here in North Carolina. Close to 100°F (38°C) for the next few days.

In some of my hobby hours, I'm constructing an XML document that contains a lot of constants and relationships that pertain to machining. Part of it has to do with drill sizes, and equivalents between standard metric and ANSI sizes. For example, ANSI drill size #92 is equivalent to standard metric drill 0.20mm. They're the same drill, though, so I'm trying to keep it all in one element tree:

  <drill>
    <group system="ANSI" units="in">
      <name>92</name>
      <diameter>0.0079</diameter>
    </group>
    <group system="metric" units="mm">
      <name>0.20</name>
      <altname>0_20</altname>
      <diameter>0.20</diameter>
    </group>
  </drill>

However, most drills don't suffer from this sort of identity crisis, and their definitions look more like this:

  <drill system="ANSI" units="in">
    <name>89</name>
    <diameter>0.0091</diameter>
  </drill>

Now, every drill needs to have at least one <name> and one <diameter> element somewhere. I just haven't figured out how to get RELAX-NG (compact) to understand that it can either be a direct child of the <drill> element, or a child of some descendant <group> element.

This bit of RNC takes care of the simple case:

element.drill = element drill
    {
        attribute.system?,
        attribute.units?,
        (
              element.group*
            & element.name
            & element.altname*
            & element.diameter
        )
    }

but so far specifying the more involved one has eluded me..

Be the first to write a comment!