Search code examples
xpathxquerymarklogic

How to perform a case-insensitive match in MarkLogic 6


Hi I have used cts search and XPath query in MarkLogic and also I have used more than one parameter. I need to capture both capital and small character (inside the XML search).

Sample XML

<PP uri="/2000_4_174.xml">
  <P name="jur" value="ht"/>
  <P name="sitting" value="17 AUGUST"/>
  <P name="startpage" value="174"/>
</PP>

My XQuery

let $attr1  := "JUR"
let $attr2  := "startpage"
let $value1 := "ht"
let $value2 := "174"

let $uri := //PP[P[@name=$attr1 and @value=$value1] and   P[@name=$attr2 and @value=$value2]]/@uri
return $uri

When $attr1 value is jur, the query runs successfully but I want to provide the value either caps or lower case. Please let me know any options.

Note: After changing the collation cts search working both caps and lower case, but the XPath query not working.


Solution

  • To address the XPath part of the problem, you can do a case insensitive match.

    let $attr1  := "JUR"
    let $attr2  := "startpage"
    let $value1 := "ht"
    let $value2 := "174"
    
    let $uri := //PP[P[fn:matches(@name, $attr1, "i") and @value=$value1] and 
        P[@name=$attr2 and @value=$value2]]/@uri
    return $uri
    

    I'd expect this to be slightly slower, but it will match regardless of the case.