从XSLT中删除特定命名空间

时间:2018-03-19 09:24:45

标签: xslt jdeveloper bpel

您需要建议我想使用xslt

删除特定的NameSpace

输入如下: -

            <GNRequest 
        xmlns="http://xmlns.tom.be/cms">     
           <Input>   
              <DocumentInputs>
                 <DocumentInput>   

                    <Language>DE</Language>
                    <TemplateInput>
                        <MPC>
                        <InteractionType xmlns="asdfasd">MobileProductOptionActivation</InteractionType>
                        <SMdn>123456</SMdn>             
                        </MPC>
                        </TemplateInput>
                 </DocumentInput>        
              </DocumentInputs>
           </Input>
        </GNRequest>

应用XSLT输出后变为:

            <?xml version="1.0" encoding="UTF-8"?><tns:Input xmlns:tns="http://xmlns.tom.be/csm/v001" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:pc="http://xmlns.oracle.com/pcbpel/" xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/">
        <tns:DocumentInputs>
        <tns:DocumentInput>
        <tns:Language>DE</tns:Language>
        <tns:TemplateInput>
        <MPC xmlns="http://xmlns.tom.be/cms">
        <InteractionType 
           xmlns="asdfasd">MobileProductOptionActivation</InteractionType>
        <SMdn>123456</SMdn>             
        </MPC>
        </tns:TemplateInput>
        </tns:DocumentInput>
        </tns:DocumentInputs>
        </tns:Input>

所以extranameSpace添加了xmlns =“http://xmlns.tom.be/cms”

XSLT:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:tns="http://xmlns.tom.be/csm/v001"
                 xmlns:ns0="http://xmlns.tom.be/cms"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>

   <xsl:template match="/">
     <tns:Input>
       <tns:DocumentInputs>
         <xsl:for-each 
select="/ns0:GNRequest/ns0:Input/ns0:DocumentInputs/ns0:DocumentInput">
           <tns:DocumentInput>
             <tns:Language>
               <xsl:value-of select="ns0:Language"/>
             </tns:Language>
             <tns:TemplateInput>
          <xsl:apply-templates select="(ns0:TemplateInput/*)"/></tns:TemplateInput>
           </tns:DocumentInput>
         </xsl:for-each>
       </tns:DocumentInputs>
     </tns:Input>
   </xsl:template>

   <xsl:template match="@*|node()">
     <xsl:copy >
       <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:0)

只需添加另一条规则以匹配您想要的元素,并创建一个具有相同本地名称但没有命名空间的新元素:

<xsl:template match="ns0:*">
  <xsl:element name="{local-name()}">
    <xsl:apply-templates select="node()|@*"/>
  </xsl:element>
</xsl:template>
<!-- the above goes before ... -->

<xsl:template match="@*|node()">
  <xsl:copy >
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

请注意,一般情况下删除命名空间并不是一个好主意,因为您丢失了信息。

相关问题