xslt-1.0 - 如何放置“和”条件以从 xslt 中删除 xml 元素
问题描述
我是 XSLT 的新手,并且有一个条件可以根据 XSLT 中应用的条件从 XML 文件中删除一个元素。我必须根据同一属性的 2 个条件删除 en 元素。
这是我的虚拟代码:
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="cdm:attributeList/cdm:attribute[cdm:attributeName = 'format'] and cdm:attributeList/cdm:attribute[cdm:attributeValue = 'XYZ']" />
运行 XSLT 文件时出现以下错误: 1. 额外的非法标记:'and' 2. xsl:output 元素上不允许使用“exclude-result-prefixes”属性!
有人可以帮我解决这个问题吗?谢谢。
解决方案
模板匹配条件不正确,and
匹配模板时不允许操作符。您需要修改模板匹配条件如下,它对应于所需条件的组合。
<xsl:template match="cdm:attributeList/cdm:attribute[cdm:attributeName = 'format'][cdm:attributeValue = 'XYZ']" />
对于第二个问题exclude-result-prefixes
,它是一个属性<xsl:stylesheet>
而不是<xsl:output>
。因此,如果您不希望输出节点具有cdm
前缀,请修改<xsl:stylesheet>
如下
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cdm="http://someurl" exclude-result-prefixes="cdm">
推荐阅读
- postgresql - 如何列出 PostgreSQL 中所有表的所有约束?
- c# - 当其中一个开关打开时切换其他开关
- mongodb - MongoDB 使用通过 C# 驱动程序插入实体与 BsonDocument
- php - XAMPP Apache 无法在 Ubuntu 20.04.3 LTS 上运行
- javascript - 如何在 Google Sheets 中使用这个 JS 函数?在 var 和循环中使用单元格值
- python - 在 pyspark 中指定列数据类型
- entity-framework-core - Automapper ProjectTo 和 JSON 列
- python - 开始信息复制而不链接到已处理变量
- spring - spring boot 2.5升级请求未绑定到ModelAttribute
- xamarin.forms - 带有扩展消息窗口的 Xamarin.Forms.Maps 引脚