XQuery returning an error..?

拥有回忆 提交于 2019-12-02 02:23:45

Your original query could have been rewritten as follows...

/Continents/Continent[
  some $x in Country/City/Desc satisfies contains($x,'Capital')]
  /Country/City/Name

...or...

/Continents/Continent[
  for $x in Country/City/Desc
  where contains($x,'Capital')
  return $x]/Country/City/Name

...but both of the queries will return all countries of any continent that contains a city description containing 'Capital'. Instead, this is probably what you are looking for:

/Continents/Continent/Country/City[contains(Desc,'Capital')]/Name

You may as well use the contains text expression to ignore case, diacritics, etc. in your key words:

/Continents/Continent/Country/City[Desc contains text 'Capital']/Name

Hope this helps.

Your predicate [contains(Country/City/Desc,'Capital')] selects all Desc nodes containing 'Capital' for the Continent element, so it evaluates to three elements. To fix this, just move the predicate to the City element (after all, you want to filter the City elements, not the Continent). I didn't test it, but i would expect this to work:

/Continents/Continent/Country/City[contains(Desc,'Capital')]/Name
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!