Re: spot/remove repeated elements in XML documet
Manuel Souto Pico <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
This is very interesting, I didn't know xpathscript. I'm having a look... One question, though: do you know if it's possible to install it under Windows? If not, I won't be able to use it at work, but then I will try it at home... Thanks, Yanick. Manuel [email protected] escribió: > On Wed, Feb 04, 2009 at 04:28:06PM +0100, mirod wrote: > >> Manuel Souto Pico wrote: >> >> > My question is: Is there any easy way to spot and/or remove repeated >> > elements? I suppose it could be done with XSL or a perl module for XML... >> > > For giggles, here's a way to do it using XML::XPathScript. > Although if the document is big, and if all you want to do is to remove > duplicate elements, XML::Twig is really a more appropriate tool. > > > $ cat removedups.xps > <% > > use 5.10.0; > > $t->set( entry => { > showtag => 1, > testcode => \&test_entry > } ); > > sub test_entry { > my $node = shift; > > state %already_seen; > > my( $eng, $spa ) = map { $node->findvalue( "$_/text()" ) } qw/ Eng Spa /; > > return $already_seen{$eng}{$spa}++ ? $DO_NOT_PROCESS > : $DO_SELF_AND_KIDS > ; > } > > %> > > <%~ / %> <%# transform the root element and all its children %> > > $ xpathscript doc.xml removedups.xps > > <document> > <entry id="10"> > <Eng>house</Eng> > <Spa>casa</Spa> > </entry> > <entry id="11"> > <Eng>shoe</Eng> > <Spa>zapato</Spa> > </entry> > > </document> > > > > Joy, > `/anick > _______________________________________________ > Perl-XML mailing list > [email protected] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > > _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs