2016-06-23 7 views
0

私は動的なXMLデータを持っており、次のxsltコードを使ってhtmlを生成します。 XML構造には、チャプター、サブチャプター、チェックリスト、サマリーノードが含まれています。再帰的なXSLTコードを書くには

  • <chapter><summary>

私のコードは動作しますが、サブチャプターの内容は、チェックリストの前に追加したすべての時間が含まれてい<subchapter><checklist>

  • <subchapter> contanins <subchapter><checklist>
  • <checklist>が含まれています。チャプターがチェックリスト、サブチャプターノード(最初のチェックリスト)を含む場合、サブチャプターコンテンツが最初に作成されます。

    これを修正するにはどうすればよいですか、または再帰的に次のコードを書き換えるにはどうすればよいですか?

    <xsl:apply-templates select="subchapter"/> 
    <xsl:apply-templates select="checklist"/> 
    

    したい:私は推測してい

    <xsl:template match="chapter"> 
        <xsl:apply-templates select="chapter"/> 
        </xsl:template> 
    
        <xsl:template match="chapter">  
        <table> 
         <tr> 
         <td> 
          <h2> 
          <xsl:value-of select="@name"/> 
          </h2> 
         </td> 
         </tr> 
         <xsl:apply-templates select="subchapter"/> 
         <xsl:apply-templates select="checklist"/> 
        </table> 
        </xsl:template> 
    
    
    
        <xsl:template match="subchapter"> 
    
         <tr> 
         <td> 
          <h3> 
          <xsl:attribute name="name"> 
           <xsl:value-of select="@value"/> 
          </xsl:attribute> 
          <xsl:value-of select="@name"/> 
          </h3> 
         </td> 
         </tr> 
    
         <xsl:apply-templates select="subchapter"/> 
         <xsl:apply-templates select="checklist"/> 
    
        </xsl:template> 
    
    
        <xsl:template match="checklist">  
         <tr> 
         <td> 
          <h4> 
          <xsl:attribute name="name"> 
           <xsl:value-of select="@value"/> 
          </xsl:attribute> 
    
          <xsl:value-of select="@name"/> 
    
          </h4> 
         </td> 
         </tr> 
    
         <xsl:apply-templates select="summary"/> 
    
        </xsl:template> 
    
        <xsl:template match="summary">  
         <tr> 
         <td> 
          <xsl:copy-of select="*"/> 
         </td> 
         </tr>  
        </xsl:template> 
    
  • +0

    」または「」で 'xsl:apply-templates select =" subchapter "/> '次に、子ノードや子要素をドキュメント順に、そして2つの' apply-templates'の順に処理します。 –

    答えて

    2

    その代わりに、(入力と期待される出力を見ることなく、私は推測することしかできません)

    <xsl:apply-templates select="subchapter | checklist"/> 
    

    chapterをした場合subchapterchecklistが含まれています。

    <xsl:apply-templates/> 
    
    +0

    あなたの質問に答えられたら、答えを受け入れて閉じてください。 –

    関連する問題