Q:

Ancestor/Preceding/Following condition to Xpath

I have the following xml
<ROOT>
<ITC>44</ITC>
<Description></Description>
<Desc_ID></Desc_ID>
<GenCommunity>
    <Community>
        <SubCommunity>
            <CID>6655779999</ID>
        </SubCommunity>
        <CommunityIdGroup>
            <Group>Charly</Group>
        </CommunityIdGroup>
        <CommunitySchool>
            <CID>1143211234</CID>
            <SchoolScheme>
                <ID>DEY</ID>
            </SchoolScheme>
        </CommunitySchool>
        <CommunitySchool>
            <CID>1143211234</CID>
            <SchoolScheme>
                <ID>BSY</ID>
            </SchoolScheme>
        </CommunitySchool>
    </Community>
</GenCommmunity>
</ROOT>

Currently I use this XPath that works perfect:
//Community/CommunitySchool/CID[following-sibling::SchoolScheme/ID = 'DEY']
[text()="1143211234"

But now I need to add a condition to this Xpath to not select if ITC =44 in the beginning of the file.
I tried:
//Community/CommunitySchool/CID[following-sibling::SchoolScheme/ID = 'DEY' and  
ancestor::ITC!='44'][text()="1143211234"

and 
//Community/CommunitySchool/CID[following-sibling::SchoolScheme/ID = 'DEY' and 
not(ancestor::ITC='44')][text()="1143211234"

and many more with no luck.
Any suggestions?

A:

You can use:
/ROOT[not(ITC='44')]//Community/CommunitySchool/CID[following-sibling::SchoolScheme/ID = 'DEY']
[text()="1143211234"]

You can alternatively add a predicate like:
[not(preceding::ITC='44')]

to some node in your existing path. You can't use ancestor:: since ITC is not really an ancestor of Community.

