Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7677301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:23:31+00:00 2026-05-31T17:23:31+00:00

I am trying to process some XML to reform it so that this input,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:23:32+00:00Added an answer on May 31, 2026 at 5:23 pm

    Use:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
        <xsl:output method="xml" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:key name="k" match="item" use="COLLECTION"/>
    
        <xsl:template match="item[generate-id() = generate-id(key('k', COLLECTION))]">
            <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:template match="item"/>
    
        <xsl:template match="@* | node()">
            <xsl:copy>
                <xsl:apply-templates select="@* | node()"/>
            </xsl:copy>
        </xsl:template>
    
    </xsl:stylesheet>
    

    When applied to this XML:

    <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>
    

    it produces wanted correct result:

    <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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a console app that would monitor some process and restart
I've been trying to parse some huge XML files that LXML won't grok, so
I'm trying to write some xml by this piece of code docs = XmlReportGenerator()
I'm trying to write some xml by this piece of code docs = XmlReportGenerator()
I'm trying to convert some XML so that iso8879 entity strings will appear in
I'm trying to incorporate some JavaScript unit testing into my automated build process. Currently
I am trying to add some custom build steps to my headless build process
I am trying to fully understand the process pro writing code in some language
I am trying to process files one at a time that are stored over
I am trying to process a CSV file in which some of the fields

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.