我正试图找到Shaquille O'Neal在维基百科页面中出演的球队:https://en.wikipedia.org/wiki/Highest-paid_NBA_players_by_season
let $doc := doc("NBApaid.xml")//table
for $x in $doc/tr
where $x/td/a="Shaquille O'Neal"
for $y in $x/td/a
where $y != "Shaquille O'Neal"
return distinct-values($y)
输出结果为:
Cleveland Cavaliers
Phoenix Suns
Phoenix Suns
Miami Heat
Miami Heat
Miami Heat
Los Angeles Lakers
Los Angeles Lakers
Los Angeles Lakers
Los Angeles Lakers
Los Angeles Lakers
Los Angeles Lakers
但是,我只想要不同的字符串,即输出如下:
Cleveland Cavaliers
Phoenix Suns
Miami Heat
Los Angeles Lakers
我不知道我在哪里出错了,在这个特定的问题上被困了大约2个小时,我无法比较数据的不同行中的两个值,即当我使用count() - 函数时我只得到一列:
1
1
1
1
1
1
1
1
1
1
1
1
是的,这是家庭作业,但我不是要求整个解决方案;只是我的代码出了什么问题。
答案 0 :(得分:0)
使用Xidel:
xidel -s https://en.wikipedia.org/wiki/Highest-paid_NBA_players_by_season -e '
distinct-values(//tr[td/a="Shaquille O'\''Neal"]/td[last()]/a)
'
Cleveland Cavaliers
Phoenix Suns
Miami Heat
Los Angeles Lakers
Orlando Magic
xidel -s https://en.wikipedia.org/wiki/Highest-paid_NBA_players_by_season --xquery '
for $x in //tr
where $x/td/a="Shaquille O'Neal"
group by $teams:=$x/td[last()]/a
return $teams
'
Cleveland Cavaliers
Los Angeles Lakers
Miami Heat
Orlando Magic
Phoenix Suns