Format output with font : html « XSLT stylesheet « XML

XML
1. CSS Style
2. SVG
3. XML Schema
4. XQuery
5. XSLT stylesheet
Java
XML Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
XML » XSLT stylesheet » html 
Format output with font


File: Data.xml
<?xml version="1.0" standalone="no" ?>
<transcript>
  <student id="STU12345" name="name 1" status="active">
    <home_address>35 Wall Street, Wonderland, NJ</home_address>
    <interests>
      <interest>interest 1</interest>
      <interest>interest 2</interest>
      <interest>interest 3</interest>
    </interests>
  </student>
  <term>
    <heading name="Winter 1999" />
    <course>
      <course-name>course 1</course-name>
      <grade>A-</grade>
      <credits>4</credits>
    </course>
    <course>
      <course-name>course 2</course-name>
      <grade>B+</grade>
      <credits>3</credits>
    </course>
  </term>
  <term>
    <heading name="Spring 1999" />
    <course>
      <course-name>Physics for Poets</course-name>
      <grade>A</grade>
      <credits>10</credits>
    </course>
    <course>
      <course-name>Poetry for Physicists</course-name>
      <grade>C+</grade>
      <credits>5</credits>
    </course>
  </term>
  <summary>summary</summary>
  <comments>
     
    comments
  </comments>
</transcript>

File: Transform.xslt

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

  <xsl:template match="transcript">
    <HTML><BODY>

    <xsl:apply-templates select="student" />

    <HR/>
    <TABLE ALIGN="left" BORDER="1" CELLPADDING="4">
      <TR>
        <TH>Course Name</TH>
        <TH>Grade</TH>
        <TH ALIGN="right">Credits</TH>
      </TR>
      <xsl:for-each select="term/course">
        <xsl:sort select="credits" data-type="number" />
        <xsl:apply-templates select="." />
      </xsl:for-each>
      
    </TABLE>
    </BODY></HTML>
  </xsl:template>

  <xsl:template match="student">
    <FONT SIZE="6"><B>Student Transcript</B></FONT><P/>
    <FONT SIZE="4"><B>Name: <I>
      <xsl:value-of select="@name" />
      </I><BR/>
      ID: <I>
      <xsl:value-of select="@id" />
    </I></B></FONT><P/>
  </xsl:template>

  <xsl:template match="course">
    <TR>
    <TD><xsl:value-of select="course-name" /></TD>
    <TD><xsl:value-of select="grade" /></TD>
    <TD ALIGN="right"><xsl:value-of select="credits" /></TD>
    </TR>
  </xsl:template>
  
</xsl:stylesheet>

Output:

<HTML>
   <BODY><FONT SIZE="6"><B>Student Transcript</B></FONT><P></P><FONT SIZE="4"><B>Name: <I>name 1</I><BR>
                  ID: <I>STU12345</I></B></FONT><P></P>
      <HR>
      <TABLE ALIGN="left" BORDER="1" CELLPADDING="4">
         <TR>
            <TH>Course Name</TH>
            <TH>Grade</TH>
            <TH ALIGN="right">Credits</TH>
         </TR>
         <TR>
            <TD>course 2</TD>
            <TD>B+</TD>
            <TD ALIGN="right">3</TD>
         </TR>
         <TR>
            <TD>course 1</TD>
            <TD>A-</TD>
            <TD ALIGN="right">4</TD>
         </TR>
         <TR>
            <TD>Poetry for Physicists</TD>
            <TD>C+</TD>
            <TD ALIGN="right">5</TD>
         </TR>
         <TR>
            <TD>Physics for Poets</TD>
            <TD>A</TD>
            <TD ALIGN="right">10</TD>
         </TR>
      </TABLE>
   </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. Format output with HTML tags
6. Construct image name used by generated HTML in style sheet
7. html output method to make br tags come out as
8. Output html with frameset
9. Transformation of book information into XHTML with sorting
10. Output whole xhtml document
11. Add more format with html tags
12. Use blockquote to output value from xml
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.