[英]XSLT 1.0 not(contains in for-each
I want to include this: 我想包括以下内容:
not(contains(country/product/@genericname, 'Color Purple'))
in this for-each
在for-each
<xsl:for-each select="country[@name = 'GB']/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')]">
I tried this: 我尝试了这个:
<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')]">
But, I get this error: The value is not a node-set
. 但是,我得到了这个错误: The value is not a node-set
。 I don't see the syntax error. 我没有看到语法错误。
Processor: Saxon6.5.5 处理器:Saxon6.5.5
@michael.hor257k @ michael.hor257k
I adapted your snippet, look hier the right for-each with params of mine. 我修改了您的代码段,让我的参数看上去更适合每个人。
<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:
<?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>
EDIT 编辑
Here is the right way, thanks, is was the wrong path. 这是正确的方法,谢谢,这是错误的道路。
<xsl:for-each select="country[@name = 'GB']/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')] [not(contains(**@genericname**, 'Stylus Pro'))]">
not country/product/@genericname 不是国家/产品/ @通用名称
Thanks 谢谢
not(contains())
needs to be in a predicate (inside square brackets). not(contains())
必须位于谓词中 (方括号内)。 Outside of the predicate/s, you need to have a path leading to a node. 在谓词之外,您需要具有通往节点的路径。 Post an example of your XML code for a more specific answer. 发布您的XML代码示例,以获得更具体的答案。
I am guessing this may be what you want: 我猜这可能是您想要的:
<xsl:for-each select="country[@name = 'GB']/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')] [not(contains(@genericname, 'Color Purple'))]">
Note that the path points to product
, and the predicates limit the classes of products to be included in the selection. 请注意,路径指向product
,并且谓词限制了要包括在选择中的产品类别。
XSLT is very context-sensitive. XSLT对上下文非常敏感。
[not(contains(@genericname, 'Stylus Pro'))]
is very different from: 与以下内容有很大的不同:
[not(contains(country/product/@genericname, 'Stylus Pro'))]
The first one looks at the genericname
attribute of the current node . 第一个查看当前节点的genericname
属性。 In the context of: 在以下情况下:
select="country[...]/product[...]"
the current node is product
. 当前节点是product
。
The second one looks at the genericname
attribute of a node named product
that is a child of country
that is a child of the current node. 第二个对象查看名为product
的节点的genericname
属性,该节点是country
的子级,而country
是当前节点的子级。 This attribute does not exist - so of course it does not contain the search string. 此属性不存在-因此,它当然不包含搜索字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.