繁体   English   中英

XSLT 1.0 not(包含在for-each中

[英]XSLT 1.0 not(contains in for-each

我想包括以下内容:

not(contains(country/product/@genericname, 'Color Purple'))

for-each

<xsl:for-each select="country[@name = 'GB']/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')]">

我尝试了这个:

<xsl:for-each select="not(contains(country/product/@genericname, 'Stylus Pro')) and country[@name = $country]/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')]">

但是,我得到了这个错误: The value is not a node-set 我没有看到语法错误。

处理器:Saxon6.5.5

@ michael.hor257k

我修改了您的代码段,让我的参数看上去更适合每个人。

<xsl:param name="country">GB</xsl:param>
<xsl:for-each select="country[@name = $country]/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')] [not(contains(country/product/@genericname, 'Stylus Pro'))]">

XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<countries>
    <country name="GB">
        <product genericname="Yellow line" id="12345" />
        <product genericname="Red line" id="6789" type="device" />
        <product genericname="This is Stylus Pro" id="256464" />
    </country>
</countries>

编辑

这是正确的方法,谢谢,这是错误的道路。

<xsl:for-each select="country[@name = 'GB']/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')] [not(contains(**@genericname**, 'Stylus Pro'))]">

不是国家/产品/ @通用名称

谢谢

not(contains())必须位于谓词中 (方括号内)。 在谓词之外,您需要具有通往节点的路径。 发布您的XML代码示例,以获得更具体的答案。

我猜这可能是您想要的:

<xsl:for-each select="country[@name = 'GB']/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')] [not(contains(@genericname, 'Color Purple'))]">

请注意,路径指向product ,并且谓词限制了要包括在选择中的产品类别。


编辑:

XSLT对上下文非常敏感。

[not(contains(@genericname, 'Stylus Pro'))]

与以下内容有很大的不同:

[not(contains(country/product/@genericname, 'Stylus Pro'))] 

第一个查看当前节点genericname属性。 在以下情况下:

select="country[...]/product[...]"

当前节点是product

第二个对象查看名为product的节点的genericname属性,该节点是country的子级,而country是当前节点的子级。 此属性不存在-因此,它当然不包含搜索字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM