简体   繁体   English

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

[英]Add new element to XML via XSLT 1.0 but without xmlns

I have this XML file and I've applied an XSLT.我有这个 XML 文件并且我已经应用了 XSLT。 The result I want is to add a new element but one that doesn't contain a namespace.我想要的结果是添加一个新元素,但不包含命名空间。

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

I have applied this XSLT:我已经应用了这个 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>

And the result is the one below.结果如下。 But I dont want to have that namespace xmlns.但我不想拥有那个命名空间 xmlns。 I just want a new element as I wrote it.我只想要一个新元素,就像我写的那样。

<?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元素。

You are analyzing the situation incorrectly:您正在错误地分析情况:

All the elements of your source document are in the default namespace xmlns="http://www.ibm.com/maximo" and your stylesheet copies them as is .源文档的所有元素都在默认名称空间xmlns="http://www.ibm.com/maximo"并且您的样式表按原样复制它们。

Your added element is is no-namespace - and the xmlns="" declaration is an indication of that.您添加的元素是无命名空间 - xmlns=""声明表明了这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM