【问题标题】:XPath to find an element whose attribute contains a text, case-insensitively?XPath 查找其属性包含文本的元素,不区分大小写?
【发布时间】:2012-03-07 15:14:44
【问题描述】:
    <root>
// other nodes
    <a href="/PatternFramework/Pages/LogOut.aspx?np=/sites/novatestsite/Home.aspx" slick-uniqueid="92">Sign out</a>
    </root>

如何编写返回a 标记的xpath,其href 包含“logout.aspx”?

比如

//a[@href[contains[., "logout.aspx"]]

【问题讨论】:

    标签: xml xslt xpath


    【解决方案1】:

    区分大小写:

    //a[contains(@href,'logout.aspx')] 
    

    XPath 2.0 不区分大小写:

    //a[contains(lower-case(@href),'logout.aspx')] 
    

    XPath 1.0 不区分大小写:

    //a[contains(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'logout.aspx')] 
    

    【讨论】:

    • 是谁?使用了哪个 xpath-provider?
    • bit-101.com/xpath 是 2006 年的旧工具。使用xpath.online-toolz.com/tools/xpath-editor.php
    • 啊,我的原文有“LogOut”。如何使它不区分大小写?我的意思是忽略区分大小写?
    • 这不区分大小写,只是小写。
    • @nicolimo86 完全不区分大小写的变体://a[contains(lower-case(@href),lower-case('LogOut.aspx'))]
    猜你喜欢
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 2012-02-18
    相关资源
    最近更新 更多