首页 > 解决方案 > 如何使用 xslt 从 xml 中删除未使用的元素?

问题描述

所以我是xslt的新手,我在网上看过,但我很困惑。我刚刚删除了 Location 设置,现在我想删除 XML 文件中的 Location 元素:

在我的 xslt 文件中,我有这个转换来修改 XML 文件

      <xsl:when test="@name = 'Location'">
        <xsl:call-template name="ConvertElement">
          <xsl:with-param name="element" select="." />
          <xsl:with-param name="newElement" select="../Location" />
          <xsl:with-param name="newElementName" select="'Location'"/>
        </xsl:call-template>
      </xsl:when>

什么是 xslt 转换以删除该 Location 元素 XML 文件?

标签: xmlxslt

解决方案


查看更多 XSLT 内容会很有帮助,以便能够提供更具体和正确的答案。

在使用恒等变换时,删除给定元素的方法的一般答案是添加一个与要删除的元素匹配的空模板。然后,当模板匹配该元素时,它不会产生任何输出或对该元素的节点进行任何进一步的处理。

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

  <xsl:template match="Location"/>

</xsl:stylesheet>

推荐阅读