XPath: How to find node contaning substring of value?

I am new to XML and I would appreciate any help. I need to find all XML nodes which have value which includes given substring. For example:
<name> abcd </name>
<name> cdfg </name>
<name> cbcs </name>
I will need to get list of nodes contaning substring "bc" (first and third nodes). I know how to search xml to match entire value string. But what should I do to match substring of value string?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

i' assuming you have xml like this, for instance:

<?xml version="1.0" encoding="UTF-8"?>
      <name> abcd </name>
      <name> cdfg </name>
      <name> cbcs </name>

so, xslt to get  what you want:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <xsl:for-each select="/root/name[contains(.,'bc')]">
                <xsl:copy-of select="." />

will produce:
<name> abcd </name>
<name> cbcs </name>
, or if you don't use xslt, just use following XPath:


to get nodes with substring 'bc'
gelbertAuthor Commented:
Thanks  dualsoul, but I forgot to mention that I need XPath, not XSLT
> Thanks  dualsoul, but I forgot to mention that I need XPath, not XSLT
you read inattentive :)
i wrote:
  if you don't use xslt, just use following XPath:  /root/name[contains(.,'bc')]  
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

But, if you're using MSXML, first make sure you tell the DOM document object that you're using XPath (it defaults to XSL Patterns):

var xmlDoc = new ActiveXObject("Msxml2.DomDocument");
xmlDoc.setProperty("SelectionLanguage", "XPath");

var oNodeList = xmlDoc.selectNodes("/root/name[contains(.,'bc')]")

Mike Sharp
gelbertAuthor Commented:
Thanks guys
ok, if you haven't more questions, please close the question.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.