什么XPath从表中选择奇数TR,从第三个开始? [英] What XPath selects odd TRs from a table, starting with the third?

查看:1251
本文介绍了什么XPath从表中选择奇数TR,从第三个开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张表:

<table>  
    <tr><td>1</td></tr>  
    <tr><td>2</td></tr>  
    <tr><td>3</td></tr>  
    <tr><td>4</td></tr>  
    <tr><td>5</td></tr>  
    <tr><td>6</td></tr>  
    <tr><td>7</td></tr>  
    <tr><td>8</td></tr>  
    <tr><td>9</td></tr>  
</table>

我需要一个XPath来选择奇数行,从第三行开始(3,5,7, 9,等等。

I need an XPath to select odd rows, starting on the third row (3, 5, 7, 9, etc.).

推荐答案

我认为XPath的position()功能会做这个工作。返回当前正在处理的节点的索引位置。你需要做position()mod 2。

I think 'position()' function of XPATH will do the job. Returns the index position of the node that is currently being processed. you need to do position() mod 2.

这里是XSLT解决方案

Here is XSLT solution

<xsl:for-each select="tr">
  <xsl:choose>
   <xsl:when test="position() mod 2 = 1 and position() > 1">
      ...do smthng ....
   </xsl:when>
   <xsl:otherwise>...do something else...</xsl:otherwise>
  </xsl:choose>
</xsl:foreach>

这篇关于什么XPath从表中选择奇数TR,从第三个开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆