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 8147583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:24:04+00:00 2026-06-06T14:24:04+00:00

I am having some issues with consuming an XML and applying multiple conditions on

  • 0

I am having some issues with consuming an XML and applying multiple conditions on it. I have an input XML that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType">
    <result>
        <resultSets>
            <resultSet>
                <row>
                    <column1>11111</column1>
                    <column2>0</column2>
                    <column3>imageId/111111</column3>
                    <column4>2012-04-03T10:11:22.187</column4>
                </row>
                <row>
                    <column1>11111</column1>
                    <column2>2</column2>
                    <column3>imageId/111112</column3>
                    <column4>2012-04-03T10:11:22.187</column4>
                </row>
                <row>
                    <column1>11111</column1>
                    <column2>2</column2>
                    <column3>imageId/111113</column3>
                    <column4>2012-04-03T10:11:22.187</column4>
                </row>
                <row>
                    <column1>22222</column1>
                    <column2>0</column2>
                    <column3>imageId/222222</column3>
                    <column4>2012-04-03T10:11:22.187</column4>
                </row>
                <row>
                    <column1>22222</column1>
                    <column2>2</column2>
                    <column3>imageId/222223</column3>
                    <column4>2012-04-03T10:11:22.187</column4>
                </row>
            </resultSet>
        </resultSets>
    </result>
</results>

However i would like it to look like this:

<?xml version="1.0" encoding="UTF-8"?>
<results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType">
    <result>
        <row>
            <id>11111</id>
            <lagrgeImage>imageId/111111</lagrgeImage>
            <smallImage>imageId/111112</smallImage>
            <smallImage>imageId/111113</smallImage>
        </row>
        <row>
            <id>22222</id>
            <lagrgeImage>imageId/222222</lagrgeImage>
            <smallImage>imageId/222223</smallImage>
        </row>
    </result>
</results>

As you can see there are two filtering condition:

If column2 = 0 then largeImage tag is needed in the output however column2 = 2 then smallImage tag is needed in the output.

UPDATE

Both of the examples below worked perfectly, however they are both including namespacing in the root that are unexpected. The output i get is:

<?xml version="1.0" encoding="utf-8"?>
<results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType">
    <result>
        <row>
            <id>11111</id>
            <largeImage>imageId/111111</largeImage>
            <smallImage>imageId/111112</smallImage>
            <smallImage>imageId/111113</smallImage>
        </row>
        <row>
            <id>22222</id>
            <largeImage>imageId/222222</largeImage>
            <smallImage>imageId/222223</smallImage>
        </row>
    </result>
</results>

How do i remove xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType" from the above output?

  • 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-06-06T14:24:06+00:00Added an answer on June 6, 2026 at 2:24 pm

    If you are using XSLT2.0 you make use of the for-each-group function.

    <xsl:for-each-group select="row" group-by="column1">
    

    Assuming your context is resultSets this would group the rows by the ‘id’ in column1. The current grouping key could then be obtained as follows:

    <xsl:value-of select="current-grouping-key()"/>
    

    And to get the various rows in the group, to transform them to either largeImage or smallImage, you would do this

    <xsl:apply-templates select="current-group()" />
    

    Here is the full XSLT

    <xsl:stylesheet version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns="http://www.castiron.com//response">
    
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="resultSets">
          <xsl:apply-templates select="@*|node()"/>
       </xsl:template>
    
       <xsl:template match="resultSet">
          <xsl:apply-templates select="@*"/>
          <xsl:for-each-group select="row" group-by="column1">
             <row>
                <id><xsl:value-of select="current-grouping-key()"/></id>
                <xsl:apply-templates select="current-group()" />
              </row>
          </xsl:for-each-group>
       </xsl:template>
    
       <xsl:template match="row[column2='0']">
          <largeImage><xsl:value-of select="column3" /></largeImage>
       </xsl:template>
    
       <xsl:template match="row">
          <smallImage><xsl:value-of select="column3" /></smallImage>
       </xsl:template>
    
       <xsl:template match="@*|node()[not(self::*)]">
          <xsl:copy> 
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    
       <xsl:template match="*">
          <xsl:element name="{local-name()}"> 
             <xsl:apply-templates select="@*|node()"/>
          </xsl:element>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    <results xmlns="http://www.castiron.com//response">
       <result>
          <row>
             <id>11111</id>
             <largeImage>imageId/111111</largeImage>
             <smallImage>imageId/111112</smallImage>
             <smallImage>imageId/111113</smallImage>
          </row>
          <row>
             <id>22222</id>
             <largeImage>imageId/222222</largeImage>
             <smallImage>imageId/222223</smallImage>
          </row>
       </result>
    </results>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having some issues running my code local. I have host file setup like this:
Having some issues with C. I have this is my code: // First line
I'm having some issues with an asp.net implementation of this JQuery facebook style autocomplete
I'm having some issues with some jQuery code, and I'm hoping and thinking that
I'm having some issues with my code. This is probably due to some design
having some issues with a networking assignment. End goal is to have a C
We have two iOS Distribution certificates. I´m having some issues with signing because both
Having some issues with this search engine I am trying to put together. I'll
Having some issues deploying this. I've tried to deploy it twice now. Here's what
Having some issues trying to create a fixed header layout for this jsfiddle: http://jsfiddle.net/4xk4D/107/

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.