通过 XSLT 1.0 但没有 xmlns 向 XML 添加新元素

Add new element to XML via XSLT 1.0 but without xmlns

我有这个 XML 文件并且我应用了 XSLT。我想要的结果是添加一个新元素,但不包含名称空间。

<?xml version="1.0" encoding="UTF-8"?>  <ITIN3 />
<Export xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
creationDateTime="2018-09-29T12:53:10+02:00" transLanguage="EN" baseLanguage="EN" 
messageID="24242525" maximoVersion="7 6 20190514-1348 V7611-365" event="1">
<MRCSet>
  <MRC action="Add">
     <PONUM>MPO15114</PONUM>
     <POREVISIONNUM>0</POREVISIONNUM>      
  </MRC>
</MRCSet>
</Export>

我已经应用了这个 XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   
 xmlns:mea="http://www.ibm.com/maximo" exclude-result-prefixes="mea">
 <xsl:output omit-xml-declaration="no" indent="yes" encoding="UTF-8"/>
 <xsl:strip-space elements="*"/>
 
   <!-- Identity transform -->
   <xsl:template match="@* | node()">
     <xsl:copy>
   <xsl:apply-templates select="@* | node()"/>

   </xsl:copy> 
   </xsl:template>

   <xsl:template match="/mea:Export/mea:MRCSet/mea:MRC">
   <xsl:copy>
 
   <xsl:copy-of select="@*"/>
   <NEWINFO>1</NEWINFO>
   <xsl:copy-of select="node()"/>

    </xsl:copy>
  </xsl:template>
  </xsl:stylesheet>

结果如下。但我不想拥有那个命名空间 xmlns。我只是想要一个我写的新元素。

<?xml version="1.0" encoding="UTF-8"?>
<Export xmlns="http://www.ibm.com/maximo"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        creationDateTime="2018-09-29T12:53:10+02:00"
        transLanguage="EN"
        baseLanguage="EN"
        messageID="24242525"
        maximoVersion="7 6 20190514-1348 V7611-365"
        event="1">
   <MRCSet>
  <MRC action="Add">
     <NEWINFO xmlns="">1</NEWINFO >
     <PONUM>MPO15114</PONUM>
     <POREVISIONNUM>0</POREVISIONNUM>
      </MRC>
   </MRCSet>
</Export>

xmlns="http://www.ibm.com/maximo" 添加到 xsl:stylesheet 元素或至少添加到 NEWINFO 元素。

你分析的情况不正确:

您的源文档的所有元素都在默认命名空间 xmlns="http://www.ibm.com/maximo" 中,并且您的样式表按原样复制它们

您添加的元素是 no-namespace - xmlns="" 声明表明了这一点。