--- loncom/xml/lonxml.pm 2000/08/03 19:34:11 1.16 +++ loncom/xml/lonxml.pm 2000/08/08 19:34:29 1.17 @@ -45,8 +45,8 @@ sub xmlparse { my @stack = (); my @parstack = (); + &initdepth; my $token; - print $#pars; while ( $#pars > -1 ) { while ($token = $pars[$#pars]->get_token) { if ($token->[0] eq 'T') { @@ -57,26 +57,26 @@ sub xmlparse { push (@stack,$token->[1]); # add parameters list to another stack push (@parstack,&parstring($token)); - + &increasedepth(); if (exists $style_for_target{$token->[1]}) { $finaloutput .= &recurse($style_for_target{$token->[1]}, $target,$safeeval,\%style_for_target, @parstack); } else { - my $result = &callsub("start_$token->[1]", $target, $token,\@parstack, + $result = &callsub("start_$token->[1]", $target, $token,\@parstack, \@pars, $safeeval, \%style_for_target); } } elsif ($token->[0] eq 'E') { #clear out any tags that didn't end while ($token->[1] ne $stack[$#stack] - && ($#stack > -1)) {pop @stack;pop @parstack;} + && ($#stack > -1)) {pop @stack;pop @parstack;&decreasedepth;} if (exists $style_for_target{'/'."$token->[1]"}) { $finaloutput .= &recurse($style_for_target{'/'."$token->[1]"}, $target,$safeeval,\%style_for_target, @parstack); } else { - my $result = &callsub("end_$token->[1]", $target, $token, \@parstack, + $result = &callsub("end_$token->[1]", $target, $token, \@parstack, \@pars,$safeeval, \%style_for_target); } } @@ -89,7 +89,7 @@ sub xmlparse { } $result = ''; } - if ($token->[0] eq 'E') { pop @stack;pop @parstack; } + if ($token->[0] eq 'E') { pop @stack;pop @parstack;&decreasedepth;} } pop @pars; } @@ -114,13 +114,15 @@ sub recurse { } elsif ($tokenpat->[0] eq 'S') { push (@innerstack,$tokenpat->[1]); push (@innerparstack,&parstring($tokenpat)); + &increasedepth(); $partstring = &callsub("start_$tokenpat->[1]", $target, $tokenpat, \@innerparstack, \@pat, $safeeval, $style_for_target); } elsif ($tokenpat->[0] eq 'E') { #clear out any tags that didn't end while ($tokenpat->[1] ne $innerstack[$#innerstack] - && ($#innerstack > -1)) {pop @innerstack;pop @innerparstack;} + && ($#innerstack > -1)) {pop @innerstack;pop @innerparstack; + &decreasedepth;} $partstring = &callsub("end_$tokenpat->[1]", $target, $tokenpat, \@innerparstack, \@pat, $safeeval, $style_for_target); @@ -144,7 +146,8 @@ sub recurse { $output .= &Apache::run::evaluate($partstring,$safeeval,$decls); $partstring = ''; } - if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack; } + if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack; + &decreasedepth;} } pop @pat; } @@ -159,6 +162,7 @@ sub callsub { if (my $space=$Apache::lonxml::alltags{$token->[1]}) { #print "Calling sub $sub in $space \n"; $sub="$space\:\:$sub"; + $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter); $currentstring = &$sub($target,$token,$parstack,$parser, $safeeval,$style); } else { @@ -174,6 +178,28 @@ sub callsub { return $currentstring; } +sub initdepth { + @Apache::lonxml::depthcounter=(); + $Apache::lonxml::depth=-1; + $Apache::lonxml::olddepth=-1; +} + +sub increasedepth { + if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) { + $#Apache::lonxml::depthcounter--; + $Apache::lonxml::olddepth=$Apache::lonxml::depth; + } + $Apache::lonxml::depth++; + $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++; + if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) { + $Apache::lonxml::olddepth=$Apache::lonxml::depth; + } +} + +sub decreasedepth { + $Apache::lonxml::depth--; +} + sub parstring { my ($token) = @_; my $temp='';