3

模板匹配中的实现和条件

       <xsl:template match="a[!(img)and(not(@id))]">

我想写一个模板,这样

       a tag should not have attribute id and should not be followed by img tag.

但它的显示错误。任何人都可以帮助

4

2 回答 2

8

假设followed by img tag指的是孩子而不是兄弟姐妹,您只需要巩固您对not()函数的使用,而不是不受支持的!运算符:

<xsl:template match="a[not(img) and not(@id)]">
    <!-- ... -->
</xsl:template>
于 2012-07-04T06:10:50.173 回答
2

首先,错误可能是因为你在做!(img),这是无效的。应该不是(img)

但是,在您的 XSLT 中,您正在检查img元素是否是 a 元素的子元素。您真的应该让我们使用以下兄弟轴。

<xsl:template match="a[not(following-sibling::*[1][self::img]) and not(@id)]"> 

因此,following-sibling::*[1]匹配a元素的第一个后续兄弟,然后[self::img]检查它是否是img标签。

请注意,如果您只执行a[not(following-sibling::*[self::img])那么它将查找任何后续兄弟,而不仅仅是紧跟a元素的那个。

于 2012-07-04T06:31:03.570 回答