Format output with HTML tags : html « XSLT stylesheet « XML






Format output with HTML tags


File: Data.xml

<?xml version="1.0"?>
<itinerary>
  <day number="1">day 1</day>
  <day number="2">day 2</day>
  <day number="3">day 3</day>
  <day number="4">day 4</day>
  <day number="5">day 5</day>
  <day number="6">day 6</day>
  <day number="7">day 7</day>
  <day number="8">day 8</day>
  <day number="9">day 9</day>
</itinerary>


File: Transform.xslt
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <head>
        <title>Itinerary</title>
      </head>
      <body>
        <center>
          <xsl:apply-templates select="//day" />
        </center>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="day">
    <h3>
      Day
      <xsl:value-of select="@number" />
    </h3>
    <p>
      <xsl:apply-templates />
    </p>
  </xsl:template>
</xsl:stylesheet>

Output:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Itinerary</title>
   </head>
   <body>
      <center>
         <h3>
                  Day
                  1
         </h3>
         <p>day 1</p>
         <h3>
                  Day
                  2
         </h3>
         <p>day 2</p>
         <h3>
                  Day
                  3
         </h3>
         <p>day 3</p>
         <h3>
                  Day
                  4
         </h3>
         <p>day 4</p>
         <h3>
                  Day
                  5
         </h3>
         <p>day 5</p>
         <h3>
                  Day
                  6
         </h3>
         <p>day 6</p>
         <h3>
                  Day
                  7
         </h3>
         <p>day 7</p>
         <h3>
                  Day
                  8
         </h3>
         <p>day 8</p>
         <h3>
                  Day
                  9
         </h3>
         <p>day 9</p>
      </center>
   </body>
</html>

 








Related examples in the same category

1.Output various html tags
2.Output html img tag
3.One html tag per template
4.Wrap HTML tags in template
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