OmniMark groups is a nice feature to group your elements.
You can compare it with the “mode” feature in XSLT.

Let’s look first at an example without using groups.

input.xml file
  1. <doc>
  2.     <p>
  3.         <al>Alinea not in table</al>
  4.     </p>
  5.     <table>
  6.         <row><al>a1</al><al>a2</al></row>
  7.         <row><al>b1</al><al>b2</al></row>
  8.     </table>
  9. </doc>
  1. process
  2.   do xml-parse
  3.     scan file 'input.xml'
  4.     output '%c'
  5.   done
  6.  
  7. element #implied
  8.   output '<%q>%c</%q>'
output result
  1. <doc>
  2.     <p>
  3.         <al>Alinea not in table</al>
  4.     </p>
  5.     <table>
  6.         <row><al>a1</al><al>a2</al></row>
  7.         <row><al>b1</al><al>b2</al></row>
  8.     </table>
  9. </doc>

Changing <al> element without groups

  1. process
  2.   do xml-parse
  3.     scan file 'input.xml'
  4.     output '%c'
  5.   done
  6.  
  7. element #implied
  8.   output '<%q>%c</%q>'
  9.  
  10. element al when open element isnt table
  11.   output '<alinea>%c</alinea>'
  12.  
  13. element al when open element is table
  14.   output '<td>%c</td>'
output result
  1. <doc>
  2.     <p>
  3.         <alinea>Alinea not in table</alinea>
  4.     </p>
  5.     <table>
  6.         <row><td>a1</td><td>a2</td></row>
  7.         <row><td>b1</td><td>b2</td></row>
  8.     </table>
  9. </doc>

Doing the same with groups

  1. process
  2.   using group my-maingroup
  3.     do xml-parse
  4.       scan file 'input.xml'
  5.       output '%c'
  6.     done
  7.  
  8. ;group #implied  
  9. element #implied
  10.   output '<%q>%c</%q>'
  11.  
  12. group my-maingroup
  13.   element al
  14.     output '<alinea>%c</alinea>'
  15.  
  16.   element table
  17.     using group my-table-processing
  18.       output '<%q>%c</%q>'    
  19.  
  20. group my-table-processing
  21.   element al
  22.     output '<td>%c</td>'
same output result with groups
  1. <doc>
  2.     <p>
  3.         <alinea>Alinea not in table</alinea>
  4.     </p>
  5.     <table>
  6.         <row><td>a1</td><td>a2</td></row>
  7.         <row><td>b1</td><td>b2</td></row>
  8.     </table>
  9. </doc>

The using keyword makes it possible to scope your element rules and this scoping can be nested.
We start with using group my-maingroup at the beginning of the parsing process.
The element rules without a group or in the group #implied are ALWAYS active (that’s why commenting it out with “;” gives the same result) even when an other group is in scope.
So for instance the <doc> element and the <row> element are processed by the element #implied rule.
So writing:
using group my-maingroup
is the same as writing
using group my-maingroup & group #implied
Writing:
using group my-table-processing
is the same as writing
using group my-table-processing & group #implied

Rating 3.00 out of 5
[?]