以单斜杠(/)开头,则代表绝对路径

/AAA/DDD/BBB

<AAA> 
  <BBB/> 
  <CCC/> 
  <BBB/> 
  <BBB/> 
  <DDD> 
    <BBB/> <!-- selected -->
  </DDD> 
  <CCC/> 
</AAA>

以双斜杠(//)开头,则选中文档中所有符合条件的节点

//DDD/BBB

<AAA> 
  <BBB/> 
  <CCC/> 
  <BBB/> 
  <DDD>
    <BBB/> <!-- selected -->
  </DDD>
  <CCC> 
    <DDD> 
      <BBB/> <!-- selected -->
      <BBB/> <!-- selected -->
    </DDD> 
  </CCC> 
</AAA>

星号(*)选中指定的所有节点

/AAA/CCC/DDD/*

<AAA> 
  <XXX> 
    <DDD> 
      <BBB/> 
      <BBB/> 
      <EEE/> 
      <FFF/> 
    </DDD> 
  </XXX> 
  <CCC> 
    <DDD> 
      <BBB/> <!-- selected -->
      <BBB/> <!-- selected -->
      <EEE/> <!-- selected -->
      <FFF/> <!-- selected -->
    </DDD> 
  </CCC> 
  <CCC> 
    <BBB> 
      <BBB> 
        <BBB/> 
      </BBB> 
    </BBB> 
  </CCC> 
</AAA>

属性(@)

//BBB[@name]

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

//BBB[@name=’bbb’]

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

下标

<AAA> 
  <BBB/> <!-- /AAA/BBB[1] -->
  <BBB/> 
  <BBB/> 
  <BBB/> <!-- /AAA/BBB[last()] -->
</AAA>

计数(count())

//*[count(BBB)=2]

<AAA> 
  <CCC> 
    <BBB/> 
    <BBB/> 
    <BBB/> 
  </CCC> 
  <DDD> <!-- selected -->
    <BBB/> 
    <BBB/> 
  </DDD>
  <EEE> 
    <CCC/> 
    <DDD/> 
  </EEE> 
</AAA>

节点名(name())

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

<AAA> 
  <BCC> 
    <BBB/> <!-- selected -->
    <BBB/> <!-- selected -->
    <BBB/> <!-- selected -->
  </BCC> 
  <DDB> 
    <BBB/> <!-- selected -->
    <BBB/> <!-- selected -->
  </DDB> 
  <BEC> 
    <CCC/> 
    <DBD/> 
  </BEC> 
</AAA>

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

<AAA> 
  <BCC> <!-- selected -->
    <BBB/> <!-- selected -->
    <BBB/> <!-- selected -->
    <BBB/> <!-- selected -->
  </BCC> 
  <DDB> 
    <BBB/> <!-- selected -->
    <BBB/> <!-- selected -->
  </DDB> 
  <BEC> <!-- selected -->
    <CCC/> 
    <DBD/> 
  </BEC> 
</AAA>

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

<AAA> 
  <BCC> <!-- selected -->
    <BBB/> 
    <BBB/> 
    <BBB/> 
  </BCC> 
  <DDB> 
    <BBB/> 
    <BBB/> 
  </DDB> 
  <BEC> <!-- selected -->
    <CCC/> <!-- selected -->
    <DBD/> 
  </BEC> 
</AAA>

字符串长度(string-length())

//*[string-length(name()) < 3]

<AAA> 
  <Q/> <!-- selected -->
  <SSSS/> 
  <BB/> <!-- selected -->
  <CCC/> 
  <DDDDDDDD/> 
  <EEEE/> 
</AAA>

联合(|)

/AAA/EEE | //BBB
<AAA> 
  <BBB/> <!-- selected -->
  <CCC/> 
  <DDD> 
    <CCC/> 
  </DDD> 
  <EEE/> <!-- selected -->
</AAA>

父轴(parent::)

//DDD/parent::*

<AAA> 
  <BBB> <!-- selected -->
    <DDD> 
      <CCC> <!-- selected -->
        <DDD/> 
        <EEE/> 
      </CCC> 
    </DDD> 
  </BBB> 
  <CCC> <!-- selected -->
    <DDD> 
      <EEE> <!-- selected -->
        <DDD> 
          <FFF/> 
        </DDD> 
      </EEE> 
    </DDD> 
  </CCC> 
</AAA>

祖先轴(ancestor::)

//FFF/ancestor::*

<AAA> <!-- selected -->
  <BBB> 
    <DDD> 
      <CCC> 
        <DDD/> 
        <EEE/> 
      </CCC> 
    </DDD> 
  </BBB> 
  <CCC> <!-- selected -->
    <DDD> <!-- selected -->
      <EEE> <!-- selected -->
        <DDD> <!-- selected -->
          <FFF/> 
        </DDD> 
      </EEE> 
    </DDD> 
  </CCC> 
</AAA>

向下兄弟轴(following-sibling::)

//CCC/following-sibling::*

<AAA> 
  <BBB> 
    <CCC/> 
    <DDD/> <!-- selected -->
  </BBB> 
  <XXX> 
    <DDD> 
      <EEE/> 
      <DDD/> 
      <CCC/> 
      <FFF/> <!-- selected -->
      <FFF> <!-- selected -->
        <GGG/> 
      </FFF> 
    </DDD> 
  </XXX> 
  <CCC> 
    <DDD/> 
  </CCC> 
</AAA>

向上兄弟轴(preceding-sibling::)

//CCC/preceding-sibling::*

<AAA> 
  <BBB> <!-- selected -->
    <CCC/> 
    <DDD/> 
  </BBB> 
  <XXX> <!-- selected -->
    <DDD> 
      <EEE/> <!-- selected -->
      <DDD/> <!-- selected -->
      <CCC/> 
      <FFF/> 
      <FFF> 
        <GGG/> 
      </FFF> 
    </DDD> 
  </XXX> 
  <CCC> 
    <DDD/> 
  </CCC> 
</AAA>

算术运算

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

<AAA> 
  <BBB/> 
  <BBB/> <!-- selected -->
  <BBB/> 
  <BBB/> <!-- selected -->
  <BBB/> 
  <BBB/> <!-- selected -->
  <BBB/> 
  <BBB/> <!-- selected -->
  <CCC/> 
  <CCC/> 
  <CCC/> 
</AAA>