Xpath路径中引入变量求值达到循环|xlst及java不同

PS:困扰了半个小时
先说说在java中吧,我要实现下面这个
for(int i=0;i<list.getLength();i++){

…….

String cond1="//user[position()=i]";//这里在Xpath中加入了变量i ,这个是java意义的变量,不是Xlst的!
……..
}//结果可以想象,悲剧了!
于是拆分成2个for循环了,只能庆幸,我之需要它循环两次,所以这个问题还是要继续研究。等有时间吧!
String cond1="//user[position()=1]";//第一个用户
String cond2="//user[position()=2]";//第二个用户
NodeList lst1=XPathAPI.selectNodeList(document,cond1+"//music/special");
NodeList lst2=XPathAPI.selectNodeList(document,cond2+"//music/special");
for(int i=0;i<list1.getLength();i++){ }
for(int i=0;i<list2.getLength();i++){ }//只能说这是最最最土的办法
position()这个函数很不多,在ajax 中改变元素的位置很出色~~~~
————-在xlst中就不一样了啦———-
$system/*[name()=$user] 
//这种是查找出system下一级的名字为变量$user的元素
$system/@*[name()=$user]
//这种是查找出system下一级属性的名字为变量$user的,这样的话在循环里面就好使用了!
版权所有© HzlzH | 本文采用 BY-NC-SA 进行授权
转载需注明 转自: 《Xpath路径中引入变量求值达到循环|xlst及java不同

随机文章

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)