xml - 如何使用 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 文件?
解决方案
查看更多 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>
推荐阅读
- postgresql - 将字段上的值转换为新值以作为键加入 PostgreSQL
- c# - 为什么每次使用此身份验证过程都必须重新登录
- mysql - 如何根据 ID 从另一个表的单个字段中获取每一行的所有结果
- html - 如何修复'$'modal bootstrap未定义?
- c# - 如何使用 ADO.NET 将 API 中的 json 插入雪花数据库?
- java - 在 while 循环中验证 isDisplayed() WebElement 属性
- azure-devops - DevOps 发布从 QA 到 PRODUCTION
- schema - Flatbuffers Schema:联合向量不能使用 --binary
- c++ - 从 0 数到 N
- python - “POST /upload HTTP/1.1”415 - 视频上传问题