template mode="index" : template match « XSLT stylesheet « XML






template mode="index"



File: Data.xml

<?xml version="1.0"?>
<cv>
  <para>
    <performance>
      <publication>H</publication>
      G
      <venue>F</venue>
      E
      <group>D</group>
      C
      <date>1998</date>
      B
      <quote>
        A
      </quote>
    </performance>
  </para>
</cv>



File: Transform.xslt

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


  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates />
        <table bgcolor="#cccccc" border="1" cellpadding="5">
          <tr>
            <td>
              <b>Date</b>
            </td>
            <td>
              <b>Venue</b>
            </td>
            <td>
              <b>Composer</b>
            </td>
            <td>
              <b>Work</b>
            </td>
            <td>
              <b>Role</b>
            </td>
          </tr>
          <xsl:apply-templates mode="index" />
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="performance" mode="index">
    <tr>
      <td>
        <xsl:value-of select="date" />
        &#xa0;
      </td>
      <td>
        <xsl:value-of select="venue" />
        &#xa0;
      </td>
      <td>
        <xsl:value-of select="composer" />
        &#xa0;
      </td>
      <td>
        <xsl:value-of select="work" />
        &#xa0;
      </td>
      <td>
        <xsl:value-of select="role" />
        &#xa0;
      </td>
    </tr>
  </xsl:template>


</xsl:stylesheet>

Output:

<html>
   <body>
        
          
            H
            G
            F
            E
            D
            C
            1998
            B
            
              A
            
          
        
      
      <table bgcolor="#cccccc" border="1" cellpadding="5">
         <tr>
            <td><b>Date</b></td>
            <td><b>Venue</b></td>
            <td><b>Composer</b></td>
            <td><b>Work</b></td>
            <td><b>Role</b></td>
         </tr>
           
             
         <tr>
            <td>1998
                       &nbsp;
                     
            </td>
            <td>F
                       &nbsp;
                     
            </td>
            <td>
                       &nbsp;
                     
            </td>
            <td>
                       &nbsp;
                     
            </td>
            <td>
                       &nbsp;
                     
            </td>
         </tr>
           
         
      </table>
   </body>
</html>

 








Related examples in the same category

1.Define and use template
2.Locate parent tags and get value from children tags
3.Select value from an element with value-of
4.Get two values in one template
5.match an element
6.output in template
7.set match mode to fulltext
8.match and get value operations with namespace
9.Call a template with parameter
10.template with parameters
11.output a table without loop