/scripts/ahub.form.attachments.js
0

XSLT change namespace

Feb 17, 2017 at 01:04 AM

140

avatar image

I'm trying to change the namespace of an element attribute using the below xsl code

<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:ns2="http://www.ean-ucc.org/schemas/1.3.1/eanucc"> 
    <xsl:output encoding='UTF-8' indent='yes' method='xml'/>

    <!-- copy everything into the output -->
    <xsl:template match='@*|node()'>
        <xsl:copy>
            <xsl:apply-templates select='@*|node()'/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="IRenvelope">
        <IRL xmlns:xsd="http://www.xx.com">
            <xsl:copy-of select="node()|@*"/>
        </IRL>
    </xsl:template>
</xsl:stylesheet>

my input to the xsl is

<GMessage xmlns="http://www.giffgaff.uk/CM/envelope">
<EnvelopeVersion>2.0</EnvelopeVersion>
  <body>
    <IRenvelope xmlns="http://www.mnv.com/elc/sap">
            <Keys>
                <Key Type="TaxOfficeNumber">635</Key>
            </Keys>
        </IRenvelope>
   </body>
 </GMessage>

for an expected output as below

 <GMessage xmlns="http://www.giffgaff.uk/CM/envelope">
         <EnvelopeVersion>2.0</EnvelopeVersion>
           <body>
             <IRenvelope xmlns="http://www.xx.com">
               <Keys>
                  <Key Type="TaxOfficeNumber">635</Key>
                </Keys>
               </IRenvelope>
            </body>
       </GMessage>

any thoughts and suggestions on how to get this done please?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Evgeniy Kolmakov Feb 17, 2017 at 09:36 AM
0

Hi Prabhu!

<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
                              xmlns:ns2="http://www.ean-ucc.org/schemas/1.3.1/eanucc"
                              xmlns:def="http://www.mnv.com/elc/sap"
                              exclude-result-prefixes="def ns2 xsl"> 
    <xsl:output encoding='UTF-8' indent='yes' method='xml'/>
    <xsl:template match='@*|node()'>
        <xsl:copy>
            <xsl:apply-templates select='@*|node()'/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="def:IRenvelope">
        <IRL xmlns="http://www.xx.com">
            <xsl:apply-templates/>
        </IRL>
    </xsl:template>
    <xsl:template match="def:*">
        <xsl:element name="{local-name()}" namespace="http://www.xx.com">
            <xsl:apply-templates select="@* | node()" />
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Regards, Evgeniy.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

hi Evgeniy

seems pi 7.1 works on xslt version 1.0 and the code seems not working. Please can you help with the version 1.o

0

Hi Prabhu!

The same transformation can be used with XSLT 1.0. Just change version to 1.0 in the transformation's header.

Regards, Evgeniy.

0
Prabhu S Feb 17, 2017 at 02:23 PM
0

thk u...that worked

Share
10 |10000 characters needed characters left characters exceeded
Skip to Content