2016-04-03 5 views
1

XML文書で説明されているすべてのレシピをXSLTを使用してリストする必要があります。このリストには、準備時間の降順でレシピが含まれている必要があります。同じ調理時間を有する調理法は、調理時間によって降順に列挙されなければならない。私は最後の部分を行う方法を知らない、私も最初のものについてはよく分からない。ここで私が今まで持っているものです。時間の降順でリストする方法、xsl?

<recipes> 
    <recipe> 
     <lunch> 
      <preparationTime>00:10</preparationTime> 
      <cookingTime>00:30</cookingTime> 
      <ingredients> 
       <ing1>Honey</ing1> 
       <ing2>Avocado</ing2> 
       <ing3>Chicken breast</ing3> 
       <ing4>Tomatoes</ing4> 
      </ingredients> 
      <preparationSteps> 
       <step1>Proin consectetur ligula eget magna placerat luctus</step1> 
       <step2>Donec eu sem at justo imperdiet tempor</step2> 
       <step3>Curabitur vitae ipsum rutrum, facilisis velit tincidunt, rhoncus turpis</step3> 
       <step4>Etiam maximus malesuada feugiat</step4> 
      </preparationSteps> 
     </lunch> 
    </recipe> 

    <recipe> 
     <desert> 
      <preparationTime>00:23</preparationTime> 
      <cookingTime>01:00</cookingTime> 
      <ingredients> 
       <ing1>Kiwi</ing1> 
       <ing2>Avocado</ing2> 
       <ing3>Apple</ing3> 
       <ing4>Honey</ing4> 
      </ingredients> 
      <preparationSteps> 
       <step1>Proin consectetur ligula eget magna placerat luctus</step1> 
       <step2>Praesent volutpat orci non nunc eleifend tincidunt</step2> 
       <step3>Morbi at est ac ligula ornare condimentum</step3> 
       <step4>Jaher maximus malesuada feugiat</step4> 
      </preparationSteps> 
     </desert> 
    </recipe> 

    <recipe> 
     <diet> 
      <preparationTime>00:07</preparationTime> 
      <cookingTime>00:00</cookingTime> 
      <ingredients> 
       <ing1>Water</ing1> 
       <ing2>Lemon</ing2> 
       <ing3>Apple</ing3> 
       <ing4>Tomato</ing4> 
      </ingredients> 
      <preparationSteps> 
       <step1>Class aptent taciti sociosqu ad litora torquent per conubia nostras</step1> 
       <step2> Quisque id pretium eros</step2> 
       <step3>Pellentesque elit velit, feugiat vel rhoncus</step3> 
       <step4>Vee milori malesuada feugiat</step4> 
      </preparationSteps> 
     </diet> 
    </recipe> 

    <recipe> 
     <dinner> 
      <preparationTime>00:18</preparationTime> 
      <cookingTime>00:11</cookingTime> 
      <ingredients> 
       <ing1>Fish</ing1> 
       <ing2>Lemon</ing2> 
       <ing3>Honey</ing3> 
       <ing4>Salt</ing4> 
      </ingredients> 
      <preparationSteps> 
       <step1>Donec eu sem at justo imperdiet tempor</step1> 
       <step2>Nurcas non tellus eu magna dictum hendrerit</step2> 
       <step3>Morbi at est ac ligula ornare condimentum</step3> 
       <step4>Derbis maximus malesuada feugiat</step4> 
      </preparationSteps> 
     </dinner> 
    </recipe> 

</recipes> 

とXSL:

<?xml version="1.0"?> 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 

<html> 
    <body> 
     <h2>Recipes</h2> 
     <xsl:for-each select="recipes/recipe"> 
     <ul> 
      <li><xsl:value-of select="lunch"></li> 
       <li><xsl:value-of select="preparationTime"></li> 
       <li><xsl:value-of select="cookingTime"></li> 
       <ul><xsl:value-of select="ingredients"> 
        <li><xsl:value-of select="ing1"></li> 
        <li><xsl:value-of select="ing2"></li> 
        <li><xsl:value-of select="ing3"></li> 
        <li><xsl:value-of select="ing4"></li> 
       </ul> 
       <ol><xsl:value-of select="preparationSteps"> 
        <li><xsl:value-of select="step1"></li> 
        <li><xsl:value-of select="step2"></li> 
        <li><xsl:value-of select="step3"></li> 
        <li><xsl:value-of select="step4"></li> 
       </ol> 


      <li><xsl:value-of select="desert"></li> 
       <li><xsl:value-of select="preparationTime"></li> 
       <li><xsl:value-of select="cookingTime"></li> 
       <ul><xsl:value-of select="ingredients"> 
        <li><xsl:value-of select="ing1"></li> 
        <li><xsl:value-of select="ing2"></li> 
        <li><xsl:value-of select="ing3"></li> 
        <li><xsl:value-of select="ing4"></li> 
       </ul> 
       <ol><xsl:value-of select="preparationSteps"> 
        <li><xsl:value-of select="step1"></li> 
        <li><xsl:value-of select="step2"></li> 
        <li><xsl:value-of select="step3"></li> 
        <li><xsl:value-of select="step4"></li> 
       </ol> 


      <li><xsl:value-of select="diet"></li> 
       <li><xsl:value-of select="preparationTime"></li> 
       <li><xsl:value-of select="cookingTime"></li> 
       <ul><xsl:value-of select="ingredients"> 
        <li><xsl:value-of select="ing1"></li> 
        <li><xsl:value-of select="ing2"></li> 
        <li><xsl:value-of select="ing3"></li> 
        <li><xsl:value-of select="ing4"></li> 
       </ul> 
       <ol><xsl:value-of select="preparationSteps"> 
        <li><xsl:value-of select="step1"></li> 
        <li><xsl:value-of select="step2"></li> 
        <li><xsl:value-of select="step3"></li> 
        <li><xsl:value-of select="step4"></li> 
       </ol> 


      <li><xsl:value-of select="dinner"></li> 
       <li><xsl:value-of select="preparationTime"></li> 
       <li><xsl:value-of select="cookingTime"></li> 
       <ul><xsl:value-of select="ingredients"> 
        <li><xsl:value-of select="ing1"></li> 
        <li><xsl:value-of select="ing2"></li> 
        <li><xsl:value-of select="ing3"></li> 
        <li><xsl:value-of select="ing4"></li> 
       </ul> 
       <ol><xsl:value-of select="preparationSteps"> 
        <li><xsl:value-of select="step1"></li> 
        <li><xsl:value-of select="step2"></li> 
        <li><xsl:value-of select="step3"></li> 
        <li><xsl:value-of select="step4"></li> 
       </ol> 
     </ul> 

     <!-- 
     <xsl:sort select="substring-before(substring-after(normalize-space(NoteEnteredOn), ,' '),':') mod 12" 
      order="descending" data-type="number" /> 
     <xsl:sort select="substring-before(substring-after(normalize-space(NoteEnteredOn),':'), ' ')" 
      order="descending" data-type="number" /> --> 
    </body> 
</html> 

</xsl:template> 
</xsl:stylesheet> 
+0

あなたはpreparationTime' 'による最初のグループ' recipe'要素にしたい場合は、XSLT 2.0で、簡単に、例えば使用してそれを行うことができます' group-by = ".// prepareTime"> ... 'です。 XSLT 1.0プロセッサを使用する必要がある場合は、Muenchianグループhttp://www.jenitennison.com/xslt/grouping/muenchian.xmlを使用できます。 –

答えて

0

あなたは、 "文字列" としてソート可能最適です。そのため、ソートのためにあなただけの次のXSLT追加する必要があります。ソートあなたのfor-eachた:

 <xsl:sort select="*/preparationTime" order="descending" /> 
     <xsl:sort select="*/cookingTime" order="descending" /> 

しかし、あなたのXSLTと他のいくつかの問題があります。

  • があなたのXSLTは有効ではありません。
  • 各レシピでは、昼食、砂漠などのエントリは1つだけですが、レシピごとにすべてを選択しようとします。

for-eachには、以下のように見えることがあります。

<xsl:for-each select="recipes/recipe"> 
     <xsl:sort select="*/preparationTime" order="descending" /> 
     <xsl:sort select="*/cookingTime" order="descending" /> 
    <ul> 
     <li><xsl:value-of select="name(*)"/></li> 
     <li><xsl:value-of select="*/preparationTime"/></li> 
     <li><xsl:value-of select="*/cookingTime"/></li> 

     <!-- some more infos --> 
    </ul> 
    </xsl:for-each> 
+0

私は以下のコードを書いています。これはすばらしいと思いますし、原料+ preparationStepsを追加しましたが、それは必要なことをしません。私は次のようなものを得ています: "00:10 00:30ハニーアボカドチキン乳房トマト熟成した卵の上に卵を入れておいてください卵の上に卵を置いてください卵を食べる卵は、 23 01:00キウイアボカドアップルハニーProin consectetur ligula ... "なぜそれはリストのように見えませんか? – AndrB

+0

'' prepareSteps'とすべての子からのすべてのテキストコンテキストを追加します。試してみてください

  • ' –

    関連する問題