XPath最通俗的教程--看了,真的不错

转载 2006年06月01日 00:50:00

XPath最通俗的教程(ZZ)

  以下是本人找到的最完整最易懂的XPath教程,不敢私藏,拿出来与大家分享。帮我点旁边的google广告呀。

实例 1
基本的XPath语法类似于在一个文件系统中定位文件,如果路径以斜线 / 开始, 那么该路径就表示到一个元素的绝对路径

/AAA

选择根元素AAA


     <
AAA>
          <BBB/>
          <CCC/>
          <BBB/>
          <BBB/>
          <DDD>
               <BBB/>
          </DDD>
          <CCC/>
     </
AAA>

 

/AAA/CCC

选择AAA的所有CCC子元素


     <AAA>
          <BBB/>
          <
CCC/>
          <BBB/>
          <BBB/>
          <DDD>
               <BBB/>
          </DDD>
          <
CCC/>
     </AAA>

 

/AAA/DDD/BBB

选择AAA的子元素DDD的所有子元素


     <AAA>
          <BBB/>
          <CCC/>
          <BBB/>
          <BBB/>
          <DDD>
               <
BBB/>
          </DDD>
          <CCC/>
     </AAA>

 

 

实例 2

如果路径以双斜线 // 开头, 则表示选择文档中所有满足双斜线//之后规则的元素(无论层级关系)

 

//BBB

选择所有BBB元素


     <AAA>
          <
BBB/>
          <CCC/>
          <
BBB/>
          <DDD>
               <
BBB/>
          </DDD>
          <CCC>
               <DDD>
                    <
BBB/>
                    <
BBB/>
               </DDD>
          </CCC>
     </AAA>

 

//DDD/BBB

选择所有父元素是DDDBBB元素


     <AAA>
          <BBB/>
          <CCC/>
          <BBB/>
          <DDD>
               <
BBB/>
          </DDD>
          <CCC>
               <DDD>
                    <
BBB/>
                    <
BBB/>
               </DDD>
          </CCC>
     </AAA>

 

 

实例 3

星号 * 表示选择所有由星号之前的路径所定位的元素

 

/AAA/CCC/DDD/*

选择所有路径依附于/AAA/CCC/DDD的元素


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

 

/*/*/*/BBB

选择所有的有3个祖先元素的BBB元素


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

 

//*

选择所有元素


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

 

 

 

实例 4

方块号里的表达式可以进一步的指定元素, 其中数字表示元素在选择集里的位置, last()函数则表示选择集中的最后一个元素.

 

/AAA/BBB[1]

选择AAA的第一个BBB子元素


     <AAA>
          <
BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
     </AAA>

 

/AAA/BBB[last()]

选择AAA的最后一个BBB子元素


     <AAA>
          <BBB/>
          <BBB/>
          <BBB/>
          <
BBB/>
     </AAA>

 

 

 

实例 5

//@id

选择所有的id属性


     <AAA>
          <BBB
id = "b1"/>
          <BBB
id = "b2"/>
          <BBB name = "bbb"/>
          <BBB/>
     </AAA>

 

//BBB[@id]

选择有id属性的BBB元素


     <AAA>
          <
BBB id = "b1"/>
          <
BBB id = "b2"/>
          <BBB name = "bbb"/>
          <BBB/>
     </AAA>

 

//BBB[@name]

选择有name属性的BBB元素


     <AAA>
          <BBB id = "b1"/>
          <BBB id = "b2"/>
          <
BBB name = "bbb"/>
          <BBB/>
     </AAA>

 

//BBB[@*]

选择有任意属性的BBB元素


     <AAA>
          <
BBB id = "b1"/>
          <
BBB id = "b2"/>
          <
BBB name = "bbb"/>
          <BBB/>
     </AAA>

 

//BBB[not(@*)]

选择没有属性的BBB元素


     <AAA>
          <BBB id = "b1"/>
          <BBB id = "b2"/>
          <BBB name = "bbb"/>
          <
BBB/>
     </AAA>

 

 

 

实例 6

属性的值可以被用来作为选择的准则, normalize-space函数删除了前部和尾部的空格, 并且把连续的空格串替换为一个单一的空格

 

//BBB[@id='b1']

选择含有属性id且其值为'b1'BBB元素


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

 

//BBB[@name='bbb']

选择含有属性name且其值为'bbb'BBB元素


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

 

//BBB[normalize-space(@name)='bbb']

选择含有属性name且其值(在用normalize-space函数去掉前后空格后)'bbb'BBB元素


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

 

 

 

实例 7

count()函数可以计数所选元素的个数

 

//*[count(BBB)=2]

选择含有2BBB子元素的元素


     <AAA>
          <CCC>
               <BBB/>
               <BBB/>
               <BBB/>
          </CCC>
          <
DDD>
               <BBB/>
               <BBB/>
          </
DDD>
          <EEE>
               <CCC/>
               <DDD/>
          </EEE>
     </AAA>

 

//*[count(*)=2]

选择含有2个子元素的元素


     <AAA>
          <CCC>
               <BBB/>
               <BBB/>
               <BBB/>
          </CCC>
          <
DDD>
               <BBB/>
               <BBB/>
          </
DDD>
          <
EEE>
               <CCC/>
               <DDD/>
          </
EEE>
     </AAA>

 

//*[count(*)=3]

选择含有3个子元素的元素


     <
AAA>
          <
CCC>
               <BBB/>
               <BBB/>
               <BBB/>
          </
CCC>
          <DDD>
               <BBB/>
               <BBB/>
          </DDD>
          <EEE>
               <CCC/>
               <DDD/>
          </EEE>
     </
AAA>

 

 

 

实例 8

name()函数返回元素的名称, start-with()函数在该函数的第一个参数字符串是以第二个参数字符开始的情况返回true, contains()函数当其第一个字符串参数包含有第二个字符串参数时返回true.

 

//*[name()='BBB']

选择所有名称为BBB的元素(这里等价于//BBB)


     <AAA>
          <BCC>
               <
BBB/>
               <
BBB/>
               <
BBB/>
          </BCC>
          <DDB>
               <
BBB/>
               <
BBB/>
          </DDB>
          <BEC>
               <CCC/>
               <DBD/>
          </BEC>
     </AAA>

 

//*[starts-with(name(),'B')]

选择所有名称以"B"起始的元素


     <AAA>
          <
BCC>
               <
BBB/>
               <
BBB/>
               <
BBB/>
          </
BCC>
          <DDB>
               <
BBB/>
               <
BBB/>
          </DDB>
          <
BEC>
               <CCC/>
               <DBD/>
          </
BEC>
     </AAA>

 

//*[contains(name(),'C')]

选择所有名称包含"C"的元素


     <AAA>
          <
BCC>
               <BBB/>
               <BBB/>
               <BBB/>
          </
BCC>
          <DDB>
               <BBB/>
               <BBB/>
          </DDB>
          <
BEC>
               <
CCC/>
               <DBD/>
          </
BEC>
     </AAA>

 

 

 

实例 10

多个路径可以用分隔符 | 合并在一起

 

//CCC | //BBB

选择所有的CCCBBB元素


     <AAA>
          <
BBB/>
          <
CCC/>
          <DDD>
               <
CCC/>
          </DDD>
          <EEE/>
     </AAA>

 

/AAA/EEE | //BBB

选择所有的BBB元素和所有是AAA的子元素的EEE元素


     <AAA>
          <
BBB/>
          <CCC/>
          <DDD>
               <CCC/>
          </DDD>
          <
EEE/>
     </AAA>

 

/AAA/EEE | //DDD/CCC | /AAA | //BBB

可以合并的路径数目没有限制


     <
AAA>
          <
BBB/>
          <CCC/>
          <DDD>
               <
CCC/>
          </DDD>
          <
EEE/>
     </
AAA>

 

 

 

实例 11

child(axis)包含上下文节点的子元素, 作为默认的轴,可以忽略不写.

 

/AAA

等价于 /child::AAA


     <
AAA>
          <BBB/>
          <CCC/>
     </
AAA>

 

/child::AAA

等价于/AAA


     <
AAA>
          <BBB/>
          <CCC/>
     </
AAA>

 

/AAA/BBB

等价于/child::AAA/child::BBB


     <AAA>
          <
BBB/>
          <CCC/>
     </AAA>

 

/child::AAA/child::BBB

等价于/AAA/BBB


     <AAA>
          <
BBB/>
          <CCC/>
     </AAA>

 

/child::AAA/BBB

二者都可以被合并


     <AAA>
          <
BBB/>
          <CCC/>
     </AAA>

 

 

 

 

实例 12

descendant (后代)轴包含上下文节点的后代,一个后代是指子节点或者子节点的子节点等等, 因此descendant轴不会包含属性和命名空间节点.

 

/descendant::*

选择文档根元素的所有后代.即所有的元素被选择


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

 

/AAA/BBB/descendant::*

选择/AAA/BBB的所有后代元素


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

 

//CCC/descendant::*

选择在祖先元素中有CCC的所有元素


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

 

//CCC/descendant::DDD

选择所有以CCC为祖先元素的DDD元素


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

 

 

 

 

实例 13

parent(axis)包含上下文节点的父节点, 如果有父节点的话

 

//DDD/parent::*

选择DDD元素的所有父节点


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

 

 

 

 

实例 14

ancestor(axis)包含上下节点的祖先节点, 该祖先节点由其上下文节点的父节点以及父节点的父节点等等诸如此类的节点构成,所以ancestor轴总是包含有根节点,除非上下文节点就是根节点本身.

 

/AAA/BBB/DDD/CCC/EEE/ancestor::*

选择一个绝对路径上的所有节点


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

 

//FFF/ancestor::*

选择FFF元素的祖先节点


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

 

 

 

 

实例 15

following-sibling(axis)包含上下文节点之后的所有兄弟节点

 

/AAA/BBB/following-sibling::*

 


     <AAA>
          <BBB>
               <CCC/>
               <DDD/>
          </BBB>
          <
XXX>
               <DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </
XXX>
          <
CCC>
               <DDD/>
          </
CCC>
     </AAA>

 

//CCC/following-sibling::*

 


     <AAA>
          <BBB>
               <CCC/>
               <
DDD/>
          </BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <
FFF/>
                    <
FFF>
                         <GGG/>
                    </
FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA>

 

 

 

 

实例 16

preceding-sibling (axis)包含上下文节点之前的所有兄弟节点

 

/AAA/XXX/preceding-sibling::*

 


     <AAA>
          <
BBB>
               <CCC/>
               <DDD/>
          </
BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA>

 

//CCC/preceding-sibling::*

 


     <AAA>
          <
BBB>
               <CCC/>
               <DDD/>
          </
BBB>
          <
XXX>
               <DDD>
                    <
EEE/>
                    <
DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </
XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA>

 

 

 

 

实例 17

following(axis)包含同一文档中按文档顺序位于上下文节点之后的所有节点, 除了祖先节点,属性节点和命名空间节点

 

/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>
               <
DDD/>
          </
CCC>
     </AAA>

 

//ZZZ/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>
               <
DDD/>
          </
CCC>
     </AAA>

 

 

 

 

实例 18

preceding(axis)包含同一文档中按文档顺序位于上下文节点之前的所有节点, 除了祖先节点,属性节点和命名空间节点

 

/AAA/XXX/preceding::*

 


     <AAA>
          <
BBB>
               <
CCC/>
               <
ZZZ>
                    <
DDD/>
               </
ZZZ>
          </
BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA>

 

//GGG/preceding::*

 


     <AAA>
          <
BBB>
               <
CCC/>
               <
ZZZ>
                    <
DDD/>
               </
ZZZ>
          </
BBB>
          <XXX>
               <DDD>
                    <
EEE/>
                    <
DDD/>
                    <
CCC/>
                    <
FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA>

 

 

 

 

实例 19

descendant-or-self (axis)包含上下文节点本身和该节点的后代节点

 

/AAA/XXX/descendant-or-self::*

 


     <AAA>
          <BBB>
               <CCC/>
               <ZZZ>
                    <DDD/>
               </ZZZ>
          </BBB>
          <
XXX>
               <
DDD>
                    <
EEE/>
                    <
DDD/>
                    <
CCC/>
                    <
FFF/>
                    <
FFF>
                         <
GGG/>
                    </
FFF>
               </
DDD>
          </
XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA>

 

//CCC/descendant-or-self::*

 


     <AAA>
          <BBB>
               <
CCC/>
               <ZZZ>
                    <DDD/>
               </ZZZ>
          </BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <DDD/>
                    <
CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </DDD>
          </XXX>
          <
CCC>
               <
DDD/>
          </
CCC>
     </AAA>

 

 

 

 

实例 20

ancestor-or-self (axis)包含上下文节点本身和该节点的祖先节点

 

/AAA/XXX/DDD/EEE/ancestor-or-self::*

 


     <
AAA>
          <BBB>
               <CCC/>
               <ZZZ>
                    <DDD/>
               </ZZZ>
          </BBB>
          <
XXX>
               <
DDD>
                    <
EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <FFF>
                         <GGG/>
                    </FFF>
               </
DDD>
          </
XXX>
          <CCC>
               <DDD/>
          </CCC>
     </
AAA>

 

//GGG/ancestor-or-self::*

 


     <
AAA>
          <BBB>
               <CCC/>
               <ZZZ>
                    <DDD/>
               </ZZZ>
          </BBB>
          <
XXX>
               <
DDD>
                    <EEE/>
                    <DDD/>
                    <CCC/>
                    <FFF/>
                    <
FFF>
                         <
GGG/>
                    </
FFF>
               </
DDD>
          </
XXX>
          <CCC>
               <DDD/>
          </CCC>
     </
AAA>

 

 

 

 

实例 21

ancestor, descendant, following, preceding self(axis)分割了XML文档(忽略属性节点和命名空间节点), 不能交迭, 而一起使用则包含所有节点

 

//GGG/ancestor::*

 


     <
AAA>
          <BBB>
               <CCC/>
               <ZZZ/>
          </BBB>
          <
XXX>
               <
DDD>
                    <EEE/>
                    <
FFF>
                         <HHH/>
                         <GGG>
                              <JJJ>
                                   <QQQ/>
                              </JJJ>
                              <JJJ/>
                         </GGG>
                         <HHH/>
                    </
FFF>
               </
DDD>
          </
XXX>
          <CCC>
               <DDD/>
          </CCC>
     </
AAA>

 

//GGG/descendant::*

 


     <AAA>
          <BBB>
               <CCC/>
               <ZZZ/>
          </BBB>
          <XXX>
               <DDD>
                    <EEE/>
                    <FFF>
                         <HHH/>
                         <GGG>
                              <
JJJ>
                                   <
QQQ/>
                              </
JJJ>
                              <
JJJ/>
                         </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/>
                    </FFF>
               </DDD>
          </XXX>
          <
CCC>
               <
DDD/>
          </
CCC>
     </AAA>

 

//GGG/preceding::*

 


     <AAA>
          <
BBB>
               <
CCC/>
               <
ZZZ/>
          </
BBB>
          <XXX>
               <DDD>
                    <
EEE/>
                    <FFF>
                         <
HHH/>
                         <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>
                              <JJJ>
                                   <QQQ/>
                              </JJJ>
                              <JJJ/>
                         </
GGG>
                         <HHH/>
                    </FFF>
               </DDD>
          </XXX>
          <CCC>
               <DDD/>
          </CCC>
     </AAA>

 

//GGG/ancestor::* | //GGG/descendant::* | //GGG/following::* | //GGG/preceding::* | //GGG/self::*

 


     <
AAA>
          <
BBB>
               <
CCC/>
               <
ZZZ/>
          </
BBB>
          <
XXX>
               <
DDD>
                    <
EEE/>
                    <
FFF>
                         <
HHH/>
                         <
GGG>
                              <
JJJ>
                                   <
QQQ/>
                              </
JJJ>
                              <
JJJ/>
                         </
GGG>
                         <
HHH/>
                    </
FFF>
               </
DDD>
          </
XXX>
          <
CCC>
               <
DDD/>
          </
CCC>
     </
AAA>

 

 

 

 

实例 22

div运算符做浮点除法运算, mod运算符做求余运算, floor函数返回不大于参数的最大整数(趋近于正无穷), ceiling返回不小于参数的最小整数(趋近于负无穷)

 

//BBB[position() mod 2 = 0 ]

选择偶数位置的BBB元素


     <AAA>
          <BBB/>
          <
BBB/>
          <BBB/>
          <
BBB/>
          <BBB/>
          <
BBB/>
          <BBB/>
          <
BBB/>
          <CCC/>
          <CCC/>
          <CCC/>
     </AAA>

 

//BBB[ position() = floor(last() div 2 + 0.5) or position() = ceiling(last() div 2 + 0.5) ]

选择中间的BBB元素


     <AAA>
          <BBB/>
          <BBB/>
          <BBB/>
          <
BBB/>
          <
BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <CCC/>
          <CCC/>
          <CCC/>
     </AAA>

 

//CCC[ position() = floor(last() div 2 + 0.5) or position() = ceiling(last() div 2 + 0.5) ]

选择中间的CCC元素


     <AAA>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <BBB/>
          <CCC/>
          <
CCC/>
          <CCC/>
     </AAA>

相关文章推荐

XPATH 通俗教程

  • 2008年09月11日 20:44
  • 181KB
  • 下载

正则表达式30分钟入门教程 - 这篇文章写的真不错,我看了一下午,以为我的智商不够。。在结尾看到作者说到30分钟是骗人的~在标题里写出来,只是想提醒读者

正则表达式30分钟入门教程 版本:v2.33 (2013-1-10) 作者:deerchao 转载请注明来源 目录 跳过目录 本文目标如何使用本教程正则表达式到底是什么东西?入...

XPath最通俗的教程

实例 1基本的XPath语法类似于在一个文件系统中定位文件,如果路径以斜线 / 开始, 那么该路径就表示到一个元素的绝对路径/AAA选择根元素AAA     AAA>           BBB/> ...

看了一个博客觉得不错

一.对新生事物要有一颗好奇心和“我一定行的”信心。这点很重要,如果有好奇心和信心,才有动力,看到别人的博客做得漂亮,就认为是专业人士所做,是一种错误的看法,我可以肯定漂亮的博客大多数是博友工作之余,利...
  • wjp2417
  • wjp2417
  • 2011年10月31日 09:42
  • 136

Rest API开发 看了这么多久这篇文章写得不错 转载的

本文我们将使用Spring MVC 4实现 CRUD Restful WebService , 通过RestTemplate写一个 REST 客户端,定义这些服务. 我们也可以通过外部的一些客户端来测...
  • scmrpu
  • scmrpu
  • 2016年07月07日 15:25
  • 2027

看了下分析的不错,就记了下来

ARM中C和汇编混合编程及示例     在嵌入式系统开发中,目前使用的主要编程语言是C和汇编,C++已经有相应的编译器,但是现在使用还是比较少的。在稍大规模的嵌入式软件中,例如含有OS,大...

为什么你总成为不了架构师?看了下 觉得确实不错

, 为什么你总成为不了架构师?   背景: 今天接到一个哥们儿的电话,说,很郁闷,想和我聊聊。 我问,有啥郁闷的事情啊,说来听听。 他说,最近很郁闷,我本来今年的计划是成为...

自定义标签实现分页功能[看了点网上的,自己在写的。还不错。欢迎点评]

PageTag.java代码: package com.cn.tags; import java.io.IOException; import javax.servlet.http.Http...

软件工程思想--我看了一下还不错

  • 2009年04月03日 22:48
  • 2.13MB
  • 下载

不错的DIC+CSS视频,看了不后悔

  • 2008年09月07日 23:14
  • 9.01MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:XPath最通俗的教程--看了,真的不错
举报原因:
原因补充:

(最多只允许输入30个字)