I am converting my XML file to CSV using XML2CSV
The XML format can be simplified to
<PersonalInfo>
<UserDetail>
<FirstName>ABC</FirstName>
<Occupation>Student</Occupation>
<DateOfBirth>08/14/1999</DateOfBirth>
</UserDetail>
<CaseDetail>....</CaseDetail>
<TransactionDetail></TransactionDetail>
</PersonalInfo>
<PersonalInfo>
<UserDetail>
<FirstName>XYZ</FirstName>
<Occupation>Student</Occupation>
<DateOfBirth>04/25/1991</DateOfBirth>
</UserDetail>
<CaseDetail>....</CaseDetail>
<TransactionDetail></TransactionDetail>
</PersonalInfo>
<PersonalInfo>
<UserDetail>
<FirstName>DEF</FirstName>
<Occupation>Teacher</Occupation>
<DateOfBirth>05/12/1984</DateOfBirth>
</UserDetail>
<CaseDetail>....</CaseDetail>
<TransactionDetail></TransactionDetail>
</PersonalInfo>
While using the XML to CSV converter i only want to convert those fields where the Occupation tag has value of Student. Is it possible through this or i have to use some other script to make a final xml file, then convert that to CSV. Any Ideas.
EDIT: Only Values of FirstName, Occupation and DateOfBirth are needed. No value from CaseDetail or TransactionDetail should be in the resultant file.
The format of the end file should be like
ABC|Student|08/14/1999
XYZ|Student|04/25/1991
Extending my comment to a real answer now. Here’s the xslt I used to convert the xml to csv directly. (I used libxml2’s
xsltprocto do the actual conversion)applied to your xml this gives: