【问题标题】:Removal of Namespace using XSLT is not Working使用 XSLT 删除命名空间不起作用
【发布时间】:2016-12-02 04:52:49
【问题描述】:

我正在尝试删除现有名称空间并将另一个名称空间添加到我的 XML 文档中。当我没有添加属性时,它正在工作。现在,当我添加属性“id”时,删除代码不起作用。

我的 XML 文档是:

<?xml version="1.0" encoding="UTF-8"?>

<n0:eCPR xmlns:prx="urn:sap.com:proxy:DV4:/1SAI/TAS1F59A417878D36573F1D:700:2013/05/24" xmlns:n0="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">

<n0:employees>
  <n0:employee>
    <n0:name id="20019768">Paul John</n0:name>
</n0:employee>
</n0:employees>
</n0:eCPR>

我想要的是:

<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
 <CPR:employees>
   <CPR:employee>
   <CPR:name id="12345">JOHN SMITH</CPR:name>
   </CPR:employee>
 </CPR:employees>
</CPR:eCPR>

我应用的 XSLT 代码(在使用我之前的帖子 Unable to Update the Namespace of XML Document 之前正在工作)是:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 <xsl:strip-space elements="*"/>

   <xsl:template match="*">
     <xsl:element name="CPR:{local-name()}">
     <xsl:apply-templates/>
   </xsl:element>
   </xsl:template>

</xsl:stylesheet>

【问题讨论】:

    标签: xml xslt xml-namespaces


    【解决方案1】:

    如果你的输入有属性,你需要这样做:

    <xsl:copy-of select="@*"/>
    

    在你做之前:

    <xsl:apply-templates/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多