nayakss@in.com 0 Newbie Poster

I need to tranform an xml to tsv but I am facing some problem with looping.
<Test.xml>

<Tag1>
<Tag2>
<subtag1>
<subtag2 F=1 Yr=2007/>
<subtag2 F=2 Yr=2008/>
<subtag2 F=3 Yr=2009/>
<subtag2 F=4 Yr=2007/>
<subtag2 F=5 Yr=2008/>
<subtag2 F=6 Yr=2009/>
<subtag2 F=7 Yr=2007/>
<subtag2 F=8 Yr=2008/>
<subtag2 F=9 Yr=2009/>
<subtag2 F=10 Yr=2007/>
<subtag2 F=11 Yr=2008/>
<subtag2 F=12 Yr=2009/>
</subtag1>
</Tag2>
<Tag3>
<stag1>
<V F=1 >ABC</V>
<V F=2 >DEF</V>
<V F=3 >123</V>
</stag1>
<stag2>
<V F=1 >ssss</V>
<V F=2 >DDD</V>
<V F=3 >121</V>
</stag2
</Tag3>
<Tag3>
<stag1>
<V F=4 >A1B2C3</V>
<V F=5 >D2E3F5</V>
<V F=6 >243</V>
</stag1>
<stag2>
<V F=4 >s3ds</V>
<V F=5 >DsDD</V>
<V F=6 >141</V>
</stag2
</Tag3>
<Tag3>
<stag1>
<V F=7 >AABC</V>
<V F=8 >DDEF</V> 
</stag1>
<stag2>
<V F=7 >sTUV</V>
<V F=8 >DSDS</V>
</stag2
</Tag3>
<Tag3>
<stag1>
<V F= 11>XYZ</V>
<V F=12 >999</V> 
</stag1>
<stag2>
<V F=11 >LLL</V>
<V F=12 >888</V>
</stag2
</Tag3>
</Tag1>

Desired Output
output.tsv

ABC DEF 123 ssss DDD 121
A1B2C3 D2E3F5 243 s3ds DsDD 141
AABC DDEF NULL sTUV DSDS NULL
NULL XYZ 999 NULL LLL 888

I have designed a xsl file to transform the above xml and parse it using perl. Till now my script works fine because in side Tag3/stag1/ and Tag3/stag2, we always have 3 entries. For todays file we have some stag1 amd stag2 where we have only 2 entries or 1 entris. Which causes problem and my output file has wrong number of coloumns for those entries. Now I want to check each "F" value inside stag1 amd stag2 and map it to /tag2/subtag1 /subtag2 "F" values. For each non matching, It should have null value against those years.

I don't how can I map the "F" value in stag1 and stag2 with "F" subtag1/subtag2. Can any one please help me out?

Thanks,
Siba S Nayak

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.