2013-03-05 39 views
0

我的XPath表達式如下:如何驗證多個值與XPath或存儲值

//ep:getSwitchListResponse[1]/result[1]/item[position() >1 and position() <= last()]/ipAddress[1]/text() 

我想要得到的position()值,並用它來驗證名稱。像

//ep:getSwitchListResponse[1]/result[1]/**item[Position()FromPreviousQuery**)]/name[1]/text() 

這是可能的一個xpath表達式?

+0

請張貼的XML你'以wh爲例進行定位在你想要返回。這就是說,你可以插入第一個XPath表達式**作爲位置,給你一個想法。 – JWiley 2013-03-05 14:30:31

回答

0

除非您從本地某處的第一個XPath存儲位置,否則如果要重複使用相同的位置,則必須再次調用xpath,XPath不會存儲以前遍歷的任何內容。

例)

你的第一個XPath:

//ep:getSwitchListResponse[1]/result[1]/item[position() >1 and position() <= last()]/ipAddress[1]/text() 

自己的立場:

count(//ep:getSwitchListResponse[1]/result[1]/item[position() >1 and position() <= last()]/ipAddress[1]/preceding-sibling::*) 

的XPath插入到第二的位置:

//ep:getSwitchListResponse[1]/result[1]/**item[count(//ep:getSwitchListResponse[1]/result[1]/item[position() >1 and position() <= last()]/ipAddress[1]/preceding-sibling::*)]/name[1]/text()