Archive for tag: translate()

XPath value lower case or upper case function in C#

XPath function to translate or convert into lower case using two different ways based on version of XPath.

In XPath 2.0 onwards it has function lower-case() or upper-case(). If your environment supports this version of the standard, you can write:

Lower Case:

NodeIter = nav.Select("/Products/Product/name[lower-case(.) ='" + productName +"']")

Upper Case:

NodeIter = nav.Select("/Products/Product/name[upper-case(.) ='" + productName +"']")

However, if your system supports XPath version 1.0. In that case, you can use the translate() function:

Lower Case:

NodeIter = nav.Select("("/Products/Product/name[ (translate(., "
    + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '"
    + productName + '"]");

Upper Case:

NodeIter = nav.Select("("/Products/Product/name[ (translate(., "
    + "'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), '"
    + productName + '"]");

If you have any question don't forget to ask
Thank you for watching this article