【问题标题】:Displaying xquery result显示 xquery 结果
【发布时间】:2016-10-17 17:58:16
【问题描述】:

我在 xquery 中执行这个函数

     declare function local:f(){
        for $Restaurant in collection("Guide")/Restaurants/Restaurant
        return 
        <Restaurants>
        {local:f()/Nom}
        {local:f()/Adresse}
        {local:f()/Telephone}
        </Restaurants>
        };

这是我从函数中得到的结果:

<Restaurants>
   <Nom>La ferme Saint-Simon </Nom>
   <Nom>La Romantique </Nom>
   <Adresse>
        <Num> 6 </Num>
        <Rue> rue Saint Simon </Rue>
        <Zip> 75007 </Zip>
        <Ville> Paris </Ville>
    </Adresse>
   <Adresse>
        <Num> 8 </Num>
        <Rue> Avenue A.Piat </Rue>
        <Zip> 14000 </Zip>
        <Ville> Cabourg </Ville>
    </Adresse>
   <Telephone> 01 45 48 35 74 </Telephone>
   <Telephone> 01 45 48 35 75 </Telephone>
   <Telephone> 02 31 24 10 92 </Telephone>
</Restaurants>

我想将显示更改为这样的:

        <Restaurant>
        <Nom>La ferme Saint-Simon </Nom>
        <Adresse>
        <Num> 6 </Num>
        <Rue> rue Saint Simon </Rue>
        <Zip> 75007 </Zip>
        <Ville> Paris </Ville>
        </Adresse>
        <Telephone> 01 45 48 35 74 </Telephone>
        </Restaurant>

     <Restaurant>
        <Nom>La ferme Saint-Simon </Nom>
        <Adresse>
        <Num> 6 </Num>
        <Rue> rue Saint Simon </Rue>
        <Zip> 75007 </Zip>
        <Ville> Paris </Ville>
        </Adresse>
        <Telephone> 01 45 48 35 74 </Telephone>
        </Restaurant>

请问我刚开始学习 xquery 有什么帮助吗?

【问题讨论】:

  • 我看不出您的查询是如何工作的 - 该函数是无限递归的。

标签: loops formatting xquery


【解决方案1】:

在您的返回中仅引用变量 $Restaurant(而不是函数 local:f() 本身):

declare function local:f(){
    for $Restaurant in collection("Guide")/Restaurants/Restaurant
    return 
    <Restaurants>
        {$Restaurant/Nom}
        {$Restaurant/Adresse}
        {$Restaurant/Telephone}
    </Restaurants>
    };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 2017-05-04
    • 1970-01-01
    • 2016-04-08
    相关资源
    最近更新 更多