I would try to convert an XML file to CSV and I am taking help from the following link but struck in a place where I have to retrieve the value from a two different tag that exists at the same level.
From the first tag, I have to select a value and from the next tag its child and sub-child tags values.
To select values from the second tag I am using an iterator and finally, I have to publish output in the same row but I don't know how to select values from the first tag as well as from the second tag and concatenate the values of the first tag with the values coming from the second tag.
For more clarification I have attached the following sample output:
My input XML sample as follows:
<PayLocation>
<LocationCode>VNS</LocationCode>
<LocationDescription>VARANASI</LocationDescription>
<PayrunDetails>
<PayrunNumber>000428</PayrunNumber>
</PayrunDetails>
<CompanyDetails>
<CompanyCode>Stack99</CompanyCode>
<CompanyName>StackOverFlow</CompanyName>
<Payslip>
<StaffNumber>123456</StaffNumber>
<StaffName>ALIBABA</StaffName>
<PayDetails>
<AmountNet>2100</AmountNet>
<ComponentDetails>
<ComponentType>SALARY</ComponentType>
<Code>SAL</Code>
</ComponentDetails>
</PayDetails>
<LeaveTaken>
<Description>LEAVE</Description>
<StartDate/>
<EndDate/>
</LeaveTaken>
</Payslip>
<Payslip>
<StaffNumber>456789</StaffNumber>
<StaffName>AMAZON</StaffName>
<PayDetails>
<AmountNet>2200</AmountNet>
<ComponentDetails>
<ComponentType>SALARY</ComponentType>
<Code>SAL</Code>
</ComponentDetails>
</PayDetails>
<LeaveTaken>
<Description>LEAVE</Description>
<StartDate>2015-05-28</StartDate>
<EndDate>2015-05-31</EndDate>
</LeaveTaken>
</Payslip>
</CompanyDetails>
</PayLocation>
My expected output sample is as follows:
Above Output contains first column values I got from the first tag and rest of the values I got from the second tag and its child tags.
I am also sharing my XSL file:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" >
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
StaffNumber,Payslip
<xsl:for-each select="//PayLocation/CompanyDetails/Payslip">
<xsl:value-of select="concat(StaffNumber,',',PayDetails/AmountNet,'
')"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Please note that I have not mention PayNumber, CompanyCode, CompanyName in the above XSL file because I don't know how to select values of the first tag along with the second tag. I'm fairly new to XSLT so please excuse the potential novice question. Any guidance would be appreciated here. Thanks in advance.
StaffNumber,StaffName
although theStaffName
is not even listed in the output? – Martin Honnen