0
votes

I'm facing an issue while trying to change my XML namespace definition.

i have this namespace in my input xml : <ns3:DataElement xmlns:ns3="http://fakeurl_V3/xsd">

and lower in my xml i have a field : <productsList xsi:type="ns3:Segment" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

++++++++++++++++++++++++++++++++++++++++++++++++++ In my XSL i did this :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   
    xmlns:ns2="http://fakeurl_V2/xsd"
    xmlns:ns3="http://fakeurl_V3/xsd"
... others namespace ....
>

    <xsl:output method="xml" version="1.0" omit-xml-declaration="no"
        encoding="UTF-8" indent="yes" />
....

<xsl:template match="ns3:*">
  <xsl:element name="ns2:{local-name()}">
  
    <xsl:apply-templates select="@*|node()" />
  </xsl:element>
</xsl:template>

....

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

there is the result :

<ns2:DataElement xmlns:ns2="http://fakeurl_V2/xsd">

<productsList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns3:Segment">

As you can see the namespace ns2 has been changed as i wish But it did not affect this line : xsi:type="ns3:Segment" that i need to transform in : xsi:type="ns2:Segment"

Do you have any solution about that ?

Thank you for your attention, i hope i made myself clear enougth.

Regards

1
The thing is that the content of the xsi:type attribute is not a namespace, but a meaningless string. You need to modify it using string manipulation.michael.hor257k
Thank you for your answer , do you any idea how i can work on a string inside a param ? I know i will need to use something like : select="fn:replace(fn:string(fn:starts-with('xsi:type', 'ns3')), 'ns3', 'ns2')"Benjamin
this is probably not the good way ; fn:starts-with('xsi:type', 'ns3') but just an exempleBenjamin

1 Answers

0
votes

You could add a template to replace the old prefix with the new one, such as:

<xsl:template match="@xsi:type">
    <xsl:attribute name="{name()}" select="replace(., '^ns3:', 'ns2:')" />
</xsl:template>

Demo: https://xsltfiddle.liberty-development.net/gVrvcxa