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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:14:02+00:00 2026-06-03T23:14:02+00:00

I have a relatively simple Soap response message XML which I’d like to modify

  • 0

I have a relatively simple Soap response message XML which I’d like to modify with XSLT.

Here’s what I have so far:

<?xml version="1.0" encoding="utf-8"?>
<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"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:z="http://some.url/WS/">
    <xsl:output method="xml" indent="yes"/>

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

    <xsl:variable name="Method" select="name(//soap:Body/*)" />

    <xsl:template match="//soap:Body/*" >
      <xsl:choose>
        <xsl:when test="$Method='Method1Response'">
          <xsl:call-template name="Method1" />
        </xsl:when>
        <xsl:otherwise>

        </xsl:otherwise>
      </xsl:choose>      
    </xsl:template>

      <xsl:template name="Method1" match="//soap:Body/z:Method1Response/z:Method1Result/z:Errors" />

</xsl:stylesheet>

Sample XML:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">
  <wsa:Action></wsa:Action>
  <wsa:MessageID></wsa:MessageID>
  <wsa:RelatesTo></wsa:RelatesTo>
  <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
</env:Header>
  <soap:Body>
    <Method1Response xmlns="http://some.url/WS/">
      <Method1Result>
        <Msg>blah blah</Msg>
        <Errors>
          <ErrorItem>error 1</ErrorItem>
          <ErrorItem>error 2</ErrorItem>
        </Errors>
        <Data />
      </Method1Result>
    </Method1Response>
  </soap:Body>
</soap:Envelope>

The idea is to delete the Errors from under Method1Result, if Method1 = specific value. If not, leave it as is. What I currently have, itsn’t doing it. Thanks.

Another edit to further clarify:
I want to have a single XSLT file for multiple XML files which belong to different web service calls. Thise means that Method1 can have a number of different values for example: GetMeal, GetWindow, GetHandle, GetWeatherReport,… I’m hoping to create a “case” for each value within the same XSLT in order to intentionally ‘break’ the expected XML for testing purposes. Each time I will delete a different element.

  • 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-03T23:14:03+00:00Added an answer on June 3, 2026 at 11:14 pm

    The problem is the template that matches //soap:Body/* calls a named template which itself does not output anything. This results in all elemenets under soap:Body being ignored.

    As you already have a template to match the elements you want to remove, you can remove the template that matches soap:Body and you should find it will work as expected.

    <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" 
        xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
        xmlns:z="http://some.url/WS/"> 
        <xsl:output method="xml" indent="yes"/> 
    
        <xsl:template match="@* | node()"> 
          <xsl:copy> 
            <xsl:apply-templates select="@* | node()"/> 
          </xsl:copy> 
        </xsl:template> 
    
        <xsl:template match="//soap:Body/z:Method1Response/z:Method1Result/z:Errors" /> 
    </xsl:stylesheet> 
    

    when this applied to your sample XML, the following is output

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
       <env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">
          <wsa:Action/>
          <wsa:MessageID/>
          <wsa:RelatesTo/>
          <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
       </env:Header>
       <soap:Body>
          <Method1Response xmlns="http://some.url/WS/">
             <Method1Result>
                <Msg>blah blah</Msg>
                <Data/>
             </Method1Result>
          </Method1Response>
       </soap:Body>
    </soap:Envelope>
    

    EDIT: There is no reason why you can’t have further matching templates to handle other method responses you might get back. For example….

    <xsl:template match="//soap:Body/z:GetMealResponse/z:GetMealResult/z:Leftovers" />
    <xsl:template match="//soap:Body/z:Method1Response/z:Method1Result/z:Errors" /> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a relatively simple Java App Engine application which I would like
I have a relatively simple application which I need to make native Mac OSX
I have a relatively simple Backbone handled message container. I can add messages, and
I have a relatively simple problem. I have a model named Item which I've
I have a (hopefully) a relatively simple question. How do I tell Android which
I have a relatively simple package of 8 Java classes generated from an XML
I have a relatively simple goal: I want to create a Cocoa application which
A relatively simple question. I have a datagridview, which all it does is displays
I have a relatively simple form which asks a variety of questions. One of
I have a relatively simple Rails app and I would like to store various

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.