<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<ns0:DataResponse xmlns:ns0="http://somenamspace/v1.0">
<ns0:ResponseId>
<ns0:RequestID>12345</ns0:RequestID>
</ns0:ResponseId>
<ns0:Payload>
<ns1:Product xmlns:ns1="http://anothernamespace/v1.x">
<ns1:ProductName>productName</ns1:ProductName>
<ns1:ProductIdentifier>12222</ns1:ProductIdentifier>
<ns1:ProdInst>
<ns1:Type>Conv</ns1:Type>
<ns1:Descr>Conventional Loan</ns1:Descr>
<ns1:AllowedTypes>
<ns1:ScheduleSchedule>true</ns1:ScheduleSchedule>
</ns1:AllowedTypes>
<ns1:prdExist>false</ns1:prdExist>
<ns1:AdditionalAttributes>
<ns1:AdditionalAttribute name="gura" value="C"/>
</ns1:AdditionalAttributes>
</ns1:ProdInst>
<ns1:ProductGroups>
<ns1:ProductGroupName>1111</ns1:ProductGroupName>
<ns1:ProductGroupName>2222</ns1:ProductGroupName>
</ns1:ProductGroups>
</ns1:Product>
<ns1:Product>
.......
</ns1:Product>
</ns0:Payload>
</ns0:DataResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
------------------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns0="http://somenamespace/v1.0"
xmlns:ns1="http://anothernamespace/v1.x"
exclude-result-prefixes="ns1">
<xsl:output omit-xml-declaration="yes" indent="no" method="text"/>
<xsl:template match="ns1:Products">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
----------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://namespace/v1.x"
exclude-result-prefixes="ns1">
<xsl:output omit-xml-declaration="yes" indent="no" method="text"/>
<xsl:template match="/">
<xsl:for-each select="ns1:Product">
<xsl:value-of select="ns1:ProductName" />
<xsl:text>,</xsl:text>
<xsl:value-of select="ns1:ProdInst/ns1:Type" />
<xsl:text>,</xsl:text>
<xsl:value-of select="ns1:ProdInst/ns1:Descr" />
<xsl:text>,</xsl:text>
<xsl:value-of select="ns1:ProdInst/ns1:AdditionalAttributes/@gura" />
<xsl:text>,</xsl:text>
<xsl:for-each select="ns1:ProductGroups">
<xsl:value-of select="."/>
</xsl:for-each>,
</xsl:for-each>
</xsl:template>
Basically I am trying to write the XSL to convert all these "Product" inner attribute values to the CSV format. I already struggled with overcome using the namespaces but still could not write up in the perfect format, sometimes the styles going on next line , and if I tried the generic one then the problem as could not read the additionalAtrributes values. any help on this would be great.
Expecting output as all the tag inner attributes lined up in the CSV format with "," in order .
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://somenamspace/v1.0"
xmlns:ns1="http://anothernamespace/v1.x"
exclude-result-prefixes="ns1">
<xsl:output method="text" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="ns1:Product"/>
</xsl:template>
<xsl:template match="ns1:Product">
<xsl:value-of select="*"/>
<xsl:apply-templates select="ns1:ProdInst"/>
<xsl:apply-templates select="ns1:ProductGroups"/>
</xsl:template>
<xsl:template match="ns1:ProdInst">
<xsl:value-of select="."/>
<xsl:apply-templates select="ns1:AllowedTypes"/>
<xsl:apply-templates select="ns1:AdditionalAttributes"/>
</xsl:template>
<xsl:template match="ns1:AllowedTypes">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="ns1:AdditionalAttributes">
<xsl:for-each select="@*">
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I have tried as above and got atleast all in the same line, but still its not comma seperated also the "AdditionalAttributes" are not included. can anybody help on this?
Please have a look this solution:
XSLT:
OUTPUT: