2017-10-22 9 views
0

の横に表示されています。だから、私はステップがあり、ステップがありますが、何らかの理由でxmlのテキストが転送されていません。「メソッド」では<step>という番号が付けられていますが、番号はXSLT

これは今何が起こることは、私は私の方向がステップには番号が付けなければというタイトルにしたいということです。これは私が私のXSLTファイルに持っているもの

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

<xsl:template match="ingredients"> 
    <h1>Ingredients</h1> 
    <xsl:text>&#10;</xsl:text> 
    <xsl:for-each select="ing"> 

     <p> 
      <xsl:choose> 
       <xsl:when test="prep"> 
        <xsl:text>&#10;</xsl:text> 
        <xsl:value-of select="amt/qty"/> 
        <xsl:text>&#10;</xsl:text> 
        <xsl:value-of select="amt/unit"/> 
        <xsl:text>&#10;</xsl:text> 
        <xsl:value-of select="item"/> 
        <xsl:text>&#10;</xsl:text> 
        <span style="font-style:italic"> 
         <xsl:value-of select="prep"/> 
        </span> 
        <xsl:text>&#10;</xsl:text> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:text>&#10;</xsl:text> 
        <xsl:value-of select="amt/qty"/> 
        <xsl:text>&#10;</xsl:text> 
        <xsl:value-of select="amt/unit"/> 
        <xsl:text>&#10;</xsl:text> 
        <xsl:value-of select="item"/> 
        <xsl:text>&#10;</xsl:text> 
       </xsl:otherwise> 
      </xsl:choose> 
     </p> 

    </xsl:for-each> 
</xsl:template> 

<xsl:template match="directions"> 
    <h2>Methods</h2> 
    <xsl:text>&#10;</xsl:text> 
    <xsl:for-each select="step"> 
     <xsl:number format="1."/> 
     <xsl:text>&#10;</xsl:text> 
    </xsl:for-each> 
    <xsl:value-of select="step"/> 
    <xsl:text> </xsl:text> 
    <p> 
     <xsl:value-of select="note"/> 
     <br/> 
    </p> 

</xsl:template> 
</xsl:stylesheet> 

だろう

<recipeml> 
    <recipe> 
     <head> 
      <title>Coq au Riesling</title> 
     </head> 
     <ingredients> 
      <ing> 
      <amt> 
       <qty>30</qty> 
       <unit system="metric">ml</unit> 
      </amt> 
      <item>garlic-infused olive oil</item> 
      </ing> 
      <ing> 
      <amt> 
       <qty>150</qty> 
       <unit system="metric" unit="g">gram(s)</unit> 
      </amt> 
      <item>bacon lardons</item> 
      </ing> 
      <ing> 
      <amt> 
       <qty>1</qty> 
      </amt> 
      <item>leek(s)</item> 
      <prep>(finely sliced)</prep> 
      </ing> 
      <ing> 
      <amt> 
       <qty>12</qty> 
      </amt> 
      <item>chicken thighs (boneless and skinned)</item> 
      </ing> 
      <ing> 
      <amt> 
       <qty>3</qty> 
      </amt> 
      <item>bay leaves</item> 
      </ing> 
      <ing> 
      <amt> 
       <qty>300</qty> 
       <unit system="metric">gram(s)</unit> 
      </amt> 
      <item>oyster mushroom(s) (torn into strips)</item> 
      </ing> 
      <ing> 
      <amt> 
       <qty>750</qty> 
       <unit system="metric">ml</unit> 
      </amt> 
      <item>Riesling</item> 
      </ing> 
      <ing> 
      <amt> 
       <qty> 1</qty> 
       <unit>splash of</unit> 
      </amt> 
      <item>double cream (optional)</item> 
      </ing> 
      <ing> 
      <amt> 
       <qty> 1</qty> 
       <unit>pinch of</unit> 
      </amt> 
      <item>salt</item> 
      </ing> 
      <ing> 
      <amt> 
       <qty>1</qty> 
       <unit>pinch of </unit> 
      </amt> 
      <item>Pepper</item> 
      </ing> 
      <ing> 
      <amt> 
       <qty>1</qty> 
       <unit>tablespoon(s)</unit> 
      </amt> 
      <item>dill (chopped to serve (2 tablespoons if needed)) </item> 
      </ing> 
     </ingredients> 
     <directions> 
      <step> Heat the oil in a casserole or large, wide pan and fry the lardons until crisp.</step> 
      <step> Add the sliced leek and soften it with the lardons for a minute or so.</step> 
      <step> Cut chicken thighs into 2 or 3 pieces each, tip them into the pan with the bay leaves, torn mushrooms and wine. </step> 
      <step>Season with salt and pepper to taste and bring to the boil, cover the pan and simmer gently for 30-40 minutes, stirring in the double cream for the last couple of minutes if you want. </step> 
      <note> Like all stews, this tastes its mellowest best if you let it get cold and then reheat the next day. But it's no hardship to eat straight off. Whichever, serve sprinkled with dill and together with some buttered noodles.</note> 
     </directions> 
    </recipe> 
</recipeml> 

XMLファイルであり、私はそれらに番号を付けるが、何らかの理由でxmlのテキストが転送されない。私はどこかではなく、完全に確認してくださいめちゃくちゃよどこ:(

答えて

0

このロジックを

<xsl:for-each select="step"> 
    <xsl:number format="1."/> 
    <xsl:text>&#10;</xsl:text> 
</xsl:for-each> 
<xsl:value-of select="step"/> 

XSLT 1.0と2.0では異なる効果がありますが、使用している言葉はありません。しかし、どちらの場合でも、それは間違っています。各ステップごとに数値を出力し、最後にステップの値を出力することを考えます。 XSLT 1.0では、xsl:value-ofは最初のステップの内容を出力し、2.0ではすべてのステップの値をスペースで区切って出力します。あなたが実際に欲しいものは、次のようなものです:

<xsl:for-each select="step"> 
    <xsl:number format="1."/> 
    <xsl:text>&#10;</xsl:text> 
    <xsl:value-of select="."/> 
</xsl:for-each> 
+0

それは問題を解決することができました。助けてくれてありがとう。私はいくつかの変更を加えていますが、それは私が把握できなかった1つの問題でした。 – OC1092

0

ターゲット形式はHTMLであると思わとして、私はHTMLに順序付けられたリスト、それらのstep Sを変換することをお勧め:

<xsl:template match="directions"> 
    <h2>Methods</h2> 
    <xsl:text>&#10;</xsl:text> 
    <ol> 
     <xsl:apply-templates select="step"/> 
    </ol> 

    <xsl:text> </xsl:text> 
    <p> 
     <xsl:value-of select="note"/> 
     <br/> 
    </p> 

</xsl:template> 

<xsl:template match="step"> 
    <li> 
     <xsl:apply-templates/> 
    </li> 
</xsl:template> 

そのようにいずれかを結果をHTMLレンダリングするユーザエージェントはstep sがに変換されているリスト項目の番号付けの世話をします。

関連する問題