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

  • Home
  • SEARCH
  • 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 8813009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:44:16+00:00 2026-06-14T03:44:16+00:00

Given my input XML: <?xml version=1.0 encoding=utf-8?> <FlightAvailability> <FareDetails> <Fare ID=2007 DepartureDate=2012-11-23T07:05:00> <FareTypes> <FareType

  • 0

Given my input XML:

<?xml version="1.0" encoding="utf-8"?>
<FlightAvailability>
    <FareDetails>
        <Fare ID="2007" DepartureDate="2012-11-23T07:05:00">
            <FareTypes>
                <FareType FareType="Promo1">
                    <FareInfo Class="Y" FareBasis="Y" Fare="1500"/>
                </FareType>
                <FareType FareType="Promo2">
                    <FareInfo Class="Y" FareBasis="Y" Fare="1000"/>
                </FareType>
            </FareTypes>
        </Fare>
        <Fare ID="2008" DepartureDate="2012-11-23T08:00:00">
            <FareTypes>
                <FareType FareType="Promo1">
                    <FareInfo Class="Y" FareBasis="Y" Fare="2500"/>
                </FareType>
                <FareType FareType="Promo2">
                    <FareInfo Class="Y" FareBasis="Y" Fare="2000"/>
                </FareType>
            </FareTypes>        
        </Fare>
    </FareDetails>
    <SegmentDetails>
        <Segment ID="2007" Origin="DEL" Destination="BOM"
            DepartureDate="2012-11-23T07:05:00" Airline="YY" ArrivalDate="2012-11-23T08:55:00"
            Stops="0" AircraftType="320"
            FlightNum="100"/>
        <Segment ID="2008" Origin="DEL" Destination="BOM"
            DepartureDate="2012-11-23T08:00:00" Airline="YY" ArrivalDate="2012-11-23T09:55:00"
            Stops="0" AircraftType="320" FlightNum="200"/>
    </SegmentDetails>
</FlightAvailability>

I wanted to create an output XML wherein I pick up FareTypes of FareType “Promo1” and find the corresponding Segment by matching the ID (eg. 2007 in Fare and Segment tags). While I iterate for-each in the FareDetails/Fare and pick up the ID, how do I pass the ID and pick up the particular Segment information. I am new to XSL and know this should probably done making a call to template with-param, where the param is the ID, but not able to set it up. I tried to pass a variable, but it doesn’t pick anything from the Segments.

This is an XSL I tried:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output  version="1.0" method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
   <xsl:element name="AvailRS">
        <xsl:element name="Availability">
                        <xsl:for-each select="//FareDetails/Fare">
                                <xsl:element name="item">
                                <xsl:element name="Fares">
                <xsl:variable name = "lfid" select="@ID"/>
                <xsl:element name = "ID"><xsl:value-of select="$lfid"/></xsl:element>
                <xsl:for-each select="FareTypes/FareType[@FareType='Promo1']">
                                        <xsl:element name="item">
                                    <xsl:element name="BaseAmount">
                        <xsl:value-of select="ceiling(FareInfo/@Fare)"/>
                           </xsl:element>
                           <xsl:element name="FareBasisCode">
                                <xsl:value-of select="FareInfo/@FareBasis"/>
                           </xsl:element>
                           <xsl:element name="FareClass">
                                <xsl:value-of select="FareInfo/@Class"/>
                           </xsl:element>
                          </xsl:element>
                        </xsl:for-each>
                        </xsl:element>
                <xsl:element name="Flights">
                    <xsl:variable name="seg" select="//SegmentDetails/Segment[@ID='$lfid']"/>
                          <xsl:element name="item">
                        <xsl:element name="FlightNumber"><xsl:value-of select="$seg/@FlightNum"/></xsl:element>
                        <xsl:element name="DepTime"><xsl:value-of select="$seg/@DepartureDate"/></xsl:element>
                        <xsl:element name="ArrTime"><xsl:value-of select="$seg/@ArrivalDate"/></xsl:element>
                        <xsl:element name="Origin"><xsl:value-of select="$seg/@Origin"/></xsl:element>
                        <xsl:element name="Destination"><xsl:value-of select="$seg/@Destination"/></xsl:element>
                        <xsl:element name="Stops"><xsl:value-of select="$seg/@Stops"/></xsl:element>
                        <xsl:element name="Aircraft"><xsl:value-of select="$seg/@AircraftType"/></xsl:element>
                      </xsl:element>
                        </xsl:element>
            </xsl:element>
                </xsl:for-each>
  </xsl:element>
  <Status>Success</Status>
  </xsl:element>
</xsl:template>
</xsl:stylesheet>

This doesn’t pick the data from Segment:

<AvailRS>
  <Availability>
    <item>
      <Fares>
        <ID>2007</ID>
        <item>
          <BaseAmount>1500</BaseAmount>
          <FareBasisCode>Y</FareBasisCode>
          <FareClass>Y</FareClass>
        </item>
      </Fares>
      <Flights>
        <item>
          <FlightNumber></FlightNumber>
          <DepTime></DepTime>
          <ArrTime></ArrTime>
          <Origin></Origin>
          <Destination></Destination>
          <Stops></Stops>
          <Aircraft></Aircraft>
        </item>
      </Flights>
    </item>
    <item>
      <Fares>
        <ID>2008</ID>
        <item>
          <BaseAmount>2500</BaseAmount>
          <FareBasisCode>Y</FareBasisCode>
          <FareClass>Y</FareClass>
        </item>
      </Fares>
      <Flights>
        <item>
          <FlightNumber></FlightNumber>
          <DepTime></DepTime>
          <ArrTime></ArrTime>
          <Origin></Origin>
          <Destination></Destination>
          <Stops></Stops>
          <Aircraft></Aircraft>
        </item>
      </Flights>
    </item>
  </Availability>
  <Status>Success</Status>
</AvailRS>

What I would like to get in the above example would be the Segment information corresponding to the Fare connected by the ID attribute (2007, 2008), but the $id variable isn’t going to work. How do I select the corresponding ID?

  • 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-14T03:44:18+00:00Added an answer on June 14, 2026 at 3:44 am

    You need to remove the quotes around the variable reference. Change

    //SegmentDetails/Segment[@ID='$lfid']
    

    to

    //SegmentDetails/Segment[@ID = $lfid]
    

    Otherwise, you are asking XSLT to compare the value of the ID attribute with the literal string $lfid.

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

Sidebar

Related Questions

Given an input XML document like this: <?xml version=1.0 encoding=utf-8?> <title> This contains an
Given the input XML <FlightOptions> <item> <Fares> <item> <FareClass>T</FareClass> <Fare>100</Fare> <FareType>E</FareType> <Seats>5</Seats> </item> <item>
Wikipedia's example of XHTML-MP : <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC -//WAPFORUM//DTD XHTML Mobile
<?xml version=1.0 encoding=utf-8?> <s:Application xmlns:fx=http://ns.adobe.com/mxml/2009 xmlns:s=library://ns.adobe.com/flex/spark xmlns:mx=library://ns.adobe.com/flex/mx width=1501 height=960 minWidth=955 minHeight=600> <fx:Declarations> <!-- Place
Given the input XML file: <acctInfo> <wfInfo> <aaa>1</aaa> <bbb>1</bbb> <ccc>1</ccc> <ddd>1</ddd> <eee>1</eee> </wfInfo> <acctInfo>
I am looking to transform a input xml given below <profile name=default> <color id=forecolor
Given a xml file as input howto modify a attribute of a tag with
Given the contrived XML schema, sample XML input, and sample XSLT below used to
I am attempting to compose a style sheet that, given an XML input (obviously)
Given this code (C#, .NET 3.5 SP1): var doc = new XmlDocument(); doc.LoadXml(<?xml version=\1.0\?><root>

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.