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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:10:27+00:00 2026-06-19T03:10:27+00:00

The request XML I have is given below and the XSLT transformation I am

  • 0

The request XML I have is given below and the XSLT transformation I am using is also given.

Unfortunately the ordertotal element is repeating twice after transformation. How can I update the ordertotal element instead of repeating it?

Request XML is

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:fetchOrderListResponse xmlns:ns2="http://impl.lob.wipro.com/">
         <return>
            <customerOrderNumber>1</customerOrderNumber>
            <orderDetails>
               <itemPrice>50.0</itemPrice>
               <itemQty>2</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>37516016-D71B-4790-951F-55D00B0CC159</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderDetails>
               <itemPrice>39.0</itemPrice>
               <itemQty>3</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>6095ABC7-0D0D-4B2E-92E5-80F24E9092B8</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderId>84EC371D-40CA-455E-A0FA-7EA733E9BFD3</orderId>
            <ordertotal>0.0</ordertotal>
            <camelAddedHdrField>0.0</camelAddedHdrField>
         </return>
         <return>
            <customerOrderNumber>1</customerOrderNumber>
            <orderId>54712493-2172-4ADB-814B-BC7AA0BB72C3</orderId>
            <ordertotal>0.0</ordertotal>
            <camelAddedHdrField>0.0</camelAddedHdrField>
         </return>
         <return>
            <customerOrderNumber>1</customerOrderNumber>
            <deliverydate>2013-02-06T00:00:00+05:30</deliverydate>
            <orderDetails>
               <itemPrice>565.0</itemPrice>
               <itemQty>1</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>9A5030BE-F95F-4C62-B5A2-41FF85423218</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderDetails>
               <itemPrice>4.0</itemPrice>
               <itemQty>90</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>65A8B3BE-D407-43D8-8754-EA1E26AA56E4</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderId>0BDCB222-0117-47A9-8813-DF03A1D19E5E</orderId>
            <ordertotal>0.0</ordertotal>
            <camelAddedHdrField>0.0</camelAddedHdrField>
         </return>
         <return>
            <customerOrderNumber>1</customerOrderNumber>
            <orderId>8E4220DC-884B-47BC-A565-E26B80BA5249</orderId>
            <ordertotal>0.0</ordertotal>
            <camelAddedHdrField>0.0</camelAddedHdrField>
         </return>
         <return>
            <customerOrderNumber>1</customerOrderNumber>
            <deliverydate>2013-02-06T00:00:00+05:30</deliverydate>
            <orderDetails>
               <itemPrice>10.0</itemPrice>
               <itemQty>4</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>5A2DF895-BB0F-4039-80DB-F44CED31697B</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderDetails>
               <itemPrice>20.0</itemPrice>
               <itemQty>3</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>8034FBF4-B573-4B19-BDF5-FAF6C4247A55</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderId>60161E3E-3C4A-4CE6-AAC3-E4D2BC240046</orderId>
            <ordertotal>0.0</ordertotal>
            <camelAddedHdrField>0.0</camelAddedHdrField>
         </return>
      </ns2:fetchOrderListResponse>
   </soap:Body>
</soap:Envelope>

XSLT is

<xsl:output method="xml" indent="yes" />

<xsl:template match="*|@*">
    <xsl:copy>
        <xsl:apply-templates select="*|@*" />
    </xsl:copy>
</xsl:template>

<xsl:template match="return">
    <xsl:copy>
        <xsl:copy-of select="@*|*" />
        <ordertotal><xsl:call-template name="calculate-total" /></ordertotal>
    </xsl:copy>
</xsl:template>

<!-- Recursive template -->
<xsl:template name="calculate-total">
    <!-- Select by default the set of orderDetails from the current context -->
    <xsl:param name="orderDetails"
               select="orderDetails" />
    <!-- Param which is going to keep track of the result step by step -->
    <xsl:param name="total"
               select="'0'" />

    <xsl:choose>
        <!-- If we have remaining order details, recurse -->
        <xsl:when test="$orderDetails">
            <xsl:call-template name="calculate-total">
                <!-- Remove the current element for the next step -->
                <xsl:with-param name="orderDetails"
                                select="$orderDetails[position() > 1]" />
                <!-- Do the partial operation for the current element, and continue to the next step -->
                <xsl:with-param name="total"
                                select="$total + ($orderDetails[1]/itemPrice * $orderDetails[1]/itemQty)" />
            </xsl:call-template>        
        </xsl:when>
        <!-- Output the result -->
        <xsl:otherwise>
            <xsl:value-of select="$total" />
        </xsl:otherwise>
    </xsl:choose>

</xsl:template>

Response XML Is showing with duplicate tag is

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:fetchOrderListResponse xmlns:ns2="http://impl.lob.wipro.com/">

         <return>
            <customerOrderNumber>1</customerOrderNumber>
            <orderDetails>
               <itemPrice>50.0</itemPrice>
               <itemQty>2</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>37516016-D71B-4790-951F-55D00B0CC159</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderDetails>
               <itemPrice>39.0</itemPrice>
               <itemQty>3</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>6095ABC7-0D0D-4B2E-92E5-80F24E9092B8</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderId>84EC371D-40CA-455E-A0FA-7EA733E9BFD3</orderId>
            <ordertotal>0.0</ordertotal>
            <camelAddedHdrField>0.0</camelAddedHdrField>
            <ordertotal>217</ordertotal>
         </return>
         <return>
            <customerOrderNumber>1</customerOrderNumber>
            <orderId>54712493-2172-4ADB-814B-BC7AA0BB72C3</orderId>
            <ordertotal>0.0</ordertotal>
            <camelAddedHdrField>0.0</camelAddedHdrField>
            <ordertotal>0</ordertotal>
         </return>
         <return>
            <customerOrderNumber>1</customerOrderNumber>
            <deliverydate>2013-02-06T00:00:00+05:30</deliverydate>
            <orderDetails>
               <itemPrice>565.0</itemPrice>
               <itemQty>1</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>9A5030BE-F95F-4C62-B5A2-41FF85423218</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderDetails>
               <itemPrice>4.0</itemPrice>
               <itemQty>90</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>65A8B3BE-D407-43D8-8754-EA1E26AA56E4</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderId>0BDCB222-0117-47A9-8813-DF03A1D19E5E</orderId>
            <ordertotal>0.0</ordertotal>
            <camelAddedHdrField>0.0</camelAddedHdrField>
            <ordertotal>925</ordertotal>
         </return>
         <return>
            <customerOrderNumber>1</customerOrderNumber>
            <orderId>8E4220DC-884B-47BC-A565-E26B80BA5249</orderId>
            <ordertotal>0.0</ordertotal>
            <camelAddedHdrField>0.0</camelAddedHdrField>
            <ordertotal>0</ordertotal>
         </return>
         <return>
            <customerOrderNumber>1</customerOrderNumber>
            <deliverydate>2013-02-06T00:00:00+05:30</deliverydate>
            <orderDetails>
               <itemPrice>10.0</itemPrice>
               <itemQty>4</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>5A2DF895-BB0F-4039-80DB-F44CED31697B</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderDetails>
               <itemPrice>20.0</itemPrice>
               <itemQty>3</itemQty>
               <itemUnit>0</itemUnit>
               <orderDetailsId>8034FBF4-B573-4B19-BDF5-FAF6C4247A55</orderDetailsId>
               <camelAddedDtlField>0.1</camelAddedDtlField>
            </orderDetails>
            <orderId>60161E3E-3C4A-4CE6-AAC3-E4D2BC240046</orderId>
            <ordertotal>0.0</ordertotal>
            <camelAddedHdrField>0.0</camelAddedHdrField>
            <ordertotal>100</ordertotal>
         </return>
      </ns2:fetchOrderListResponse>
   </soap:Body>
</soap:Envelope>
  • 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-19T03:10:28+00:00Added an answer on June 19, 2026 at 3:10 am

    You have to follow the same idea from the question that you posted here: XSLT – Updating the Header

    Instead of matching result, match ordertotal and change the XPath expression to select the
    orderDetails elements.

    So, change this:

    <xsl:template match="return">
        <xsl:copy>
            <xsl:copy-of select="@*|*" />
            <ordertotal><xsl:call-template name="calculate-total" /></ordertotal>
        </xsl:copy>
    </xsl:template>
    

    To:

    <xsl:template match="ordertotal">
        <xsl:copy>
            <xsl:call-template name="calculate-total">
                <xsl:with-param name="orderDetails"
                                select="../orderDetails" />
            </xsl:call-template>
        </xsl:copy>
    </xsl:template>
    

    Then you can remove from the calculate-total template the default value for the first parameter, removing the select=”orderDetails” attribute.

    Besides because you are not using the copy-of element, you have to change the identity template to:

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*" /> 
        </xsl:copy>
    </xsl:template>
    

    So the complete stylesheet would be:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:output method="xml" indent="yes" />
    
        <xsl:template match="node()|@*">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*" />
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="ordertotal">
            <xsl:copy>
                <xsl:call-template name="calculate-total">
                    <xsl:with-param name="orderDetails"
                                    select="../orderDetails" />
                </xsl:call-template>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template name="calculate-total">
            <xsl:param name="orderDetails" />
            <xsl:param name="total"
                       select="'0'" />
    
            <xsl:choose>
                <xsl:when test="$orderDetails">
                    <xsl:call-template name="calculate-total">
                        <xsl:with-param name="orderDetails"
                                        select="$orderDetails[position() > 1]" />
                        <xsl:with-param name="total"
                                        select="$total + ($orderDetails[1]/itemPrice * $orderDetails[1]/itemQty)" />
                    </xsl:call-template>        
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$total" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The request XML i have is given below and the XSLT transformation Iam using
I'm using Rampart to generate a request. I have a policy.xml that is used
I have one XML request which I need to modify (to XML) and then
I have a xml file whose content is <?xml version=1.0 encoding=UTF-8?> <ReturnMessage> <root>ReturnMessage</root> <cancelMessage>Request
I have a request that returns a large xml file. I have the file
In my app i have to send a xml data as request, I am
I have this code: ... request data = new request(); data.username = formNick; xml
I have a line of PHP code that does the following: $xml = <xml><request>...[snipped
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
I know we can request xml, html as well as text images directly using

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.