-1

I found the way to make case insensitive for XPATH using translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')

However I would like to make "tag names" case insensitive, not the value.

For example,

<CATALOG>
    <CD title="Empire Burlesque"/>
    <CD title="empire burlesque"/>
    <CD title="EMPIRE BURLESQUE"/>
    <CD title="Others blahblah"/>
    <CD Title="Others blah"/>
</CATALOG>

I would like to find the path //*[contains(@title, "Others") and //*[contains(@Title, "others"], so I would like to make tag names case insensitive.

I'm using nodejs Xpath using XMLDOM, which supports XPATH 1.0

Is there any way to make tag names case insensitive when using contains(@tag name, "value")? Many thanks for your help.

hiyo
  • 133
  • 3
  • 9
  • 1
    XML is designed to use case-sensitive names. Your best bet is to start by doing an XSLT transformation that converts all the names to lower-case, and from then on you can process it in the normal way. – Michael Kay Jan 04 '20 at 10:03
  • Thanks for your reply, @MichaelKay I'll look for the way to do transformation as you said. :) – hiyo Jan 05 '20 at 01:01

1 Answers1

0

The following is ugly, but try this xpath expression and see if it works:

//*/@*[translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='title']

This should output all five CDs.

Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
  • Thank you and yes, I tried, but the key "Others" is missing on the phrase. That example code was simplified example I have. I tried //@*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='title', 'others')] but not worked. – hiyo Jan 05 '20 at 01:04
  • @hiyo - It certainly worked on the xml in your question (as it was before it was edited). – Jack Fleeting Jan 05 '20 at 02:01
  • Thank you for your reply but I only edited this words: "I'm using nodejs Xpath using XMLDOM" as you can see this change log history. I have not edited any codes of example. – hiyo Jan 05 '20 at 06:16
  • @hiyo - You're right, it wasn't your edit, I checked it again, and it was a cut and paste typo on my part - apologies! Looks like I dropped something in the beginning of the expression. See edit. – Jack Fleeting Jan 05 '20 at 16:50