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.

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

Changing <al> element without groups

1
2
3
4
5
6
7
8
9
10
11
12
13
14
process
  do xml-parse
    scan file 'input.xml'
    output '%c'
  done
 
element #implied
  output '<%q>%c</%q>'

element al when open element isnt table
  output '<alinea>%c</alinea>'

element al when open element is table
  output '<td>%c</td>'
1
2
3
4
5
6
7
8
9
10
output result
<doc>
    <p>
        <alinea>Alinea not in table</alinea>
    </p>
    <table>
        <row><td>a1</td><td>a2</td></row>
        <row><td>b1</td><td>b2</td></row>
    </table>
</doc>

Doing the same with groups

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
process
  using group my-maingroup
    do xml-parse
      scan file 'input.xml'
      output '%c'
    done
 
;group #implied  
element #implied
  output '<%q>%c</%q>'

group my-maingroup
  element al
    output '<alinea>%c</alinea>'

  element table
    using group my-table-processing
      output '<%q>%c</%q>'    

group my-table-processing
  element al
    output '<td>%c</td>'
1
2
3
4
5
6
7
8
9
10
same output result with groups
<doc>
    <p>
        <alinea>Alinea not in table</alinea>
    </p>
    <table>
        <row><td>a1</td><td>a2</td></row>
        <row><td>b1</td><td>b2</td></row>
    </table>
</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
[?]