package XML::Filter::Transition;

# turn on Perl's safety features

use strict;
use warnings;

# use the XML::SAX::Base class so that unhandled events
# are just passed straight though

use base qw(XML::SAX::Base);

# simple constuctor method

sub new {
  my $class = shift;
  my %options = @_;
  return bless \%options, $class;
}

# implement a method that catches any start tags

sub start_element {

  my $self = shift; # the sax processor
  my $tag  = shift; # the tag itself

  # is this a subpoint tag?

  if ($tag->{Name} eq "spoint") {

    # rename it 'point' instead of 'spoint'

    $tag->{Name} = "point";             # qualified name
    $tag->{LocalName} = $tag->{Name};   # unqualified name

    # add an attribute for the level and set the properties
    $tag->{Attributes}{'{}level'} = {
		       LocalName => 'level',
		       Prefix => '',
		       Value => '2',
  		       Name => 'level',
		       NamespaceURI => ''}
  }

  elsif ($tag->{Name} eq "sspoint") {

    # rename it 'point' instead of 'sspoint'

    $tag->{Name} = "point";             # qualified name
    $tag->{LocalName} = $tag->{Name};   # unqualified name

    # add an attribute for the level and set the properties
    $tag->{Attributes}{'{}level'} = {
		       LocalName => 'level',
		       Prefix => '',
		       Value => '3',
  		       Name => 'level',
		       NamespaceURI => ''}
  }

  elsif ($tag->{Name} eq "tt") {

    # rename it 'span' instead of 'tt'

    $tag->{Name} = "span";             # qualified name
    $tag->{LocalName} = $tag->{Name};   # unqualified name

    # add an attribute for style and set the properties
    $tag->{Attributes}{'{}style'} = {
		       LocalName => 'style',
		       Prefix => '',
		       Value => 'font-family: monospace; font-weight: bold',
  		       Name => 'style',
		       NamespaceURI => ''}
  }

  # return the tag (following pipeline conventions)

  return $self->SUPER::start_element($tag);

}

# and a simliar one that catches end tags

sub end_element {

  my $self = shift; # the sax processor
  my $tag  = shift; # the tag itself

  # is this a spoint or sspoint tag?

  if ($tag->{Name} eq "spoint" or $tag->{Name} eq "sspoint") {
    # rename it 'point' instead
    $tag->{Name} = "point";             # qualified name
    $tag->{LocalName} = $tag->{Name};   # unqualified name
  }

  # is this a tt tag?

  if ($tag->{Name} eq "tt") {
    # rename it 'span' instead
    $tag->{Name} = "span";             # qualified name
    $tag->{LocalName} = $tag->{Name};   # unqualified name
  }
  
  # return the tag (following pipeline conventions)

  return $self->SUPER::end_element($tag);

}

1; # all perl modules need to return "true"     
