【问题标题】:How to put 'and' condition to remove an xml element from an xslt如何放置“和”条件以从 xslt 中删除 xml 元素
【发布时间】:2018-08-16 09:11:49
【问题描述】:

我是 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”属性!

有人可以帮我解决这个问题吗? 谢谢。

【问题讨论】:

  • 您能否在运行代码的位置显示输入 XML?

标签: xslt-1.0


【解决方案1】:

模板匹配条件不正确,匹配模板时不允许and运算符。您需要修改模板匹配条件如下,对应所需条件的组合。

<xsl:template match="cdm:attributeList/cdm:attribute[cdm:attributeName = 'format'][cdm:attributeValue = 'XYZ']" />

exclude-result-prefixes的第二期,是&lt;xsl:stylesheet&gt;的属性,不是&lt;xsl:output&gt;的属性。所以如果你不希望输出节点有cdm前缀,修改&lt;xsl:stylesheet&gt;如下

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:cdm="http://someurl" exclude-result-prefixes="cdm">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-08
    • 2021-12-06
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 2019-08-14
    • 2013-09-22
    • 1970-01-01
    相关资源
    最近更新 更多