疑問

2010-11-20 46 views
1

我想只得到那些數字大於1的元素。我應該用什麼標記生成器不工作我想在這裏...疑問

<games> 
    <game> 
     <Motion>False</Motion> 
     <Platform>Playstation3,XBox, typer</Platform> 
    </game> 
    <game> 
     <Motion>False</Motion> 
     <Platform>Playstation3</Platform> 
    </game> 
</games> 

回答

0

可以使用contains()功能:

doc("games.xml")//game[contains(Platform, ",")] 

編輯:您發佈的查詢不符合您的XML標記。嘗試是這樣的:

for $z in doc("videogames.xml")//game[contains(Platform, ",")] 
return 
<Platform>{$z/Motion}</Platform> 
+0

我在哪裏比條件把更大? – user507087 2010-11-20 07:17:27

+0

@ user507087,對不起,我一定誤會了。我以爲你想要帶有多個平臺的''元素,即其''元素包含一個逗號字符。那麼你究竟想要什麼? :) – 2010-11-20 07:21:25

+0

在我上面提到的問題中,當我運行查詢時,我應該只獲取具有多個平臺 - playstation3,Xbox,typer的遊戲的上層元素。它應該拋棄另一個,因爲在這種情況下只有1個平臺。 – user507087 2010-11-20 07:28:00

0

我想只有在 這些元素,其數量是大於一。我應該使用什麼 ?標記生成器不工作 我想在這裏...

我的猜測是,你希望只與遊戲可用於多個平臺上工作。

使用此測試

/*/game[tokenize(Platform, ',')[2]] 

所以,這個簡單的XQuery

for $g in /*/game[tokenize(Platform, ',')[2]] 
    return $g 

時所提供的XML文檔應用:

<games> 
    <game> 
    <Motion>False</Motion> 
    <Platform>Playstation3,XBox, typer</Platform> 
    </game> 
    <game> 
    <Motion>False</Motion> 
    <Platform>Playstation3</Platform> 
    </game> 
</games> 

回報

<game> 
    <Motion>False</Motion> 
    <Platform>Playstation3,XBox, typer</Platform> 
</game>