Sample Xml file;
<?xml version="1.0"?>
<LevelSet displayName="Sides">
<Level uniqueID="0" PayReceive="Pay" CommodityCode="" CommodityName="GAS" LocationCode="" NearbyDescription="First">
<SubLevelSets>
<SubLevelSet displayName="Discreet Periods">
<SubLevel uniqueID="1" PD="1" StartDate="20160101" EndDate="20160131" PaymentDate="20160222" DenominationCCY="USD" DiscountFactor="0.999618" ClientPV="-314639.64" />
<SubLevel uniqueID="2" PD="2" StartDate="20160201" EndDate="20160229" PaymentDate="20160321" DenominationCCY="USD" DiscountFactor="0.999182" ClientPV="-263423.84" />
</SubLevelSet>
</SubLevelSets>
</Level>
<Level uniqueID="1" PayReceive="Receive" CommodityCode="" CommodityName="GAS" LocationCode="" NearbyDescription="First">
<SubLevelSets>
<SubLevelSet displayName="Discreet Periods">
<SubLevel uniqueID="1" PD="1" StartDate="20160101" EndDate="20160131" PaymentDate="20160222" DenominationCCY="USD" DiscountFactor="0.999618" ClientPV="871990.82" />
<SubLevel uniqueID="2" PD="2" StartDate="20160201" EndDate="20160229" PaymentDate="20160321" DenominationCCY="USD" DiscountFactor="0.999182" ClientPV="832316.89" />
</SubLevelSet>
</SubLevelSets>
</Level>
</LevelSet>
Expected output;
PayReceive,CommodityName,StartDate,ClientPV
Pay,GAS,20160101,-314639.64
Pay,GAS,20160201,-263423.84
Receive,GAS,20160101,871990.82
Receive,GAS,20160201,832316.89
Below is the xsl I am using
<?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="/">
PayReceive,CommodityName,StartDate,ClientPV
<xsl:for-each select="//Level">
<xsl:value-of select="@PayReceive"/><xsl:text>,</xsl:text>
<xsl:value-of select="@CommodityName" /><xsl:text>,</xsl:text>
<xsl:for-each select="//SubLevel">
<xsl:value-of select="@StartDate"/><xsl:text>,</xsl:text>
<xsl:value-of select="@ClientPV"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>