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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:54:42+00:00 2026-05-24T07:54:42+00:00

I have an xml content and i am applying xslt 1.0 for transformation on

  • 0

I have an xml content and i am applying xslt 1.0 for transformation on it. I am also passing parameters for filteration. but i am not able to to grouping on filtered data in xslt 1.0.

I will pass “Country Value” (as like ‘United States’) as parameter for filteration. after filteration, Grouping will be applied on “Group” field for filtered data. and if only one group exist then dont group data. grouping applied only in case if more then one group becomes possible.

please help me on this.

thanks in advance.

Here is my sample XML content.

<?xml version="1.0" encoding="utf-8" ?>
<DataRows>
  -<DataRow>
    - <Country>
      <Conty>United States</Conty>
      <Conty>United Kingdom</Conty>
    </Country>
    <Group>Group 1</Group>
    <Order>1</Order>
    <Name>Name 1_1</Name>
    <Title>Title 1</Title>
    <PhoneNo>732-989-9898</PhoneNo>
    <ImageUrl />
    <EmailId />
  </DataRow>
  -<DataRow>
    - <Country>
      <Conty>United States</Conty>
      <Conty>United Kingdom</Conty>
    </Country>
    <Group>Group 1</Group>
    <Order>2</Order>
    <Name>Name 2_2</Name>
    <Title>Title 2</Title>
    <PhoneNo>732-989-9898</PhoneNo>
    <ImageUrl />
    <EmailId />
  </DataRow>
  -<DataRow>
    - <Country>
      <Conty>United States</Conty>
    </Country>
    <Group>Group 1</Group>
    <Order>1</Order>
    <Name>Name 3_1</Name>
    <Title>Title 3</Title>
    <PhoneNo>732-989-9898</PhoneNo>
    <ImageUrl />
    <EmailId />
  </DataRow>
  -<DataRow>
    - <Country>
      <Conty>United States</Conty>
      <Conty>Germany</Conty>
    </Country>
    <Group>Group 1</Group>
    <Order>2</Order>
    <Name>Name 4_2</Name>
    <Title>Title 4</Title>
    <PhoneNo>732-989-9898</PhoneNo>
    <ImageUrl />
    <EmailId />
  </DataRow>
  -<DataRow>
    - <Country>
      <Conty>United States</Conty>
    </Country>
    <Group>Group 2</Group>
    <Order>4</Order>
    <Name>Name 8_4</Name>
    <Title>Title 8</Title>
    <PhoneNo>732-989-9898</PhoneNo>
    <ImageUrl />
    <EmailId />
  </DataRow>
  -<DataRow>
    - <Country>
      <Conty>United Kingdom</Conty>
    </Country>
    <Group>Group 2</Group>
    <Order>1</Order>
    <Name>Name 9_1</Name>
    <Title>Title 9</Title>
    <PhoneNo>732-989-9898</PhoneNo>
    <ImageUrl />
    <EmailId />
  </DataRow>
  -<DataRow>
    - <Country>
      <Conty>United States</Conty>
      <Conty>Germany</Conty>
    </Country>
    <Group>Group 2</Group>
    <Order>3</Order>
    <Name>Name 5_3</Name>
    <Title>Title 5</Title>
    <PhoneNo>732-989-9898</PhoneNo>
    <ImageUrl />
    <EmailId />
  </DataRow>
  -<DataRow>
    - <Country>
      <Conty>United States</Conty>
      <Conty>Germany</Conty>
    </Country>
    <Group>Group 2</Group>
    <Order>4</Order>
    <Name>Name 6_4</Name>
    <Title>Title 6</Title>
    <PhoneNo>732-989-9898</PhoneNo>
    <ImageUrl />
    <EmailId />
  </DataRow>
  -<DataRow>
    - <Country>
      <Conty>United States</Conty>
    </Country>
    <Group>Group 2</Group>
    <Order>3</Order>
    <Name>Name 7_3</Name>
    <Title>Title 7</Title>
    <PhoneNo>732-989-9898</PhoneNo>
    <ImageUrl />
    <EmailId />
  </DataRow>
  -<DataRow>
    - <Country>
      <Conty>Germany</Conty>
    </Country>
    <Group>Group 1</Group>
    <Order>1</Order>
    <Name>Name 10_1</Name>
    <Title>Title 10</Title>
    <PhoneNo>732-989-9898</PhoneNo>
    <ImageUrl />
    <EmailId />
  </DataRow>
</DataRows>
  • 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-24T07:54:42+00:00Added an answer on May 24, 2026 at 7:54 am

    If you really wanted to do filtering first, then grouping, then you are looking at some sort of ‘two pass’ transform. This can be achieved by use of the node-set extension function, to create a result-tree fragment which contains the filtered data.

    In the following example, I am using Microsoft’s extension function, but depending on your platform, you may have to specify another. ( EXSLT is another common one. Use name space http://exslt.org/common for that. )

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:param name="Conty">United Kingdom</xsl:param>
    
       <xsl:variable name="FilteredData">
          <xsl:apply-templates select="/DataRows/DataRow" mode="filter"/>
       </xsl:variable>
    
       <xsl:template match="DataRow" mode="filter">
          <!-- Check this DataRow matches the filter -->
          <xsl:if test="Country[Conty=$Conty]">
             <xsl:copy>
                <xsl:apply-templates select="@*|node()" mode="filter"/>
             </xsl:copy>
          </xsl:if>
       </xsl:template>
    
       <!-- Ignore Country node in the filter -->
       <xsl:template match="Country" mode="filter"/>
    
       <!-- Identity template for filter -->
       <xsl:template match="@*|node()" mode="filter">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()" mode="filter"/>
          </xsl:copy>
       </xsl:template>
    
       <xsl:template match="/DataRows">
          <xsl:copy>
             <!-- Read the filtered data -->
             <xsl:choose>
                <!-- Check there is a Group which differs from the first group -->
                <xsl:when test="msxsl:node-set($FilteredData)/DataRow[position() > 1][Group != msxsl:node-set($FilteredData)/DataRow[1]/Group]">
                   <xsl:apply-templates select="msxsl:node-set($FilteredData)"/>
                </xsl:when>
                <xsl:otherwise>
                   <xsl:apply-templates select="msxsl:node-set($FilteredData)" mode="nogroup"/>
                </xsl:otherwise>
             </xsl:choose>
          </xsl:copy>
       </xsl:template>
    
       <!-- Filtered data row -->
       <xsl:template match="DataRow">
          <!-- Is this DataRow the first in the group -->
          <xsl:if test="not(preceding-sibling::DataRow[Group=current()/Group])"><!-- If so, create the group node -->
             <Group>
                <xsl:attribute name="name">
                   <xsl:value-of select="Group"/>
                </xsl:attribute><!-- Get all the DataRow elements from the filter for the current group -->
                <xsl:apply-templates select="../DataRow[Group=current()/Group]" mode="ingroup"/>
             </Group>
          </xsl:if>
       </xsl:template>
    
       <!-- Identity template for the group -->
       <xsl:template match="@*|node()" mode="ingroup">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()" mode="ingroup"/>
          </xsl:copy>
       </xsl:template>
    
       <!-- Ignore Group and Country node in the grouping -->
       <xsl:template match="Group|Country" mode="ingroup"/>
    
       <!-- Identity template for no grouping -->
       <xsl:template match="@*|node()" mode="nogroup">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()" mode="nogroup"/>
          </xsl:copy>
       </xsl:template>
    
    </xsl:stylesheet>
    

    When this is used, the output should be as follows

    <DataRows>
        <Group name="Group 1">
            <DataRow>
                <Order>1</Order>
                <Name>Name 1_1</Name>
                <Title>Title 1</Title>
                <PhoneNo>732-989-9898</PhoneNo>
                <ImageUrl/>
                <EmailId/>
            </DataRow>
            <DataRow>
                <Order>2</Order>
                <Name>Name 2_2</Name>
                <Title>Title 2</Title>
                <PhoneNo>732-989-9898</PhoneNo>
                <ImageUrl/>
                <EmailId/>
            </DataRow>
        </Group>
        <Group name="Group 2">
            <DataRow>
                <Order>1</Order>
                <Name>Name 9_1</Name>
                <Title>Title 9</Title>
                <PhoneNo>732-989-9898</PhoneNo>
                <ImageUrl/>
                <EmailId/>
            </DataRow>
        </Group>
    </DataRows>
    

    See Understanding the node-set function for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to download a xml file,but i have a xml content in a
I have a xml file whose content is <?xml version=1.0 encoding=UTF-8?> <ReturnMessage> <root>ReturnMessage</root> <cancelMessage>Request
I have XML tag that has the content which is HTML document. <xml-tag> <!--
I have a long xml file the content of the file are below: <?xml
I have an XML file from which I am parsing some content to display
i have input xml as <content> <date> <day>14</day> <month>06</month> <year>2012</year> </date> </content> want it
I have an XML file as follows, and I'm trying to read the content
I have a xml file main.xml with following markup and data. main.xml <xml> <content>
I have an xml file likes below. <?xml version=1.0 encoding=utf-8 ?> <Book> <Title>Title</Title> <Content>Content</Content>
I have a bunch of xml files named content_[0-9] (content underscore followed by a

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.