Ok, try this

#!/usr/bin/perl use strict; use XML::LibXML; use List::Util qw{ uniq }; my $dom = 'XML::LibXML'->load_xml(IO => *DATA); my @headers = (); my @lang = (); for ($dom->findnodes('//tu/prop/@type')){ push @headers, 'tu:'.$_->value; } for my $tuv ($dom->findnodes('//tu/tuv')){ my $lang = $tuv->findvalue('@xml:lang'); push @lang, $lang; for ($tuv->findnodes('prop/@type')){ push @headers, 'tuv:'.$_->value.':'.$lang; } } @headers = sort +uniq(@headers); @lang = sort +uniq(@lang); push @headers,@lang; # add lang open OUT,'>','report.dat' or die "$!"; print OUT join "\t",@headers,"\n"; for my $tu ($dom->findnodes('/tmx/body/tu')) { my %props; for my $prop ($tu->findnodes('prop')) { $props{ 'tu:'.$prop->findvalue('@type') } = $prop->textContent; } for my $tuv ($tu->findnodes('tuv')) { my $lang = $tuv->findvalue('@xml:lang'); ($props{$lang} = $tuv->findvalue('seg')) =~ s{\n}{<lb/>}g; for my $prop ($tuv->findnodes('prop')) { my $name = join ':','tuv',$prop->findvalue('@type'),$lang; $props{$name} = $prop->textContent; } } print OUT join ("\t", map $_ // "", @props{@headers}), "\t"; print OUT "\n"; } __DATA__ <?xml version="1.0" encoding="UTF-8"?> <tmx version="1.4"> <header creationtool="xx" creationtoolversion="1" segtype="sentence" o +-tmf="undefined" adminlang="en" srclang="en" datatype="undefined"> </header> <body> <tu changedate="20180321T113135Z" creationdate="20180321T113135Z" chan +geid="user" tuid="1"> <prop type="client"> a </prop> <prop type="project"> b </prop> <prop type="domain"> c </prop> <prop type="subject"> d </prop> <prop type="corrected">no</prop> <prop type="aligned">no</prop> <tuv xml:lang="en"><seg>Hello <b>world!</b></seg></tuv> <tuv xml:lang="fr"><seg>Bonjour <b> monde</b></seg></tuv> </tu> <tu changedate="20180321T113135Z" creationdate="20180321T113135Z" chan +geid="user2" tuid="2"> <prop type="client"> 1 </prop> <prop type="project">yes</prop> <prop type="corrected">no</prop> <prop type="aligned">no</prop> <tuv xml:lang="en"> <prop type="client"> zyx </prop> <seg>Hello <b>world!</b></seg> </tuv> <tuv xml:lang="fr"> <prop type="client"> 2 </prop> <prop type="project">yes 2</prop> <prop type="corrected">no 2</prop> <prop type="aligned">no 2</prop> <seg>Bonjour <b> monde</b></seg> </tuv> </tu> </body> </tmx>
poj

In reply to Re^5: Strip XML document by poj
in thread Strip XML document by corfuitl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.