XSLT:从元素中删除命名空间前缀 [英] XSLT: Remove namespace prefix from elements

查看:46
本文介绍了XSLT:从元素中删除命名空间前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从非 SOAP 消息中删除命名空间前缀.

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

这是删除了 SOAP 信封的消息.如您所见,它在元素上包含 ns1 前缀:

This is the message that has had the SOAP envelope removed. As you can see it contains ns1 prefix on the elements:

<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>

为此:

<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 through the KB and found some hints on how to do it, but the final solution evades me.

谢谢,托尼.

推荐答案

它被称为命名空间,下面是从所有元素和属性中删除命名空间的代码..

It is called namespace, below is a 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>

这篇关于XSLT:从元素中删除命名空间前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆