Reputation:
I am trying to create a winform application that searches through an XML doc. for my search I need to convert the the XML attribute in the xpath condition to lower case, by using lower-case() xpath function. this causes a problem related to the function namespace.
I have tried to add the namespace manualy:
XmlNamespaceManager nsMgr = new XmlNamespaceManager(prs.Doc.NameTable);
nsMgr.AddNamespace("fn", "http://www.w3.org/2005/02/xpath-functions");
XmlNodeList results = prs.Doc.SelectNodes("//function[starts-with(fn:lower-case(@name),'" + txtSearch.Text + "')]",nsMgr);
but still I get exception: XsltContext is needed for this query because of an unknown function.
Upvotes: 8
Views: 6774
Reputation: 243449
The lower-case()
function is defined for XPath 2.0.
In XPath 1.0 to convert letters to lower case one can still use the
translate()
function as shown below:
translate(@attrName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')
Upvotes: 6
Reputation: 16848
I think CodeMelt is correct and gets my +1, but perhaps the Microsoft ms:string-compare extension function (with case-insensitive option) may help solve your problem?
Upvotes: 3
Reputation: 26658
fn:lower-case is defined in XQuery 1.0 and XPath 2.0. XSLT 2.0 works with XPATH 2.0.
AFAIK, .NET hasn't support XPATH 2.0 yet. and the XSLT version from .NET is 1.0 as well not 2.0 yet.
Upvotes: 4