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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:27:03+00:00 2026-06-01T06:27:03+00:00

i have an input soap message, trying to replace part of namespace uri with

  • 0

i have an input soap message, trying to replace part of namespace uri with a different string. I am able to replace entire URI with a different URI, but not able to modify the existing URI. I need to look for ‘OLDSTRING’ and replace with ‘NEWSTRING’. The string VARIABLESTRING varies in in every input xml, so I should keep as it is in the output xml

Input XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:schemas-OLDSTRING-com:VARIABLESTRING">
       <soapenv:Header/>
       <soapenv:Body>
          <requestMessage xmlns="urn:schemas-OLDSTRING-com:VARIABLESTRING">
            <merchantID>TESTID</merchantID>   
          </requestMessage>
       </soapenv:Body>
    </soapenv:Envelope>


OUTPUT XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:schemas-NEWSTRING-com:transaction-data-1.69">
   <soapenv:Header/>
   <soapenv:Body>
      <requestMessage xmlns="urn:schemas-NEWSTRING-com:VARIABLESTRING">
        <merchantID>TESTID</merchantID>   
      </requestMessage>
   </soapenv:Body>
</soapenv:Envelope>

I have tried the following XSL, and able to change the namespace URI, but i want to replace only ‘OLDSTRING’ with ‘NEWSTRING’ and keep remaining string as it is.

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="@*|*|text()" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="//*[namespace-uri()='urn:schemas-OLDSTRING-com:VARIABLESTRING']">
        <xsl:element name="{local-name()}" namespace="urn:schemas-NEWSTRING-com:VARIABLESTRING" >
            <xsl:apply-templates select="@*|*|text()" />
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>
  • 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-01T06:27:04+00:00Added an answer on June 1, 2026 at 6:27 am

    This kind of processing is easy in XSLT 2.0, but quite tricky in XSLT 1.0:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:param name="pTarget" select="'OLDSTRING'"/>
     <xsl:param name="pRepl" select="'NEWSTRING'"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
      "*[starts-with(namespace-uri(), 'urn:schemas')
       or
         namespace::*[starts-with(., 'urn:schemas')]
        ]">
    
      <xsl:variable name="vNS" select="namespace-uri()"/>
    
      <xsl:variable name="vNewNS">
        <xsl:choose>
          <xsl:when test="not(contains($vNS, $pTarget))">
            <xsl:value-of select="$vNS"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="substring-before($vNS, $pTarget)"/>
            <xsl:value-of select="$pRepl"/>
            <xsl:value-of select="substring-after($vNS, $pTarget)"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
    
      <xsl:element name="{name()}" namespace="{$vNewNS}">
       <xsl:copy-of select=
         "namespace::*
            [not(. = $vNS
                or
                 starts-with(., 'urn:schemas')
               and
                 contains(., $pTarget)
                 )
            ]"/>
    
       <xsl:for-each select=
         "namespace::*
            [starts-with(., 'urn:schemas')
           and
             contains(., $pTarget)
            ]">
         <xsl:variable name="vNewNSUri" select=
         "concat(substring-before(., $pTarget),
                 $pRepl,
                 substring-after(., $pTarget)
                 )
         "/>
    
         <xsl:variable name="vPrefix" select="name()"/>
    
         <xsl:variable name="vPref">
           <xsl:if test="$vPrefix">
             <xsl:value-of select="concat($vPrefix, ':')"/>
           </xsl:if>
         </xsl:variable>
    
         <xsl:variable name="vrtfDoc">
          <xsl:element name="{$vPref}dummy"
                       namespace="{$vNewNSUri}"/>
         </xsl:variable>
    
         <xsl:copy-of select=
         "ext:node-set($vrtfDoc)/*/namespace::*[. = $vNewNSUri]"/>
       </xsl:for-each>
    
       <xsl:apply-templates select="node()|@*"/>
      </xsl:element>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document:

    <soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:urn="urn:schemas-OLDSTRING-com:VARIABLESTRING">
        <soapenv:Header/>
        <soapenv:Body>
            <requestMessage xmlns="urn:schemas-OLDSTRING-com:VARIABLESTRING">
                <merchantID>TESTID</merchantID>
            </requestMessage>
        </soapenv:Body>
    </soapenv:Envelope>
    

    the wanted, correct result is produced:

    <soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:urn="urn:schemas-NEWSTRING-com:VARIABLESTRING">
      <soapenv:Header />
      <soapenv:Body>
        <requestMessage xmlns="urn:schemas-NEWSTRING-com:VARIABLESTRING">
          <merchantID>TESTID</merchantID>
        </requestMessage>
      </soapenv:Body>
    </soapenv:Envelope>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SOAP application created with delphi. Input comes to server correct. But
How to rewrite Webconfig connection string at runtime.I have input textbox for Server,UserName and
Is there a size limit on a SOAP message's input parameters? I currently need
I have a problem related to parsing a SOAP message. This is the message:
I have input that may either be a string or be a string of
I have soap webservice built with soaplib, but if client sent chunked request it
I have a C++ SOAP client using gSOAP and am trying to construct a
I have input fields, which I process with AJAX and send it on another
Currently I have Input: e.g., '123456789'.'+'.'987654321' Desired Pattern: Output: e.g., '123456789987654321' How can I
I have an arraylist set up. I have input instuctions set up too, so

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.