#!/usr/bin/perl

use SGMLS::Refs;

sgml('start', '');
sgml('end', sub { close STDOUT or die $!; });

sub begin_ss {
    my ($lev,$elem,$event) = @_;
    $ctr[$lev]++;
    $#ctr= $lev;
}
for ($x=0;$x<=4;$x++) {
    $ss= 'S'x$x;
    $d= "sgml('<S$ss>', sub { &begin_ss($x,\@_); }); 1;";
    eval $d or die $@;
}

sub a {
    my $z= $_[0]->attribute($_[1]);
    return defined $z ? $z->value : undef;
}

sub deflab {
    my ($elem,$event) = @_;
    $num= join('.',@ctr);
    $txt= a($elem,'TXT');
    print "ATXT CDATA $txt\nANUM CDATA $num\n(PREDEF\n)PREDEF\n" or die $!;
}

sgml('<DEF>', \&deflab);
sgml('<LAB>', \&deflab);

sgml('cdata', '');
sgml('sdata', '');
sgml('re', '');
