Since my Solution 1 is not really applicable (the tags are not XML conformant), enclosed please find an alternative version in Perl.
Cheers
Andi
use strict;
my $data = readfile(shift);
my $currentlevel = 0;
while($data =~ s%^[\s\S]*?<(P_list-(\w+)\((\d+)\))>(.*?)</\1>\s*%%g)
{
my ($tag, $kind, $level, $text) = ($1, $2, $3, $4);
if ($currentlevel < $level) {
while($currentlevel < $level) {
printBeginList($kind);
printBeginItem();
$currentlevel++;
}
} elsif ($currentlevel > $level) {
while($currentlevel > $level) {
$currentlevel--;
printEndItem();
printEndList();
}
printEndItem();
printBeginItem();
} else {
printEndItem();
printBeginItem();
}
printItem($text);
}
while($currentlevel > 0) {
$currentlevel--;
printEndItem();
printEndList();
}
exit 0;
sub readfile {
my ($file) = @_;
my $sep = $/;
$/ = undef;
open(F, $file) or die("Failed to read '$file' ($!)");
my $data = <F>;
close(F);
$/ = $sep;
return $data;
}
sub getType {
my ($kind) = @_;
return $kind eq "bull" ? "bullet" : $kind;
}
sub printBeginList {
my ($kind) = @_;
print "\n<list list-type=\"", getType($kind), "\">\n";
}
sub printEndList {
print "</list>\n";
}
sub printBeginItem {
print "<list-item><p>";
}
sub printEndItem {
print "</p></list-item>\n";
}
sub printItem {
my ($text) = @_;
print $text;
}