XPATH Formulas examples  ( XPATHのサンプル )

/AAA
Select the root element AAA

     <AAA>			------------------------- X
          <BBB/>
          <CCC/>
          <BBB/>
          <BBB/>
          <DDD>
               <BBB/>
          </DDD>
          <CCC/>
     </AAA> 		------------------------ X
	 
	 
/AAA/CCC
Select all elements CCC which are children of the root element AAA

     <AAA>
          <BBB/>
          <CCC/>			------------------------ X
          <BBB/>
          <BBB/>
          <DDD>
               <BBB/>
          </DDD>
          <CCC/>			------------------------ X
     </AAA> 
	 
/AAA/DDD/BBB
Select all elements BBB which are children of DDD which are children of the root element AAA

     <AAA>
          <BBB/>
          <CCC/>
          <BBB/>
          <BBB/>
          <DDD>
               <BBB/>		------------------------ X
          </DDD>
          <CCC/>
     </AAA>

//BBB
Select all elements BBB

     <AAA>
          <BBB/>			------------------------ X
          <CCC/>
          <BBB/>			------------------------ X
          <DDD>
               <BBB/>		------------------------ X
          </DDD>
          <CCC>
               <DDD>
                    <BBB/>	------------------------ X
                    <BBB/>	------------------------ X
               </DDD>
          </CCC>
     </AAA> 
	 
//DDD/BBB
Select all elements BBB which are children of DDD

     <AAA>
          <BBB/>
          <CCC/>
          <BBB/>
          <DDD>
               <BBB/>		------------------------ X
          </DDD>
          <CCC>
               <DDD>
                    <BBB/>	------------------------ X
                    <BBB/>	------------------------ X
               </DDD>
          </CCC>
     </AAA>

/AAA/CCC/DDD/*
Select all elements enclosed by elements /AAA/CCC/DDD

     <AAA>
          <XXX>
               <DDD>
                    <BBB/>
                    <BBB/>
                    <EEE/>
                    <FFF/>
               </DDD>
          </XXX>
          <CCC>
               <DDD>
                    <BBB/>	------------------------ X
                    <BBB/>	------------------------ X
                    <EEE/>	------------------------ X
                    <FFF/>	------------------------ X
               </DDD>
          </CCC>
          <CCC>
               <BBB>
                    <BBB>
                         <BBB/>
                    </BBB>
               </BBB>
          </CCC>
     </AAA>

/*/*/*/BBB
Select all elements BBB which have 3 ancestors

     <AAA>
          <XXX>
               <DDD>
                    <BBB/>	------------------------ X
                    <BBB/>	------------------------ X
                    <EEE/>
                    <FFF/>
               </DDD>
          </XXX>
          <CCC>
               <DDD>
                    <BBB/>	------------------------ X
                    <BBB/>	------------------------ X
                    <EEE/>
                    <FFF/>
               </DDD>
          </CCC>
          <CCC>
               <BBB>
                    <BBB>	------------------------ X
                         <BBB/>
                    </BBB>	------------------------ X
               </BBB>
          </CCC>
     </AAA> 
	 
//*
Select all elements

     <AAA>						------------------------ X
          <XXX>					------------------------ X
               <DDD>			------------------------ X
                    <BBB/>		------------------------ X
                    <BBB/>		------------------------ X
                    <EEE/>		------------------------ X
                    <FFF/>		------------------------ X
               </DDD>			------------------------ X
          </XXX>				------------------------ X
          <CCC>					------------------------ X
               <DDD>			------------------------ X
                    <BBB/>		------------------------ X
                    <BBB/>		------------------------ X
                    <EEE/>		------------------------ X
                    <FFF/>		------------------------ X
               </DDD>			------------------------ X
          </CCC>				------------------------ X
          <CCC>					------------------------ X
               <BBB>			------------------------ X
                    <BBB>		------------------------ X
                         <BBB/>	------------------------ X
                    </BBB>		------------------------ X
               </BBB>			------------------------ X
          </CCC>				------------------------ X
     </AAA> 					------------------------ X
	 
/AAA/BBB[1]
Select the first BBB child of element AAA

     <AAA>
          <BBB/>	------------------------ X			
          <BBB/>
          <BBB/>
          <BBB/>
     </AAA> 
	 
/AAA/BBB[last()]
Select the last BBB child of element AAA

     <AAA>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>	------------------------ X	
     </AAA> 
	 
//@id
Select all attributes @id

     <AAA>
          <BBB id = "b1"/>	------------------------ X	
          <BBB id = "b2"/>	------------------------ X	
          <BBB name = "bbb"/>
          <BBB/>
     </AAA>
	 
//BBB[@id]
Select BBB elements which have attribute id

     <AAA>
          <BBB id = "b1"/>	------------------------ X
          <BBB id = "b2"/>	------------------------ X
          <BBB name = "bbb"/>
          <BBB/>
     </AAA> 
	 
//BBB[@name]
Select BBB elements which have attribute name

     <AAA>
          <BBB id = "b1"/>
          <BBB id = "b2"/>
          <BBB name = "bbb"/>	------------------------ X
          <BBB/>
     </AAA> 
	 
//BBB[@*]
Select BBB elements which have any attribute

     <AAA>
          <BBB id = "b1"/>		------------------------ X
          <BBB id = "b2"/>		------------------------ X
          <BBB name = "bbb"/>	------------------------ X
          <BBB/>
     </AAA> 
	 
//BBB[not(@*)]
Select BBB elements without an attribute

     <AAA>
          <BBB id = "b1"/>
          <BBB id = "b2"/>
          <BBB name = "bbb"/>
          <BBB/>				------------------------ X
     </AAA>
	 
//BBB[@id='b1']
Select BBB elements which have attribute id with value b1

     <AAA>
          <BBB id = "b1"/>		------------------------ X
          <BBB name = " bbb "/>
          <BBB name = "bbb"/>
     </AAA> 
	 
//BBB[@name='bbb']
Select BBB elements which have attribute name with value 'bbb'

     <AAA>
          <BBB id = "b1"/>
          <BBB name = " bbb "/>
          <BBB name = "bbb"/>	------------------------ X
     </AAA>

//BBB[normalize-space(@name)='bbb']
Select BBB elements which have attribute name with value bbb, leading and trailing spaces are removed before comparison

     <AAA>
          <BBB id = "b1"/>
          <BBB name = " bbb "/>	------------------------ X
          <BBB name = "bbb"/>	------------------------ X
     </AAA> 
	 
//*[count(BBB)=2]
Select elements which have two children BBB

     <AAA>
          <CCC>
               <BBB/>
               <BBB/>
               <BBB/>
          </CCC>
          <DDD>			------------------------ X
               <BBB/>
               <BBB/>
          </DDD>		------------------------ X
          <EEE>
               <CCC/>
               <DDD/>
          </EEE>
     </AAA> 
	 
//*[count(*)=2]
Select elements which have 2 children

     <AAA>
          <CCC>
               <BBB/>
               <BBB/>
               <BBB/>
          </CCC>
          <DDD>			------------------------ X
               <BBB/>
               <BBB/>
          </DDD>		------------------------ X
          <EEE>			------------------------ X
               <CCC/>
               <DDD/>
          </EEE>		------------------------ X
     </AAA> 
	 
//*[count(*)=3]
Select elements which have 3 children

     <AAA>				------------------------ X
          <CCC>			------------------------ X
               <BBB/>
               <BBB/>
               <BBB/>
          </CCC>		------------------------ X
          <DDD>
               <BBB/>
               <BBB/>
          </DDD>
          <EEE>
               <CCC/>
               <DDD/>
          </EEE>
     </AAA> 			------------------------ X
	 
//*[name()='BBB']
Select all elements with name BBB, equivalent with //BBB

     <AAA>
          <BCC>
               <BBB/>	------------------------ X
               <BBB/>	------------------------ X
               <BBB/>	------------------------ X
          </BCC>
          <DDB>
               <BBB/>	------------------------ X
               <BBB/>	------------------------ X
          </DDB>
          <BEC>
               <CCC/>
               <DBD/>
          </BEC>
     </AAA> 
	 
//*[starts-with(name(),'B')]
Select all elements name of which starts with letter B

     <AAA>
          <BCC>			------------------------ X
               <BBB/>	------------------------ X
               <BBB/>	------------------------ X
               <BBB/>	------------------------ X
          </BCC>		------------------------ X
          <DDB>
               <BBB/>	------------------------ X
               <BBB/>	------------------------ X
          </DDB>
          <BEC>			------------------------ X
               <CCC/>
               <DBD/>
          </BEC>		------------------------ X
     </AAA> 
	 
//*[contains(name(),'C')]
Select all elements name of which contain letter C

     <AAA>
          <BCC>			------------------------ X
               <BBB/>
               <BBB/>
               <BBB/>
          </BCC>		------------------------ X
          <DDB>
               <BBB/>
               <BBB/>
          </DDB>
          <BEC>			------------------------ X
               <CCC/>	------------------------ X
               <DBD/>
          </BEC>		------------------------ X
     </AAA> 
	 
//*[string-length(name()) = 3]
Select elements with three-letter name

     <AAA>				------------------------ X
          <Q/>
          <SSSS/>
          <BB/>
          <CCC/>		------------------------ X
          <DDDDDDDD/>
          <EEEE/>
     </AAA> 			------------------------ X
	 
//*[string-length(name()) < 3]
Select elements name of which has one or two characters

     <AAA>
          <Q/>			------------------------ X
          <SSSS/>
          <BB/>			------------------------ X
          <CCC/>
          <DDDDDDDD/>
          <EEEE/>
     </AAA> 
	 
//*[string-length(name()) > 3]
Select elements with name longer than three characters

     <AAA>
          <Q/>
          <SSSS/>		------------------------ X
          <BB/>
          <CCC/>
          <DDDDDDDD/>	------------------------ X
          <EEEE/>		------------------------ X
     </AAA> 
	 
//CCC | //BBB
Select all elements CCC and BBB

     <AAA>
          <BBB/>		------------------------ X
          <CCC/>		------------------------ X
          <DDD>
               <CCC/>	------------------------ X
          </DDD>
          <EEE/>
     </AAA> 
	 
/AAA/EEE | //BBB
Select all elements BBB and elements EEE which are children of root element AAA

     <AAA>
          <BBB/>		------------------------ X
          <CCC/>
          <DDD>
               <CCC/>
          </DDD>
          <EEE/>		------------------------ X
     </AAA> 
	 
/AAA/EEE | //DDD/CCC | /AAA | //BBB
Number of combinations is not restricted

     <AAA>				------------------------ X
          <BBB/>		------------------------ X
          <CCC/>		
          <DDD>
               <CCC/>	------------------------ X
          </DDD>
          <EEE/>		------------------------ X
     </AAA>				------------------------ X
	 
/AAA
Equivalent of /child::AAA

     <AAA>				------------------------ X
          <BBB/>
          <CCC/>
     </AAA>				------------------------ X
	 
/child::AAA
Equivalent of /AAA

     <AAA>				------------------------ X
          <BBB/>
          <CCC/>
     </AAA> 			------------------------ X
	 
/AAA/BBB
Equivalent of /child::AAA/child::BBB

     <AAA>
          <BBB/>		------------------------ X
          <CCC/>
     </AAA> 
	 
/child::AAA/child::BBB
Equivalent of /AAA/BBB

     <AAA>
          <BBB/>		------------------------ X
          <CCC/>
     </AAA> 

/child::AAA/BBB
Both possibilities can be combined

     <AAA>
          <BBB/>		------------------------ X
          <CCC/>
     </AAA>
	 
/descendant::*
Select all descendants of document root and therefore all elements

     <AAA>									------------------------ X
          <BBB>								------------------------ X
               <DDD>						------------------------ X
                    <CCC>					------------------------ X
                         <DDD/>				------------------------ X
                         <EEE/>				------------------------ X
                    </CCC>					------------------------ X
               </DDD>						------------------------ X
          </BBB>							------------------------ X
          <CCC>								------------------------ X
               <DDD>						------------------------ X
                    <EEE>					------------------------ X
                         <DDD>				------------------------ X
                              <FFF/>		------------------------ X
                         </DDD>				------------------------ X
                    </EEE>					------------------------ X
               </DDD>						------------------------ X
          </CCC>							------------------------ X
     </AAA> 								------------------------ X
	 
/AAA/BBB/descendant::*
Select all descendants of /AAA/BBB

     <AAA>
          <BBB>
               <DDD>						------------------------ X
                    <CCC>					------------------------ X
                         <DDD/>				------------------------ X
                         <EEE/>				------------------------ X
                    </CCC>					------------------------ X
               </DDD>						------------------------ X
          </BBB>
          <CCC>
               <DDD>
                    <EEE>
                         <DDD>
                              <FFF/>
                         </DDD>
                    </EEE>
               </DDD>
          </CCC>
     </AAA> 

//CCC/descendant::*
Select all elements which have CCC among its ancestors

     <AAA>
          <BBB>
               <DDD>
                    <CCC>
                         <DDD/>			------------------------ X
                         <EEE/>			------------------------ X
                    </CCC>
               </DDD>
          </BBB>
          <CCC>
               <DDD>					------------------------ X
                    <EEE>				------------------------ X
                         <DDD>			------------------------ X
                              <FFF/>	------------------------ X
                         </DDD>			------------------------ X
                    </EEE>				------------------------ X
               </DDD>					------------------------ X
          </CCC>
     </AAA> 
	 
//CCC/descendant::DDD
Select elements DDD which have CCC among its ancestors

     <AAA>
          <BBB>
               <DDD>
                    <CCC>
                         <DDD/>			------------------------ X
                         <EEE/>
                    </CCC>
               </DDD>
          </BBB>
          <CCC>
               <DDD>					------------------------ X
                    <EEE>
                         <DDD>			------------------------ X
                              <FFF/>
                         </DDD>			------------------------ X
                    </EEE>	
               </DDD>					------------------------ X
          </CCC>
     </AAA> 
	 
//DDD/parent::*
Select all parents of DDD element

     <AAA>
          <BBB>							------------------------ X
               <DDD>
                    <CCC>				------------------------ X
                         <DDD/>
                         <EEE/>
                    </CCC>				------------------------ X
               </DDD>
          </BBB>						------------------------ X
          <CCC>							------------------------ X
               <DDD>
                    <EEE>				------------------------ X
                         <DDD>
                              <FFF/>
                         </DDD>			
                    </EEE>				------------------------ X
               </DDD>
          </CCC>						------------------------ X
     </AAA> 
	 
/AAA/BBB/DDD/CCC/EEE/ancestor::*
Select all elements given in this absolute path

     <AAA>								------------------------ X
          <BBB>							------------------------ X
               <DDD>					------------------------ X
                    <CCC>				------------------------ X	
                         <DDD/>
                         <EEE/>
                    </CCC>				------------------------ X
               </DDD>					------------------------ X
          </BBB>						------------------------ X
          <CCC>
               <DDD>
                    <EEE>
                         <DDD>
                              <FFF/>
                         </DDD>
                    </EEE>
               </DDD>
          </CCC>
     </AAA> 							------------------------ X
	 
//FFF/ancestor::*
Select ancestors of FFF element

     <AAA>								------------------------ X
          <BBB>
               <DDD>
                    <CCC>
                         <DDD/>
                         <EEE/>
                    </CCC>
               </DDD>
          </BBB>
          <CCC>							------------------------ X
               <DDD>					------------------------ X
                    <EEE>				------------------------ X
                         <DDD>			------------------------ X
                              <FFF/>
                         </DDD>			------------------------ X
                    </EEE>				------------------------ X
               </DDD>					------------------------ X
          </CCC>						------------------------ X
     </AAA> 							------------------------ X
	 
/AAA/BBB/following-sibling::*

     <AAA>
          <BBB>
               <CCC/>
               <DDD/>
          </BBB>
          <XXX>							------------------------ X
               <DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>						------------------------ X
          <CCC>							------------------------ X
               <DDD/>
          </CCC>						------------------------ X
     </AAA> 
	 
//CCC/following-sibling::*

     <AAA>
          <BBB>
               <CCC/>
               <DDD/>					------------------------ X
          </BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>				------------------------ X
                    <FFF>				------------------------ X
                         <GGG/>
                    </FFF>				------------------------ X
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA> 
	 
/AAA/XXX/preceding-sibling::*

     <AAA>
          <BBB>							------------------------ X
               <CCC/>
               <DDD/>
          </BBB>						------------------------ X
          <XXX>
               <DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA> 
	 
//CCC/preceding-sibling::*

     <AAA>
          <BBB>							------------------------ X
               <CCC/>
               <DDD/>
          </BBB>						------------------------ X
          <XXX>							------------------------ X
               <DDD>
                    <EEE/>				------------------------ X
                    <DDD/>				------------------------ X
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>						------------------------ X
          <CCC>
               <DDD/>
          </CCC>
     </AAA>
	 
/AAA/XXX/following::*

     <AAA>
          <BBB>
               <CCC/>
               <ZZZ>
                    <DDD/>
                    <DDD>
                         <EEE/>
                    </DDD>
               </ZZZ>
               <FFF>
                    <GGG/>
               </FFF>
          </BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>						------------------------ X
               <DDD/>				------------------------ X
          </CCC>					------------------------ X
     </AAA> 
	 
//ZZZ/following::*

     <AAA>
          <BBB>
               <CCC/>
               <ZZZ>
                    <DDD/>
                    <DDD>
                         <EEE/>
                    </DDD>
               </ZZZ>
               <FFF>				------------------------ X
                    <GGG/>			------------------------ X
               </FFF>				------------------------ X
          </BBB>
          <XXX>						------------------------ X
               <DDD>				------------------------ X
                    <EEE/>			------------------------ X
                    <DDD/>			------------------------ X
                    <CCC/>			------------------------ X
                    <FFF/>			------------------------ X
                    <FFF>			------------------------ X
                         <GGG/>		------------------------ X
                    </FFF>			------------------------ X
               </DDD>				------------------------ X
          </XXX>					------------------------ X
          <CCC>						------------------------ X
               <DDD/>				------------------------ X
          </CCC>					------------------------ X
     </AAA> 
	 
/AAA/XXX/preceding::*

     <AAA>
          <BBB>						------------------------ X
               <CCC/>				------------------------ X
               <ZZZ>				------------------------ X
                    <DDD/>			------------------------ X
               </ZZZ>				------------------------ X
          </BBB>					------------------------ X
          <XXX>
               <DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA> 
	 
//GGG/preceding::*

     <AAA>
          <BBB>						------------------------ X
               <CCC/>				------------------------ X
               <ZZZ>				------------------------ X
                    <DDD/>			------------------------ X
               </ZZZ>				------------------------ X
          </BBB>					------------------------ X
          <XXX>
               <DDD>
                    <EEE/>			------------------------ X
                    <DDD/>			------------------------ X
                    <CCC/>			------------------------ X
                    <FFF/>			------------------------ X
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA>
	 
/AAA/XXX/descendant-or-self::*

     <AAA>
          <BBB>
               <CCC/>
               <ZZZ>
                    <DDD/>
               </ZZZ>
          </BBB>
          <XXX>						------------------------ X
               <DDD>				------------------------ X
                    <EEE/>			------------------------ X
                    <DDD/>			------------------------ X
                    <CCC/>			------------------------ X
                    <FFF/>			------------------------ X
                    <FFF>			------------------------ X
                         <GGG/>		------------------------ X
                    </FFF>			------------------------ X
               </DDD>				------------------------ X
          </XXX>					------------------------ X
          <CCC>
               <DDD/>
          </CCC>
     </AAA> 
	 
//CCC/descendant-or-self::*

     <AAA>
          <BBB>
               <CCC/>				------------------------ X
               <ZZZ>
                    <DDD/>
               </ZZZ>
          </BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>			------------------------ X
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>						------------------------ X
               <DDD/>				------------------------ X
          </CCC>					------------------------ X
     </AAA>
	 
/AAA/XXX/DDD/EEE/ancestor-or-self::*

     <AAA>							------------------------ X
          <BBB>
               <CCC/>
               <ZZZ>
                    <DDD/>
               </ZZZ>
          </BBB>
          <XXX>						------------------------ X
               <DDD>				------------------------ X
                    <EEE/>			------------------------ X
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>				------------------------ X
          </XXX>					------------------------ X
          <CCC>
               <DDD/>
          </CCC>
     </AAA> 						------------------------ X
	 
//GGG/ancestor-or-self::*

     <AAA>							------------------------ X
          <BBB>
               <CCC/>
               <ZZZ>
                    <DDD/>
               </ZZZ>
          </BBB>
          <XXX>						------------------------ X
               <DDD>				------------------------ X
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>			------------------------ X
                         <GGG/>		------------------------ X
                    </FFF>			------------------------ X
               </DDD>				------------------------ X
          </XXX>					------------------------ X
          <CCC>
               <DDD/>
          </CCC>
     </AAA>							------------------------ X
	 
//GGG/ancestor::*

     <AAA>										------------------------ X
          <BBB>
               <CCC/>
               <ZZZ/>
          </BBB>
          <XXX>									------------------------ X
               <DDD>							------------------------ X
                    <EEE/>
                    <FFF>						------------------------ X
                         <HHH/>
                         <GGG>
                              <JJJ>
                                   <QQQ/>
                              </JJJ>
                              <JJJ/>
                         </GGG>
                         <HHH/>
                    </FFF>						------------------------ X
               </DDD>							------------------------ X
          </XXX>								------------------------ X
          <CCC>
               <DDD/>
          </CCC>
     </AAA> 									------------------------ X
	 
//GGG/descendant::*

     <AAA>
          <BBB>
               <CCC/>
               <ZZZ/>
          </BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <FFF>
                         <HHH/>
                         <GGG>
                              <JJJ>				------------------------ X
                                   <QQQ/>		------------------------ X	
                              </JJJ>			------------------------ X
                              <JJJ/>			------------------------ X
                         </GGG>
                         <HHH/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA>
	 
//GGG/following::*

     <AAA>
          <BBB>
               <CCC/>
               <ZZZ/>
          </BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <FFF>
                         <HHH/>
                         <GGG>
                              <JJJ>
                                   <QQQ/>
                              </JJJ>
                              <JJJ/>
                         </GGG>
                         <HHH/>				------------------------ X
                    </FFF>
               </DDD>
          </XXX>
          <CCC>								------------------------ X
               <DDD/>						------------------------ X
          </CCC>							------------------------ X
     </AAA> 
	 
//GGG/preceding::*

     <AAA>
          <BBB>								------------------------ X
               <CCC/>						------------------------ X
               <ZZZ/>						------------------------ X
          </BBB>							------------------------ X
          <XXX>
               <DDD>
                    <EEE/>					------------------------ X
                    <FFF>
                         <HHH/>				------------------------ X
                         <GGG>
                              <JJJ>
                                   <QQQ/>
                              </JJJ>
                              <JJJ/>
                         </GGG>
                         <HHH/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA> 
	 
//GGG/self::*

     <AAA>
          <BBB>
               <CCC/>
               <ZZZ/>
          </BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <FFF>
                         <HHH/>
                         <GGG>				------------------------ X
                              <JJJ>
                                   <QQQ/>
                              </JJJ>
                              <JJJ/>
                         </GGG>				------------------------ X
                         <HHH/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA> 
	 
//GGG/ancestor::* | //GGG/descendant::* | //GGG/following::* | //GGG/preceding::* | //GGG/self::*

     <AAA>											------------------------ X
          <BBB>										------------------------ X
               <CCC/>								------------------------ X
               <ZZZ/>								------------------------ X
          </BBB>									------------------------ X
          <XXX>										------------------------ X
               <DDD>								------------------------ X
                    <EEE/>							------------------------ X
                    <FFF>							------------------------ X
                         <HHH/>						------------------------ X
                         <GGG>						------------------------ X
                              <JJJ>					------------------------ X
                                   <QQQ/>			------------------------ X
                              </JJJ>				------------------------ X
                              <JJJ/>				------------------------ X
                         </GGG>						------------------------ X
                         <HHH/>						------------------------ X
                    </FFF>							------------------------ X
               </DDD>								------------------------ X
          </XXX>									------------------------ X
          <CCC>										------------------------ X	
               <DDD/>								------------------------ X
          </CCC>									------------------------ X
     </AAA> 										------------------------ X
	 
//BBB[position() mod 2 = 0 ]
Select even BBB elements

     <AAA>
          <BBB/>
          <BBB/>		------------------------ X									
          <BBB/>
          <BBB/>		------------------------ X
          <BBB/>
          <BBB/>		------------------------ X
          <BBB/>
          <BBB/>		------------------------ X
          <CCC/>
          <CCC/>
          <CCC/>
     </AAA>
	 
//BBB[ position() = floor(last() div 2 + 0.5) or position() = ceiling(last() div 2 + 0.5) ]
Select middle BBB element(s)

     <AAA>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>		------------------------ X	
          <BBB/>		------------------------ X	
          <BBB/>
          <BBB/>
          <BBB/>
          <CCC/>
          <CCC/>
          <CCC/>
     </AAA> 
	 
//CCC[ position() = floor(last() div 2 + 0.5) or position() = ceiling(last() div 2 + 0.5) ]
Select middle CCC element(s)

     <AAA>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <CCC/>
          <CCC/>		------------------------ X	
          <CCC/>
     </AAA>