How to use following-sibling:: to compare all nodes

I have a for loop that iterates through all passengers and is supposed to check for duplicates. Currently, I'm using
"following-sibling::Passenger" to obtain info for the next passenger. But what happens is that instead of beginning at IdentityNum=1 it skips that and goes to IdentityNum=2. How can I make the pointer begin at #1 and so on when checking for dups between <NewPassenger> and the 3 existing <Passenger>?


            <NewPassenger>
                  <IdentityNum>3</IdentityNum>
                  <Passenger>
                        <FName>SARAH</FName>
                  </Passenger>
            </NewPassenger>
           <Passenger>
                  <IdentityNum>1</IdentityNum>
                  <PassengerName>
                        <FName>SIM</FName>
                  </PassengerName>
            </Passenger>
            <Passenger>
                  <IdentityNum>2</IdentityNum>
                  <PassengerName>
                        <FName>SOM</FName>
                  </PassengerName>
            </Passenger>
            <Passenger>
                  <IdentityNum>3</IdentityNum>
                  <PassengerName>
                        <FName>SAM</FName>
                  </PassengerName>
            </Passenger>            
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.

Geert BormansInformation ArchitectCommented:
I must see more of your XSLT to form an opinion

"following-sibling::Passenger" is a nodeset that has all three Passenger elements
the comparison is on all three
If you want the first only, you need to be precise
"following-sibling::Passenger[1]"

Also note that the following-sibling axis works on document order.
So if the set is ordered, the might not appear in order as suspected

If you want to exclude that there is a "following-sibling::Passenger" with the same id
do this
NewPassenger[not(IdentityNum = following-sibling::Passenger/IdentityNum)]
0
badtz7229Author Commented:
I have a function that receives a dom and so i end up doing the following

   var nNext = dom.SelectNode(nodeDom,"following-sibling::Passenger");
        for (var i=0; i<nNext.Count; i++)
        {
            var nodeFoll = nNext.GetItem(i).SelectSingle("PassengerName");            
                  //here I have logic to compare the passengers. but the problem is that nNext starts at IdentityNum=2 and not 1.
        }
0
Geert BormansInformation ArchitectCommented:
SelectNode
should be
SelectNodes
no?

try
"./following-sibling::Passenger"
as the XPath

aha, and I believe the '<' in the for, should be '<='
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

badtz7229Author Commented:
Gertone:
i made the changes
var nNext = dom.SelectNodes(nodeDom,"./following-sibling::Passenger");
        for (var i=0; i<=nNext.Count; i++)
        {
            var nodeFoll = nNext.GetItem(i).SelectSingle("PassengerName");            
                  //here I have logic to compare the passengers.
       }


but i still get nNext starting at IdentityNum=2 and not 1.
0
badtz7229Author Commented:
I think
var nNext = dom.SelectNodes(nodeDom,"./following-sibling::Passenger");

is messing it all up. Because I keep starting at next sibling so it will always skip Passenger of IdentityNum=1. How do I get a count of all Passengers so that I may then loop through them to do my comparison?
0
Geert BormansInformation ArchitectCommented:
maybe this
could help
var nNext = dom.SelectNodes(nodeDom,"./parent::*/Passenger");
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:
Gertone:
that worked. can you please explain the syntax of what
"./parent::*/Passenger" is doing ?

0
Geert BormansInformation ArchitectCommented:
great

parent::* goes up one level to the parent
/Passenger, goes down to all Passenger nodes

basiaclly it takes all the Passenger nodes of the parent,
meaning it takes all preceding siblings, all following siblings and the self() if your current context happens to be a Passenger node

I have always assumed your context was NewPassenger
but it seems your context is the first Passenger allready
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
XML

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.