XJS: using xpath to check if element is found when multiple instances of an element

I have following xml
<root>
	<Telephone>
		<ElementNumber>2</ElementNumber>
		<ElementNumber>1</ElementNumber>
		<TelephoneNumber>7865554433</TelephoneNumber>
	</Telephone>
	<Telephone>
	<TelephoneNumber>68021212111</TelephoneNumber>
	</Telephone>
</root>

Open in new window


and following xjs logic:
var nodeTravelerContact = domReq.Root.SelectSingle("Telephone[ElementNumber ='1']/TelephoneNumber | Telephone[not(ElementNumber)]/TelephoneNumber");

if ((!nodeTravelerContact || !nodeTravelerContact.NormalizedText))
	false;
else
	return true;

Open in new window

     
      
I want my function to return true because it found a Telephone where ElementNumber=1 , but my variable returns false because it does not find match (specifically, because it's searching for first position which in this case = 2). I've used .SelectNode, .Select and it never traverses through ALL ElementNumber to find match.

Please advise.
badtz7229Asked:
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.

zc2Commented:
Try
"//Telephone[ElementNumber ='1']/TelephoneNumber | //Telephone[not(ElementNumber)]/TelephoneNumber"
0
leakim971PluritechnicianCommented:
the following worked for me : "Telephone/ElementNumber[text()=1]"

xpath tests
0

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
badtz7229Author Commented:
@zc2
 - that did not work.
0
badtz7229Author Commented:
@leakim971
 - that worked. i'm going to do some more testing, but this is great. thanks.
0
badtz7229Author Commented:
thanks for your help.
0
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
CSS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.