url的循环增量

时间:2013-04-22 13:52:33

标签: html xml xpath xquery

我想从我的标题中插入动态网址,它可以工作,但它会显示2个不同循环的6 * 6'原因...我不知道该怎么做...

我尝试使用全局变量,但它是一样的...(我有6个食谱)

谢谢!

代码XML:

  <recette id="r1">
    <titre>Cake au chocolat</titre>
    <cat>dessert</cat>
    <type/>
    <nombre>6</nombre>
    <listeingredients>
      <ingredient q="150" u="g">chocolat pâtissier</ingredient>
      <ingredient q="3" u="pièce">oeufs</ingredient>
      <ingredient q="100" u="g">sucre en poudre</ingredient>
      <ingredient q="60" u="g">farine</ingredient>
      <ingredient q="1" u="cuillère à café">levure</ingredient>
      <ingredient q="80" u="g">beurre</ingredient>
      <ingredient q="50" u="g">poudre d'amandes</ingredient>
    </listeingredients>
    <cuisson>
      <temps type="preparation">15</temps>
      <temps type="cuisson">30</temps>
      <temperature u="C">180</temperature>
    </cuisson>
  </recette>
  <recette id="r2">
    <titre>Brownies aux noix de pécan</titre>
    <cat>dessert</cat>
    <type/>
    <nombre>6</nombre>
    <listeingredients>
      <ingredient q="200" u="g">chocolat à cuire</ingredient>
    <cuisson>
      <temps type="preparation">10</temps>
      <temps type="cuisson">25</temps>
      <temperature u="C">180</temperature>
    </cuisson>
    <instruction>
      <etape>Faire fondre le chocolat avec le beurre, soit au bain-marie à feu doux, soit au micro-ondes sur programme 'décongélation'.</etape>
      <etape>Quand c'est bien fondu, mélanger et ajouter le sucre, les oeufs un par un, la farine, puis les noix de pécan hachées grossièrement.</etape>
      <etape>Bien mélanger et verser dans un moule carré de 20 cm (ou rectangulaire pas trop grand), chemisé de papier sulfurisé.</etape>
      <etape>Mettre au four préchauffé à 180°C pendant 25 min.</etape>
      <etape>Laisser refroidir et couper en carrés.</etape>
    </instruction>
  </recette>
</listerecettes>

代码xq:

{
    for $titre in db:open("recettes")//recette//titre, $j in (6,2,1,5,4,3)
    order by $titre
    return
    <a href="http://127.0.0.1:8984/rest/recettes?query=//recette[@id='r{$j}']">
        <ul>
            <li>
            {
                $titre
            }
            </li>
        </ul>
    </a>
}
</body>
</html>

2 个答案:

答案 0 :(得分:0)

在您发表评论后,我仍然不知道您希望通过$j实现什么目标,因为它根本没用,可以简单地删除。所以我想你可能想要别的东西而不仅仅是一个按照标题排序的简单列表 - 如果是这样,请清楚你要实现的目标。否则,只需删除$j并使用id属性即可。

for $recette in db:open("recettes")//recette
let $titre := $recette/titre
order by $titre
return
<a href="http://127.0.0.1:8984/rest/recettes?query=//recette[@id='{$recette/@id}']">
    <ul>
        <li>
        {
            $titre
        }
        </li>
    </ul>
</a>

答案 1 :(得分:0)

谢谢,但我刚刚发现了另一种方式! :

for $titre in db:open("recettes")//recette//titre
order by $titre
return
<a href="http://127.0.0.1:8984/rest/recettes?query=//recette[@id='{$titre/..//@id}']">
    <ul>
        <li>
        {
          $titre
        }
        </li>
    </ul>
</a>

我测试了你的代码并且它是正确的但你在订购后忘记了“$ titre”!

相关问题