Using translate function in XPath gives error

anutachkabelova

New Member
I have to do a case-insensitive XML search. I've written XPath expressions which are working fine, but when I use the \[code\]translate\[/code\] function inside an XPath expression I get an error. Below are the XPath expressions that are working fine:\[code\]string upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";string lower = "abcdefghijklmnopqrstuvwxyz";string xpath = "/data/item[AID/@iskey='true' and AID/text() = 'fep'][not(*[@iskey][local-name() != 'AID' ])]"; string xpath1 = "/data/item[translate('Aid','" + upper + "','" + lower + "')]";\[/code\]And here is my XML:\[code\]<?xml version="1.0" encoding="utf-8"?><data><item> <AID iskey="true">fep</AID> <account>MS</account> </item></data>\[/code\]I want to place the \[code\]translate\[/code\] function in the first XPath expression like this:\[code\] string xpath = "/data/item[translate('AID','" + upper + "','" + lower + "')/@iskey='true' and translate('AID','" + upper + "','" + lower + "')/text() = 'fep'][not(*[@iskey][local-name() != translate('aid','" + upper + "','" + lower + "') ])]";\[/code\]When I do this, I get the following error:Expression must evaluate to a node-set.This xpath is working fine for me. string col="AID"; string xpath = "/data/item[col/@iskey='true' and col/text() = 'fep'][not(*[@iskey][local-name() != 'col' ])]"; Now my requirement is that the col value can be in any case upper case or lower case, so I want a change in my xpath with which it returns me the result irrespective of in which case data is present in the xml. If a user gives aid or Aid or aiD it returns me the result.
 
Back
Top