xml - remove namespace using xslt -


hi new xml , i'm using xslt remove namespaces.below input code.

<ks6:newrequest xmlns:ks6="http://example.com/connector/ssw" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:ks3="com.newtech.kake.notification" xmlns:ks5="com.newtech.alert" xmlns:ks7="http://notification.newtech.com">     <ks5:new book = "5073">         <ks5:entityid>2314</ks5:entityid>         <ks5:entityname>newreq</ks5:entityname>     </ks5:new>     <ks3:new2>        <ks3:entityid>2315</ks3:entityid>         <ks3:entityname>newreq2</ks3:entityname>     </k3:new2> </ks6:newrequest> 

what want remove namespace ks6 uri i.e. xmlns , use namespace ks5 instead of ks6. here, how output should look.

<ks5:newrequest xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"      xmlns:ks3="com.newtech.kake.notification"     xmlns:ks5="com.newtech.alert" xmlns:ks7="http://notification.newtech.com">         <ks5:new book = "5073">             <ks5:entityid>2314</ks5:entityid>             <ks5:entityname>newreq</ks5:entityname>         </ks5:new>        <ks3:new2>            <ks3:entityid>2315</ks3:entityid>            <ks3:entityname>newreq2</ks3:entityname>        </k3:new2>     </ks5:newrequest> 

thanks,

with xslt, have write templates matching nodes want transform, in case want change namespace of elements in namespace , want strip namespace other elements need

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform"     version="1.0">      <xsl:template match="@* | node()">         <xsl:copy>             <xsl:apply-templates select="@* | node()"/>         </xsl:copy>     </xsl:template>      <xsl:template match="*">         <xsl:element name="{name()}" namespace="{namespace-uri()}">             <xsl:copy-of select="namespace::*[not(. = 'http://example.com/connector/ssw')]"/>             <xsl:apply-templates select="@* | node()"/>         </xsl:element>     </xsl:template>      <xsl:template match="ks6:*" xmlns:ks6="http://example.com/connector/ssw">         <xsl:element name="ks5:{local-name()}" namespace="com.newtech.alert">             <xsl:copy-of select="namespace::*[not(. = 'http://example.com/connector/ssw')]"/>             <xsl:apply-templates select="@* | node()"/>         </xsl:element>     </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -