XSLT: remove namespace prefix from elements

I need to remove the namespace prefix from 'un-SOAP' message.

This is the message that removed the SOAP envelope. As you can see, it contains the ns1 prefix :

<ns1:BookingSource xmlns:ns1="urn:EDI/Booking/artifacts">
    <ns1:BookingHeader>
        <ns1:BookingNo>000123</ns1:BookingNo>
        <ns1:BookingDate>01/01/2012</ns1:BookingDate>
        <ns1:DSBookingDetail>
            <ns1:BookingNo>000123</ns1:BookingNo>
            <ns1:SeqNo>1</ns1:SeqNo>
            <ns1:LineType>Item</ns1:LineType>
            <ns1:ProductCode>Box</ns1:ProductCode>
        </ns1:DSBookingDetail>
        <ns1:DSBookingDetail>
            <ns1:BookingNo>000123</ns1:BookingNo>
            <ns1:SeqNo>2</ns1:SeqNo>
            <ns1:LineType>Item</ns1:LineType>
            <ns1:ProductCode>BrakeShoe</ns1:ProductCode>
        </ns1:DSBookingDetail>
    </ns1:DSBookingHeader>
    <ns1:BookingHeader>
        <ns1:BookingNo>000124</ns1:BookingNo>
        <ns1:BookingDate>01/01/2012</ns1:BookingDate>
        <ns1:DSBookingDetail>
            <ns1:BookingNo>000124</ns1:BookingNo>
            <ns1:SeqNo>1</ns1:SeqNo>
            <ns1:LineType>Item</ns1:LineType>
            <ns1:ProductCode>Box</ns1:ProductCode>
        </ns1:DSBookingDetail>
        <ns1:DSBookingDetail>
            <ns1:BookingNo>000124</ns1:BookingNo>
            <ns1:SeqNo>2</ns1:SeqNo>
            <ns1:LineType>Item</ns1:LineType>
            <ns1:ProductCode>BrakeShoe</ns1:ProductCode>
        </ns1:DSBookingDetail>
    </ns1:DSBookingHeader>
</ns1:BookingSource>

      

For this:

<BookingSource>
    <BookingHeader>
        <BookingNo>000123</BookingNo>
        <BookingDate>01/01/2012</BookingDate>
        <DSBookingDetail>
            <BookingNo>000123</BookingNo>
            <SeqNo>1</SeqNo>
            <LineType>Item</LineType>
            <ProductCode>Box</ProductCode>
        </DSBookingDetail>
        <DSBookingDetail>
            <BookingNo>000123</BookingNo>
            <SeqNo>2</SeqNo>
            <LineType>Item</LineType>
            <ProductCode>BrakeShoe</ProductCode>
        </DSBookingDetail>
    </DSBookingHeader>
    <BookingHeader>
        <BookingNo>000124</BookingNo>
        <BookingDate>01/01/2012</BookingDate>
        <DSBookingDetail>
            <BookingNo>000124</BookingNo>
            <SeqNo>1</SeqNo>
            <LineType>Item</LineType>
            <ProductCode>Box</ProductCode>
        </DSBookingDetail>
        <DSBookingDetail>
            <BookingNo>000124</BookingNo>
            <SeqNo>2</ns1:SeqNo>
            <LineType>Item</LineType>
            <ProductCode>BrakeShoe</ProductCode>
        </DSBookingDetail>
    </DSBookingHeader>
</BookingSource>

      

I've searched in KB and found some hints on how to do this, but the final solution eludes me.

Thank you, Tony.

+3


source to share


1 answer


It is called namespace, below is the code to remove namespace from all elements and attributes.



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="*">
    <xsl:element name="{local-name(.)}">
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>
  <xsl:template match="@*">
    <xsl:attribute name="{local-name(.)}">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>

      

+15


source







All Articles