I am trying to process some XML to reform it so that this input, however the issue i am getting can be illustrated better below:
INPUT
<?xml version="1.0" encoding="UTF8"?>
<doc:ZINITIALIZE_FILTERS.Response xmlns:doc="urn:sapcom:document:sap:rfc:functions">
<MESSAGE>Success</MESSAGE>
<STATUS>0</STATUS>
<COLLECTION>
<item>
<COLLECTION>A1</COLLECTION>
<SEASON>S09</SEASON>
<TEXT>Spring Market A1</TEXT>
</item>
<item>
<COLLECTION>A1</COLLECTION>
<SEASON>S10</SEASON>
<TEXT>Spring Market A1</TEXT>
</item>
</COLLECTION>
</doc:ZINITIALIZE_FILTERS.Response>
DESIRED OUTPUT:
<?xml version="1.0" encoding="UTF8"?>
<doc:ZINITIALIZE_FILTERS.Response xmlns:doc="urn:sapcom:document:sap:rfc:functions">
<MESSAGE>Success</MESSAGE>
<STATUS>0</STATUS>
<COLLECTION>
<item>
<COLLECTION>A1</COLLECTION>
<SEASON>S09,S10</SEASON>
<TEXT>Spring Market A1</TEXT>
</item>
</COLLECTION>
</doc:ZINITIALIZE_FILTERS.Response>
XSLT being used:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="k" match="item" use="COLLECTION"/>
<xsl:template match="/ZINITIALIZE_FILTERS.Response">
<xsl:copy>
<COLLECTIONS>
<xsl:apply-templates select="COLLECTION/item[generate-id() =
generate-id(key('k', COLLECTION))]"/>
</COLLECTIONS>
</xsl:copy>
</xsl:template>
<xsl:template match="COLLECTION/item">
<xsl:copy>
<xsl:copy-of select="COLLECTION"/>
<SEASON>
<xsl:for-each select="key('k', COLLECTION)">
<xsl:value-of select="SEASON"/>
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</SEASON>
<xsl:copy-of select="TEXT"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
CURRENT INCORRECT OUTPUT:
<?xml version="1.0" encoding="UTF-8"?>
<ZINITIALIZE_FILTERS.Response xmlns=""><?xml version="1.0"?>
Success0<item xmlns:doc="urn:sap-com:document:sap:rfc:functions"><COLLECTION>A1</COLLECTION><SEASON>S09,S10,S12</SEASON><TEXT>Spring Market A1</TEXT></item>
</ZINITIALIZE_FILTERS.Response>
Can anyone help?
Use:
When applied to this XML:
it produces wanted correct result: