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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:51:37+00:00 2026-05-25T05:51:37+00:00

I am newbie in XSLT.I am Using XSLT(XML to XML).Please check my code –

  • 0

I am newbie in XSLT.I am Using XSLT(XML to XML).Please check my code –

Input XML –

 <FCRep>
      <AirInfo>
          <AdtTransFee>0.000</AdtTransFee>
          <ChdTransFee>0.000</ChdTransFee>
          <InfTransFee>0.000</InfTransFee>
          <AutoCharges grandTotal="30.000">
            <Charge name="SAFI" operator="+" isSupplierFee="TRUE" ApplyOn="BaseFare">
              <Adult>5.000</Adult>
              <Child>5.000</Child>
              <Infant>5.000</Infant>
              <DBAmount type="fixed" />
              <Total>15.000</Total>
            </Charge>
            <Charge name="APC" operator="+" isSupplierFee="TRUE" ApplyOn="BaseFare">
              <Adult>5.000</Adult>
              <Child>5.000</Child>
              <Infant>5.000</Infant>
              <DBAmount type="fixed" />
              <Total>15.000</Total>
            </Charge>
            <Charge name="Supplier Fee" operator="+" isSupplierFee="True" ApplyOn="BaseFare+YQ">
              <Adult>0.000</Adult>
              <Child>0.000</Child>
              <Infant>0.000</Infant>
              <DBAmount type="False">0</DBAmount>
              <Total>0.000</Total>
            </Charge>
          </AutoCharges>
      </AirInfo>
    </FCRep>

XSLT –

<xsl:output method="xml" indent="yes"/>
  <xsl:variable name="root" select="FareRules" />
  <xsl:variable name="journey" select="FareRules/JournyType" />
  <xsl:variable name ="nOfADT" select="FareRules/noa" />
  <xsl:variable name ="nOfCHD" select="FareRules/noc" />
  <xsl:variable name ="nOfINF" select="FareRules/noi" />
  <xsl:variable name="searchType" select="FareRules/SearchType" />

  <xsl:template match="/">
    <FlightDetailRule>

      <xsl:element name="AirInfo">

        <FareDetails>
          <xsl:if test="$nOfADT > 0">
            <xsl:element name="PaxType">
              <xsl:attribute name="Type">
                <xsl:value-of select="'ADT'"/>
              </xsl:attribute>
              <NoOfPax>
                <xsl:value-of select="$nOfADT"/>
              </NoOfPax>
              <BFare>
                <xsl:value-of select="ABP"/>
              </BFare>
              <Tax>
                <xsl:value-of select="ATax"/>
              </Tax>
              <Yq>
                <xsl:value-of select="AdultYQ"/>
              </Yq>

              <xsl:element name="OthChg">
                <xsl:attribute name="ChgTotal">
                </xsl:attribute>
                <xsl:for-each select="AutoCharges/Charge">
                  <xsl:element name="Chg">
                    <xsl:attribute name="NM">
                      <xsl:value-of select="@name"/>
                    </xsl:attribute>
                    <xsl:value-of select="Adult"/>
                  </xsl:element>
                </xsl:for-each>
                <xsl:element name="Chg">
                  <xsl:attribute name="NM">
                    <xsl:value-of select="'TransFee'"/>
                  </xsl:attribute>
                  <xsl:value-of select="AdtTransFee"/>
                </xsl:element>
              </xsl:element>
            </xsl:element>
          </xsl:if>

          <xsl:if test="$nOfCHD > 0">
            <xsl:element name="PaxType">
              <xsl:attribute name="Type">
                <xsl:value-of select="'CHD'"/>
              </xsl:attribute>
              <NoOfPax>
                <xsl:value-of select="$nOfCHD"/>
              </NoOfPax>
              <BFare>
                <xsl:value-of select="CBP"/>
              </BFare>
              <Tax>
                <xsl:value-of select="CTax"/>
              </Tax>
              <Yq>
                <xsl:value-of select="ChildYQ"/>
              </Yq>

              <xsl:element name="OthChg">
                <xsl:attribute name="ChgTotal">
                </xsl:attribute>
                <xsl:for-each select="AutoCharges/Charge">
                  <xsl:element name="Chg">
                    <xsl:attribute name="NM">
                      <xsl:value-of select="@name"/>
                    </xsl:attribute>
                    <xsl:value-of select="Child"/>
                  </xsl:element>
                </xsl:for-each>
                <xsl:element name="Chg">
                  <xsl:attribute name="NM">
                    <xsl:value-of select="'TransFee'"/>
                  </xsl:attribute>
                  <xsl:value-of select="ChdTransFee"/>
                </xsl:element>
              </xsl:element>

            </xsl:element>
          </xsl:if>

          <xsl:if test="$nOfINF > 0">
            <xsl:element name="PaxType">
              <xsl:attribute name="Type">
                <xsl:value-of select="'INF'"/>
              </xsl:attribute>
              <NoOfPax>
                <xsl:value-of select="$nOfINF"/>
              </NoOfPax>
              <BFare>
                <xsl:value-of select="IBP"/>
              </BFare>
              <Tax>
                <xsl:value-of select="ITax"/>
              </Tax>
              <Yq>
                <xsl:value-of select="InfantYQ"/>
              </Yq>

              <xsl:element name="OthChg">
                <xsl:attribute name="ChgTotal">
                </xsl:attribute>
                <xsl:for-each select="AutoCharges/Charge">
                  <xsl:element name="Chg">
                    <xsl:attribute name="NM">
                      <xsl:value-of select="@name"/>
                    </xsl:attribute>
                    <xsl:value-of select="Infant"/>
                  </xsl:element>
                </xsl:for-each>
                <xsl:element name="Chg">
                  <xsl:attribute name="NM">
                    <xsl:value-of select="'TransFee'"/>
                  </xsl:attribute>
                  <xsl:value-of select="InfTransFee"/>
                </xsl:element>
              </xsl:element>

            </xsl:element>
          </xsl:if>

        </FareDetails>

      </xsl:element>
    </FlightDetailRule>
  </xsl:template>

</xsl:stylesheet>

Output XML –

 <FlightDetailRule>
      <AirInfo>
          <FareDetails>
            <PaxType Type="ADT">
              <NoOfPax>1</NoOfPax>
              <BFare>12.000</BFare>
              <Tax>53.200</Tax>
              <Yq>0.0000</Yq>
              <OthChg ChgTotal="">
                <Chg NM="SAFI">5.000</Chg>
                <Chg NM="APC">5.000</Chg>
                <Chg NM="Supplier Fee">0.000</Chg>
                <Chg NM="TransFee">0.000</Chg>
              </OthChg>
            </PaxType>
            <PaxType Type="CHD">
              <NoOfPax>1</NoOfPax>
              <BFare>12.000</BFare>
              <Tax>53.200</Tax>
              <Yq>0.0000</Yq>
              <OthChg ChgTotal="">
                <Chg NM="SAFI">5.000</Chg>
                <Chg NM="APC">5.000</Chg>
                <Chg NM="Supplier Fee">0.000</Chg>
                <Chg NM="TransFee">0.000</Chg>
              </OthChg>
            </PaxType>
            <PaxType Type="INF">
              <NoOfPax>1</NoOfPax>
              <BFare>7.000</BFare>
              <Tax>10.300</Tax>
              <Yq>0.0000</Yq>
              <OthChg ChgTotal="">
                <Chg NM="SAFI">5.000</Chg>
                <Chg NM="APC">5.000</Chg>
                <Chg NM="Supplier Fee">0.000</Chg>
                <Chg NM="TransFee">0.000</Chg>
              </OthChg>
            </PaxType>
          </FareDetails>
      </AirInfo>
    </FlightDetailRule>

My output is coming fine but I also want ChgTotal attribute in OthChg nodes.
Please suggest me that how I can do this.

Thanks in advance.

  • 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-25T05:51:37+00:00Added an answer on May 25, 2026 at 5:51 am

    It is appropriate here to use the standard XPath function sum() like this:

    Your code:

                  <xsl:element name="OthChg">
                    <xsl:attribute name="ChgTotal">
                    </xsl:attribute>
                    <xsl:for-each select="AutoCharges/Charge">
                      <xsl:element name="Chg">
                        <xsl:attribute name="NM">
                          <xsl:value-of select="@name"/>
                        </xsl:attribute>
                        <xsl:value-of select="Adult"/>
                      </xsl:element>
                    </xsl:for-each>
                    <xsl:element name="Chg">
                      <xsl:attribute name="NM">
                        <xsl:value-of select="'TransFee'"/>
                      </xsl:attribute>
                      <xsl:value-of select="AdtTransFee"/>
                    </xsl:element>
                  </xsl:element>
                </xsl:element>
    

    Correct code:

                <OthChg ChgTotal="{sum(AutoCharges/Charge/Adult)+AdtTransFee}">
                    <xsl:for-each select="AutoCharges/Charge">
                      <Chg NM="{@name}">
                        <xsl:value-of select="Adult"/>
                      </Chg>
                    </xsl:for-each>
                    <Chg NM="TransFee">
                      <xsl:value-of select="AdtTransFee"/>
                    </xsl:element>
                </OthChg>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

XSLT newbie question: Please fill in the blank in the C# code fragment below:
An XSLT-newbie problem: I need to substitute a text value in XML-file. All other
I'm a newbie in XSLT & XPath so please forgive me for this simple
this is driving me crazy, for xslt newbie like me. Input: <root> <a><name>kyle</name></a> <b><name>stan</name></b>
Newbie question... The objective: I intend to have an HTML text input field as
Newbie question on xslt. I've multiple xsl:if checks like <xsl:if test=node/node1> ...</xsl:if> ... <xsl:if
Newbie here programming my first app (having made several tutorial apps). I am using
Newbie question here: I'm using ANSI C on server to crunch numbers for a
Newbie here (to C, objective-C, and iOS)... For this code in my AppDelegate.m, why
Newbie question... I am using silverlight to POST data to my GAE application class

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.