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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:57:05+00:00 2026-06-15T00:57:05+00:00

I am a beginner in XSLT. Below is source XML which i receive. Request

  • 0

I am a beginner in XSLT.

Below is source XML which i receive. Request tag constains the FlightId which is being used to filter the Result tag.

Source XML:

<Response>
    <Request>
        <RequestedFlights>
            <FlightId>2121</FlightId>
            <FlightId>2584</FlightId>
        </RequestedFlights>
    </Request>
    <Result>
        <Flights>
            <Flight>
                <Segments>
                    <Segment>
                        <Id>1</Id>
                        <FlightNumber>2121</FlightNumber>
                    </Segment>
                    <Segment>
                        <Id>2</Id>
                        <FlightNumber>1121</FlightNumber>
                    </Segment>
                </Segments>
            </Flight>
            <Flight>
                <Segments>
                    <Segment>
                        <Id>3</Id>
                        <FlightNumber>2121</FlightNumber>
                    </Segment>
                    <Segment>
                        <Id>4</Id>
                        <FlightNumber>2584</FlightNumber>
                    </Segment>
                </Segments>
            </Flight>
            <Flight>
                <Segments>
                    <Segment>
                        <Id>5</Id>
                        <FlightNumber>2121</FlightNumber>
                    </Segment>
                    <Segment>
                        <Id>6</Id>
                        <FlightNumber>2584</FlightNumber>
                    </Segment>
                    <Segment>
                        <Id>7</Id>
                        <FlightNumber>2023</FlightNumber>
                    </Segment>
                </Segments>
            </Flight>
        </Flights>
    </Result>
</Response>

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

    <xsl:output method="xml" indent="yes" />
    <xsl:variable name="ReqFlights" select="//Request/RequestedFlights/FlightId" />
    <xsl:variable name="FilterFlights" select="//Result/Flights/Flight[Segments/Segment/FlightNumber=$ReqFlights]"/>

    <xsl:template match="Response">
        <FilterResult>
            <ResultCount>
                <xsl:value-of select="count($FilterFlights)"/>
            </ResultCount>
            <xsl:copy>
                <xsl:copy-of select="$FilterFlights"/>
            </xsl:copy>
        </FilterResult>
    </xsl:template>
</xsl:stylesheet>

I received below output using above XSLT.

Output:

<FilterResult>
    <ResultCount>3</ResultCount>
    <Response>
        <Flight>
            <Segments>
                <Segment>
                    <Id>1</Id>
                    <FlightNumber>2121</FlightNumber>
                </Segment>
                <Segment>
                    <Id>2</Id>
                    <FlightNumber>1121</FlightNumber>
                </Segment>
            </Segments>
        </Flight>
            <Flight>
            <Segments>
                <Segment>
                    <Id>3</Id>
                    <FlightNumber>2121</FlightNumber>
                </Segment>
                <Segment>
                    <Id>4</Id>
                    <FlightNumber>2584</FlightNumber>
                </Segment>
            </Segments>
        </Flight>
            <Flight>
            <Segments>
                <Segment>
                    <Id>5</Id>
                    <FlightNumber>2121</FlightNumber>
                </Segment>
                <Segment>
                    <Id>6</Id>
                    <FlightNumber>2584</FlightNumber>
                </Segment>
                <Segment>
                    <Id>7</Id>
                    <FlightNumber>2023</FlightNumber>
                </Segment>
            </Segments>
        </Flight>
    </Response>
</FilterResult>

I would like to receive below output.

Expected Output:

<FilterResult>
    <ResultCount>1</ResultCount>
    <Response>
        <Flight>
            <Segments>
                <Segment>
                    <Id>3</Id>
                    <FlightNumber>2121</FlightNumber>
                </Segment>
                <Segment>
                    <Id>4</Id>
                    <FlightNumber>2584</FlightNumber>
                </Segment>
            </Segments>
        </Flight>
    </Response>
</FilterResult>

Please help me. How should i use the array to filter the response and get expected output.
Thanks.

  • 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-15T00:57:07+00:00Added an answer on June 15, 2026 at 12:57 am

    Use:

    /*/Result/*/Flight
                [count(*/*)=count(/*/Request/*/FlightId)
               and
                 not(*/*/FlightNumber[not(. = /*/Request/*/FlightId)])
                ]
    

    Here is the complete transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="/">
         <xsl:variable name="vHits" select=
         "/*/Result/*/Flight
                      [count(*/*)=count(/*/Request/*/FlightId)
                     and
                       not(*/*/FlightNumber[not(. = /*/Request/*/FlightId)])
                       ]"/>
        <FilterResult>
        <ResultCount><xsl:value-of select="count($vHits)"/></ResultCount>
        <Response>
         <xsl:copy-of select="$vHits"/>
        </Response>
      </FilterResult>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <Response>
        <Request>
            <RequestedFlights>
                <FlightId>2121</FlightId>
                <FlightId>2584</FlightId>
            </RequestedFlights>
        </Request>
        <Result>
            <Flights>
                <Flight>
                    <Segments>
                        <Segment>
                            <Id>1</Id>
                            <FlightNumber>2121</FlightNumber>
                        </Segment>
                        <Segment>
                            <Id>2</Id>
                            <FlightNumber>1121</FlightNumber>
                        </Segment>
                    </Segments>
                </Flight>
                <Flight>
                    <Segments>
                        <Segment>
                            <Id>3</Id>
                            <FlightNumber>2121</FlightNumber>
                        </Segment>
                        <Segment>
                            <Id>4</Id>
                            <FlightNumber>2584</FlightNumber>
                        </Segment>
                    </Segments>
                </Flight>
                <Flight>
                    <Segments>
                        <Segment>
                            <Id>5</Id>
                            <FlightNumber>2121</FlightNumber>
                        </Segment>
                        <Segment>
                            <Id>6</Id>
                            <FlightNumber>2584</FlightNumber>
                        </Segment>
                        <Segment>
                            <Id>7</Id>
                            <FlightNumber>2023</FlightNumber>
                        </Segment>
                    </Segments>
                </Flight>
            </Flights>
        </Result>
    </Response>
    

    the wanted, correct result is produced:

    <FilterResult>
       <ResultCount>1</ResultCount>
       <Response>
          <Flight>
             <Segments>
                <Segment>
                   <Id>3</Id>
                   <FlightNumber>2121</FlightNumber>
                </Segment>
                <Segment>
                   <Id>4</Id>
                   <FlightNumber>2584</FlightNumber>
                </Segment>
             </Segments>
          </Flight>
       </Response>
    </FilterResult>
    

    Explanation:

    Proper use of the double negation law.

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

Sidebar

Related Questions

I am beginner in XSLT. My Source XML is as below <Options> <Option> <Data>Data1</Data>
I am a beginner to XSLT. My Source XML is as below: <Passengers> <Passenger
I am beginner in XSLT. My Source XML: <Request> <Documents> <Doc Type=A>123</Doc> <Doc Type=C>345</Doc>
I am a beginner and want to learn XSLT. I came upon an issue
Beginner help needed :) I am doign an example form a php book which
I'm a beginner at XSL FO. I have a very simple XML document :
Beginner hobby programmer here. I'm used to running C in OSX compiling with GCC
Beginner question here. I'm going to make a Jquery function that is used to
I have JDK6 and using JAXP for the transformation. I am beginner to XSLT.
Beginner to assembly programming for x86. I have a simple asm file which I

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.