Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8185311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:48:13+00:00 2026-06-07T01:48:13+00:00

I have to do a case-insensitive XML search. I’ve written XPath expressions which are

  • 0

I have to do a case-insensitive XML search. I’ve written XPath expressions which are working fine, but when I use the translate function inside an XPath expression I get an error. Below are the XPath expressions that are working fine:

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 + "')]";

And here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<data>
<item>
 <AID iskey="true">fep</AID>
  <account>MS</account>
  </item>
</data>

I want to place the translate function in the first XPath expression like this:

 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 + "') ])]";

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:48:14+00:00Added an answer on June 7, 2026 at 1:48 am

    The error is due to the fact that in your XPath expression you have a location step like this:

    item['aid'/@isKey = 'true' ...]
    

    The subexpression:

    'aid'/@isKey
    

    is syntactically illegal in XPath, because the left-hand-side of the / operator must be a node-set — here it is just a string.

    You want to have an XPath expression like this — not the one you are generating at present:

    /data/item
           [*[translate(name(), 'aid', 'AID') = 'AID']/@iskey='true'
          and
            *[translate(name(), 'aid', 'AID') = 'AID'] = 'fep'
             ]
              [not(*[@iskey]
                    [translate(name(), 'aid', 'AID') != 'AID']
                 )
             ]
    

    XSLT – based verification:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:variable name="vLower" select="'aid'"/>
     <xsl:variable name="vUpper" select="'AID'"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy-of select=
          "/data/item
               [*[translate(name(), 'aid', 'AID') = 'AID']/@iskey='true'
              and
                *[translate(name(), 'aid', 'AID') = 'AID'] = 'fep'
                 ]
                  [not(*[@iskey]
                        [translate(name(), 'aid', 'AID') != 'AID']
                     )
                 ]
          "/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <data>
        <item>
            <AID iskey="true">fep</AID>
            <account>MS</account>
        </item>
    </data>
    

    the XPath expression is evaluated and the selected nodes (just one in this case) are copied to the output:

    <item>
       <AID iskey="true">fep</AID>
       <account>MS</account>
    </item>
    

    Update:

    The OP has difficulty understanding this solution. This is an example to show him that the solution works for any capitalisation of the string “aid”:

    When the transformation above is applied on an XML document, that contains element names that are any capitalization of “aid” — such as this:

    <data>
        <item>
            <aId iskey="true">fep</aId>
            <account>MS</account>
        </item>
    </data>
    

    again the expected result is produced:

    <item>
       <aId iskey="true">fep</aId>
       <account>MS</account>
    </item>
    

    Update 2:

    The OP still doesn’t understand the solution and claims that for a specific XML document — provided below — “I used your expression it returns null “

    Here is the XML document as provided in the comment of the OP:

    <data>
        <item>
            <aId iskey="true">fep</aId>
            <account>FG</account>
        </item>
    </data>
    

    When the same XSLT verification is run against this document, again the correct element is selected and output:

    <item>
       <aId iskey="true">fep</aId>
       <account>FG</account>
    </item>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a case sensitive SERVER (SQL_Latin1_General_CP1_CS_AS) but the Database is Case insensitive (SQL_Latin1_General_CP1_CI_AS).
I have to compare two strings for case insensitive equality which one is faster
I have been sick and tired Googling the solution for doing case-insensitive search on
Does the map::find method support case insensitive search? I have a map as follows:
How do you have a case insensitive insertion Or search of a string in
I have a varbinary field id like to do a case-insensitive search on. I
DON'T ASK WHY but... I have a regex that needs to be case insensitive
I have basically a username is unique (case insensitive), but the case matters when
My search is case sensitive, but I want it to be case insensitive. In
I have a search function, I want it to be case insensitive, including characters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.