【问题标题】:XSLT 1.0 not(contains in for-eachXSLT 1.0 不是(包含在 for-each 中
【发布时间】:2014-08-28 13:13:56
【问题描述】:

我想包括这个:

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

我调整了你的 sn-p,用我的参数看起来更合适。

<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'))]">

不是国家/产品/@genericname

谢谢

【问题讨论】:

    标签: xml xslt foreach contains


    【解决方案1】:

    not(contains()) 需要在 谓词 中(方括号内)。在谓词/s 之外,您需要有一条通往节点的路径。发布您的 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 是当前节点的子节点。该属性不存在 - 所以它当然不包含搜索字符串。

    【讨论】:

    • @Stefan 好吧,它会选择确实在其genericname 属性中包含“Color Purple”的产品吗?
    • @Stefan 请不要在 cmets 中发布代码;改为编辑您的问题。 -- 我不确定你是否看过我的评论:你使用的代码不是我发布的代码。
    • 我正在学习...我发布了我的改编的真实代码我的目标是:我想排除 Stylus Pro
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多