0

私はxmlを持っています:

<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <med:PutEmployee xmlns:med="https://services">
      <med:employees>
         <med:Employee>
            <med:Name xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:nil="true">Мария</med:Name>
            <med:SNILS>111-111-111-11</med:SNILS>
         </med:Employee>
      </med:employees>
   </med:PutEmployee>
</soapenv:Body>

xslt を使用してパラメーター「@i:nill」を削除しました。

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
   exclude-result-prefixes="i">               
   <xsl:template match="node() | @*">
      <xsl:copy>
         <xsl:apply-templates select="node() | @*[name()!='i:nil']" />
      </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

xslt を実行すると、xml が得られました。

<?xml version="1.0"?>
<?xml version="1.0"?>
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <med:PutEmployee xmlns:med="https://services">
      <med:employees>
         <med:Employee>
            <med:Name xmlns:i="http://www.w3.org/2001/XMLSchema-instance">Мария</med:Name>
            <med:SNILS>111-111-111-11</med:SNILS>
         </med:Employee>
      </med:employees>
   </med:PutEmploy>

を残したxmlns:i="http://www.w3.org/2001/XMLSchema-instance"

それを削除するには?

を追加しようとしましexclude-result-prefixes = "i"たが、役に立ちませんでした

4

2 に答える 2

3

XSLT 2.0 を使用している場合は、

<xsl:copy copy-namespaces="no">
于 2013-07-18T07:15:10.357 に答える
2

これでうまくいくはずです:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
                exclude-result-prefixes="i">
  <xsl:output omit-xml-declaration="yes"/>

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

  <xsl:template match="@i:nil" />

  <xsl:template match="*">
    <xsl:element name="{name()}" namespace="{namespace-uri()}">
      <xsl:apply-templates select="@* | node()" />
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

サンプル入力で実行すると、結果は次のようになります。

<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <med:PutEmployee xmlns:med="https://services">
    <med:employees>
      <med:Employee>
        <med:Name>Мария</med:Name>
        <med:SNILS>111-111-111-11</med:SNILS>
      </med:Employee>
    </med:employees>
  </med:PutEmployee>
</soapenv:Body>
于 2013-07-17T13:50:53.553 に答える