English | česky | Nederlands | Français | Español | По-русски | Deutsch | >> 中文 << | Italiano | Polski ZVON > Tutorials > XPath Tutorial
>> 实例 12 << | 前页 | 后页

descendant (后代)轴包含上下文节点的后代,一个后代是指子节点或者子节点的子节点等等, 因此descendant轴不会包含属性和命名空间节点.
 
/descendant::*
选择文档根元素的所有后代.即所有的元素被选择

     <AAA>
          <BBB>
               <DDD>
                    <CCC>
                         <DDD/>
                         <EEE/>
                    </CCC>
               </DDD>
          </BBB>
          <CCC>
               <DDD>
                    <EEE>
                         <DDD>
                              <FFF/>
                         </DDD>
                    </EEE>
               </DDD>
          </CCC>
     </AAA>
在XLab中打开实例 | 树视图 (JPG)
 
/AAA/BBB/descendant::*
选择/AAA/BBB的所有后代元素

     <AAA>
          <BBB>
               <DDD>
                    <CCC>
                         <DDD/>
                         <EEE/>
                    </CCC>
               </DDD>
          </BBB>
          <CCC>
               <DDD>
                    <EEE>
                         <DDD>
                              <FFF/>
                         </DDD>
                    </EEE>
               </DDD>
          </CCC>
     </AAA>
在XLab中打开实例 | 树视图 (JPG)
 
//CCC/descendant::*
选择在祖先元素中有CCC的所有元素

     <AAA>
          <BBB>
               <DDD>
                    <CCC>
                         <DDD/>
                         <EEE/>
                    </CCC>
               </DDD>
          </BBB>
          <CCC>
               <DDD>
                    <EEE>
                         <DDD>
                              <FFF/>
                         </DDD>
                    </EEE>
               </DDD>
          </CCC>
     </AAA>
在XLab中打开实例 | 树视图 (JPG)
 
//CCC/descendant::DDD
选择所有以CCC为祖先元素的DDD元素

     <AAA>
          <BBB>
               <DDD>
                    <CCC>
                         <DDD/>
                         <EEE/>
                    </CCC>
               </DDD>
          </BBB>
          <CCC>
               <DDD>
                    <EEE>
                         <DDD>
                              <FFF/>
                         </DDD>
                    </EEE>
               </DDD>
          </CCC>
     </AAA>
在XLab中打开实例 | 树视图 (JPG)