Output various html tags : html « XSLT stylesheet « XML






Output various html tags



File: Data.xml

<poem>
  <title>From Book I</title>
  <excerpt>
    <verse>para1</verse>
    <verse>para2</verse>
    <verse>line 2;</verse>
  </excerpt>
  <excerpt>
    <verse>line 2</verse>
    <verse></verse>
  </excerpt>
</poem>

File: Transform.xslt

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

  <xsl:output method="html" />

  <xsl:template match="poem">
    <html>
      <body>
        <xsl:apply-templates />
      </body>
    </html>
  </xsl:template>

  <xsl:template match="title">
    <h1>
      <xsl:apply-templates />
    </h1>
  </xsl:template>

  <xsl:template match="excerpt">
    <p>
      <xsl:apply-templates />
    </p>
    <hr></hr>
  </xsl:template>

  <xsl:template match="verse">
    <xsl:apply-templates />
    <br />
  </xsl:template>


</xsl:stylesheet>

Output:

<html>
   <body>
        
      <h1>From Book I</h1>
        
      <p>
             para1<br>
             para2<br>
             line 2;<br>
           
      </p>
      <hr>
        
      <p>
             line 2<br>
             <br>
           
      </p>
      <hr>
      
   </body>
</html>

 








Related examples in the same category

1.Output html img tag
2.One html tag per template
3.Wrap HTML tags in template
4.Format output with HTML tags
5.Construct image name used by generated HTML in style sheet
6.html output method to make br tags come out as
7.Output html with frameset
8.Transformation of book information into XHTML with sorting
9.Output whole xhtml document
10.Add more format with html tags
11.Format output with font
12.Use blockquote to output value from xml