1

我有一个源 XML

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
<PublishANZINCIDENTESB xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDateTime="2013-02-25T23:25:35+00:00" transLanguage="EN" baseLanguage="EN" messageID="1361834735434709840" maximoVersion="7 1 20110105-1024 V7118-37" event="1"><ANZINCIDENTESBSet><INCIDENT action="Replace"></INCIDENT></ANZINCIDENTESBSet></PublishANZINCIDENTESB></soapenv:Body></soapenv:Envelope>

我想通过将名称空间和标头添加到标记来更改为目标 XML。输出 XML 是

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s600="http://LIB_ISM_WPS/S600_PublishANZINCIDENT_Service_INT" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Header/><soapenv:Body>
<s600:PublishANZINCIDENTESBOperation><PublishANZINCIDENTESB xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDateTime="2013-02-25T23:25:35+00:00" transLanguage="EN" baseLanguage="EN" messageID="1361834735434709840" maximoVersion="7 1 20110105-1024 V7118-37" event="1"><ANZINCIDENTESBSet><INCIDENT action="Replace"></INCIDENT></ANZINCIDENTESBSet></PublishANZINCIDENTESB></s600:PublishANZINCIDENTESBOperation></soapenv:Body></soapenv:Envelope>

我正在使用的 XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:s600="http://LIB_ISM_WPS/S600_PublishANZINCIDENT_Service_INT" >
 <s600:PublishANZINCIDENTESBOperation>
 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>
</s600:PublishANZINCIDENTESBOperation>
 <xsl:template match="*">
  <xsl:element name="s600:{name()}" namespace="http://LIB_ISM_WPS/S600_PublishANZINCIDENT_Service_INT">
   <xsl:copy-of select="namespace::*"/>
       <xsl:apply-templates select="node()|@*"/>
  </xsl:element>
 </xsl:template>
</xsl:stylesheet>

任何人都可以尽快帮助我吗?

4

1 回答 1

0

从您的输入和输出示例看来,您只是想将一个s600:PublishANZINCIDENTESBOperation元素包装在 的内容周围,soapenv:Body否则保持内容不变。你可以用

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:s600="http://LIB_ISM_WPS/S600_PublishANZINCIDENT_Service_INT"
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

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

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

  <!-- If the namespace declaration absolutely _must_ be on the Envelope 
       you could uncomment this extra template -->
  <!--
  <xsl:template match="soapenv:Envelope">
    <soapenv:Envelope>
      <xsl:apply-templates select="@*|node()" />
    </soapenv:Envelope>
  </xsl:template>
  -->
</xsl:stylesheet>

这将产生您正在寻找的输出,除了xmlns:s600声明将在s600:PublishANZINCIDENTESBOperation元素上而不是在 上soapenv:Envelope,但这对于下游组件应该无关紧要,只要它们使用适当的 XML 解析器来处理数据而不是处理它作为文本。如果将声明放在信封上真的很重要,请取消注释第三个模板。

于 2013-03-29T14:27:05.760 回答