Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Increment the tag content using XML::Twig

by Jenda (Abbot)
on Apr 04, 2007 at 09:35 UTC ( [id://608233]=note: print w/replies, xml ) Need Help??


in reply to Increment the tag content using XML::Twig

Sorry, not a XML::Twig solution:

use strict; use warnings; use XML::Rules; my $parser = XML::Rules->new( rules => [ _default => 'raw', item => 'as array', orderedlist => sub { delete $_[1]->{_content}; # remove the whitespace for (my $inst = 1; $inst <= @{$_[1]->{item}}; $inst++) { push @{$_[1]->{_content}}, "\n", [inst => "\t$inst.\t" +], [item => $_[1]->{item}[$inst-1]]; } push @{$_[1]->{_content}}, "\n"; delete $_[1]->{item}; return $_[0] => $_[1]; } ], style => 'filter', ); $parser->filter(\*DATA); __DATA__ <chapter> <chbody> <exercises att="problems"> <title>Content</title> <orderedlist numeration="number"> <item><para>Text1</para></item> <item><para>Text2</para></item> <item><para>Text3</para></item> </orderedlist> <orderedlist numeration="number"> <item><para>Text1</para></item> <item><para>Text2</para></item> <item><para>Text3</para></item> <item><para>Text4</para></item> </orderedlist> </exercises> </chbody> </chapter>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://608233]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-16 15:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found