Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 如何从根元素中删除soap命名空间_Xslt - Fatal编程技术网

Xslt 如何从根元素中删除soap命名空间

Xslt 如何从根元素中删除soap命名空间,xslt,Xslt,我在xslt转换中面临一些问题。我想删除在xslt转换期间添加到结果中的额外名称空间 以下是我的源xml: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <Root xmlns="http://www.abc123.org/xyz/ase" xmlns:xsd="http://www.w3.org/2001/XM

我在xslt转换中面临一些问题。我想删除在xslt转换期间添加到结果中的额外名称空间

以下是我的源xml:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <Root xmlns="http://www.abc123.org/xyz/ase" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <Header>           
            <CreationDateTime>2019-05-08T06:34:04.2235068-05:0011</CreationDateTime>
            <BODID>51c336d1-8e6a-46211c-973f-a9ca6c8a33ce</BODID>
            <ReferenceID>9078111e00-9b82-46b3-a419-be80521b2a94</ReferenceID>
            <Success>false</Success>
         </Header>
         <Data>
            <ErrorMessage>
               <ID/>
               <Type>Invalid Data</Type>
               <Description>InvalidData</Description>
            </ErrorMessage>
         </Data>
      </Root>
   </soapenv:Body>
</soapenv:Envelope>

2019-05-08T06:34:04.2235068-05:0011
51c336d1-8e6a-46211c-973f-a9ca6c8a33ce
9078111e00-9b82-46b3-a419-be80521b2a94
假的
无效数据
无效数据
以下是我的xslt代码:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" exclude-result-prefixes="soapenv">
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="soapenv:*">
    <xsl:apply-templates select="@* | node()" />
  </xsl:template>
</xsl:stylesheet>

预期产出:

<Root xmlns="http://www.abc123.org/xyz/ase" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <Header>           
            <CreationDateTime>2019-05-08T06:34:04.2235068-05:0011</CreationDateTime>
            <BODID>51c336d1-8e6a-46211c-973f-a9ca6c8a33ce</BODID>
            <ReferenceID>9078111e00-9b82-46b3-a419-be80521b2a94</ReferenceID>
            <Success>false</Success>
         </Header>
         <Data>
            <ErrorMessage>
               <ID/>
               <Type>Invalid Data</Type>
               <Description>InvalidData</Description>
            </ErrorMessage>
         </Data>
</Root>

2019-05-08T06:34:04.2235068-05:0011
51c336d1-8e6a-46211c-973f-a9ca6c8a33ce
9078111e00-9b82-46b3-a419-be80521b2a94
假的
无效数据
无效数据
实际产量:

 <Root xmlns="http://www.abc123.org/xyz/ase" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
         <Header>           
            <CreationDateTime>2019-05-08T06:34:04.2235068-05:0011</CreationDateTime>
            <BODID>51c336d1-8e6a-46211c-973f-a9ca6c8a33ce</BODID>
            <ReferenceID>9078111e00-9b82-46b3-a419-be80521b2a94</ReferenceID>
            <Success>false</Success>
         </Header>
         <Data>
            <ErrorMessage>
               <ID/>
               <Type>Invalid Data</Type>
               <Description>InvalidData</Description>
            </ErrorMessage>
         </Data>
 </Root>

2019-05-08T06:34:04.2235068-05:0011
51c336d1-8e6a-46211c-973f-a9ca6c8a33ce
9078111e00-9b82-46b3-a419-be80521b2a94
假的
无效数据
无效数据
这里,我得到了需要删除的额外名称空间“xmlns:soapenv”

请建议更正


谢谢

xsl:copy将复制XML中声明的任何名称空间,即使元素本身不使用名称空间

您可以做的是,不用对元素使用
xsl:copy
,而是使用
xsl:element
创建一个新元素,并只跨所需的名称空间声明进行复制

尝试将此模板添加到XSLT

<xsl:template match="*[namespace-uri() != 'http://schemas.xmlsoap.org/soap/envelope/']" priority="2">
  <xsl:element name="{name()}" namespace="{namespace-uri()}">
    <xsl:copy-of select="namespace::*[. != 'http://schemas.xmlsoap.org/soap/envelope/']" />
    <xsl:apply-templates select="@* | node()" />  
  </xsl:element>
</xsl:template>