Hi Gurus, Am trying to club the <text entries together those having same y & page attribute values from the below input.
Am performing this individually those having two & three <text> entries with in <font> block:
<font...><text..><text..></font>
&
<font...><text..><text..><text..></font>
when trying with <font..> block having two <text> entries it's not working please clarify me what's the defect?
Input a.xml
-----------
<font size="12" face="IJCINN+AvantGarde-Bold" color="#1BADEB">
<text x="198" y="200" width="32" height="12" page="vii">Part I</text>
<text x="242" y="200" width="75" height="12" page="vii">Introduction</
+text>
<text x="329" y="200" width="7" height="12" page="vii">2</text>
</font>
<font size="9" face="IJCINN+AvantGarde-Bold" color="#231F20">
<text x="183" y="221" width="47" height="9" page="vii">Chapter 1</text
+>
</font>
<font size="10" face="IJCIOP+Frutiger-Light" color="#231F20">
<text x="242" y="220" width="121" height="10" page="vii">Managers and
+Management</text>
<text x="373" y="220" width="6" height="10" page="vii">2</text>
</font>
<font size="9" face="IJCINN+AvantGarde-Bold" color="#231F20">
<text x="198" y="234" width="32" height="9" page="vii">History</text>
<text x="195" y="246" width="35" height="9" page="vii">Module</text>
</font>
<font size="12" face="IJCINN+AvantGarde-Bold" color="#1BADEB">
<text x="194" y="292" width="36" height="12" page="vii">Part II</text>
<text x="242" y="292" width="54" height="12" page="vii">Planning</text
+>
<text x="308" y="292" width="15" height="12" page="vii">56</text>
</font>
------------------
Code
------------------
use warnings;
use strict;
undef $/;
open(A3a,"a.xml") or die "$!";
open(B3a, ">a5.xml") or die("Sorry!");
my $tab_space = 16;
my ($xa, $ya, $wida, $heiga, $paga, $inxa, $xaa, $yaa, $widaa, $heigaa
+, $pagaa, $inxaa);
my ($content2, $wid_new1);
$content2 = <A3a>;
$content2 =~s/\n//gi;
while($content2 =~m/<font size="(.*?)" face="(.*?)" color="(.*?)"><tex
+t x="(.*?)" y="(.*?)" width="(.*?)" height="(.*?)" page="(.*?)">(.*?)
+<\/text><text x="(.*?)" y="(.*?)" width="(.*?)" height="(.*?)" page="
+(.*?)">(.*?)<\/text><\/font>/msgi){
$xa = $4;
$ya = $5;
$wida = $6;
$heiga = $7;
$paga = $8;
$inxa = $9;
$xaa = $10;
$yaa = $11;
$widaa = $12;
$heigaa = $13;
$pagaa = $14;
$inxaa = $15;
if ($ya == $yaa && $paga == $pagaa){
$wid_new1 = $wida + $widaa + $tab_space;
$content2 =~s/<font size=\"(.*?)\" face=\"(.*?)\" color=\"(.*?
+)\"><text x=\"(.*?)\" y=\"(.*?)\" width=\"(.*?)\" height=\"(.*?)\" pa
+ge=\"(.*?)\">(.*?)<\/text><text x=\"(.*?)\" y=\"(.*?)\" width=\"(.*?)
+\" height=\"(.*?)\" page=\"(.*?)\">(.*?)<\/text><\/font>/<font>\n<tex
+t x=\"$xa\" y=\"$ya\" width=\"$wid_new1\" height=\"$heiga\" page=\"$p
+aga\">$inxa~~~$inxaa<\/text>\n/msgi;
}
else {
$content2 =~s/<font size=\"(.*?)\" face=\"(.*?)\" color=\"(.*?
+)\"><text x=\"(.*?)\" y=\"(.*?)\" width=\"(.*?)\" height=\"(.*?)\" pa
+ge=\"(.*?)\">(.*?)<\/text><text x=\"(.*?)\" y=\"(.*?)\" width=\"(.*?)
+\" height=\"(.*?)\" page=\"(.*?)\">(.*?)<\/text><\/font>/<font>\n<tex
+t x=\"$xa\" y=\"$ya\" width=\"$wida\" height=\"$heiga\" page=\"$paga\
+">$inxa<\/text>\n<text x=\"$xaa\" y=\"$yaa\" width=\"$widaa\" height=
+\"$heigaa\" page=\"$pagaa\">$inxaa<\/text>\n<\/font>\n/msgi;
}
print B3a $content2;
}
close (A3a);
close (B3a);
but it's working fine for three <text..> entries present in in <font..> block
use warnings;
undef $/;
open(A3,"a.xml") or die "$!";
open(B3, ">a4.xml") or die("Sorry!");
my $tab_space = 16;
my ($xx, $yy, $wid, $heig, $pag, $inx, $xx1, $yy1, $wid1, $heig1, $pag
+1, $inx1, $inx2, $xx2, $yy2, $wid2, $heig2, $pag2, $xx3, $yy3, $wid3,
+ $heig3, $pag3, $inx3, $size, $face, $color);
my ($content1, $wid1_new, $wid_new1);
$content1 = <A3>;
$content1 =~s/\n//gi;
while($content1 =~m/<font size="(.*?)" face="(.*?)" color="(.*?)"><tex
+t x="(.*?)" y="(.*?)" width="(.*?)" height="(.*?)" page="(.*?)">(.*?)
+<\/text><text x="(.*?)" y="(.*?)" width="(.*?)" height="(.*?)" page="
+(.*?)">(.*?)<\/text><text x="(.*?)" y="(.*?)" width="(.*?)" height="(
+.*?)" page="(.*?)">(.*?)<\/text><\/font>/gi){
$size = $1;
$face = $2;
$color = $3;
$xx1 = $4;
$yy1 = $5;
$wid1 = $6;
$heig1 = $7;
$pag1 = $8;
$inx1 = $9;
$xx2 = $10;
$yy2 = $11;
$wid2 = $12;
$heig2 = $13;
$pag2 = $14;
$inx2 = $15;
$xx3 = $16;
$yy3 = $17;
$wid3 = $18;
$heig3 = $19;
$pag3 = $20;
$inx3 = $21;
if ($yy1 == $yy2 && $yy2 == $yy3 && $pag1 == $pag2 && $pag2 == $pa
+g3){
$wid1_new = $wid1 + $wid2 + $wid3 + $tab_space;
print B3 "<text x=\"$xx1\" y=\"$yy1\" width=\"$wid1_new\" heig
+ht=\"$heig1\" page=\"$pag1\">$inx1^^^$inx2%%%$inx3<\/text>\n";
}
else {
print B3 "<font size=\"$size\" face=\"$face\" color=\"$color\"
+>\n<text x=\"$xx1\" y=\"$yy1\" width=\"$wid1\" height=\"$heig1\" page
+=\"$pag1\">$inx1<\/text>\n";
print B3 "<text x=\"$xx2\" y=\"$yy2\" width=\"$wid2\" height=\
+"$heig2\" page=\"$pag2\">$inx2<\/text>\n";
print B3 "<text x=\"$xx3\" y=\"$yy3\" width=\"$wid3\" height=\
+"$heig3\" page=\"$pag3\">$inx3<\/text>\n</font>\n";
}
}
close (A3);
close (B3);
Could someone please help me?
Thanks in advance,
Thirilog