Publishing Books Using XML Technologies
Dr. Herong Yang, Version 4.01

How XSL Technology Is Used in hyPub?

This section describes how to XSL transformation is used in hyPub to transforming book source files, adding page layout and formatting information in Web pages.

XSL technology is used in hyPub in many ways:

1. Splitting the book source file into Web page files, one file per chapter and section.

2. Adding layout and formatting information into Web page files.

3. Adding FO (Formatting Objects) for PDF generation.

Splitting the Book Source File

In order to publish a book on the Web, we need to split the book source file into smaller Web page files. One easy way to do this is to use an XSL template.

Here is a sample XSL template that can be used to split chapters out of the book source file:

 <xsl:template match="html/body/blockquote[@class='chapter']">
  <xsl:variable name="filename" select="concat(@id,'.html')"/>
  <redirect:write select="$filename">
   <html>
    <head>
     <title>__chapterTitle__</title>
     <meta name="description" content="__description__"/> 
     <meta name="keywords" content="__keywords__"/>
     <meta http-equiv="Content-Type" 
        content="text/html; charset=utf-8"/>
     <link rel="stylesheet" type="text/css" href="_hypub.css"/>
     <script type="text/javascript" src="_hypub.js">x=1;</script>
    </head>
    <body>
     <xsl:apply-templates />
    </body>
   </html>
  </redirect:write>
 </xsl:template>

Notice that a special Xalan-Java command "redirect:write" is used to write out output to new files.

Adding Layout Information to Web Pages

If you want to add some extra HTML code to create a Web page layout, you have to add that extra HTML code to all Web page files. One quick way to do this is to use XSL templates.

Here is a sample XSL template that can be used to add HTML table structure all Web page files:

 <xsl:template match="html/body">
   <body><div class="body">
<table class="frame" cellspacing="0" cellpadding="0">

<tr><td class="frameTop" colspan="3">
<script language="JavaScript">writeTop("Top");</script>
</td></tr>

<tr><td class="frameLeft">
<script language="JavaScript">writeLeft("Left");</script>
</td>
<td class="frameCenter">

    <xsl:apply-templates />

</td>

<td class="frameRight">
<script language="JavaScript">writeRight("Right");</script>
</td></tr>
<tr><td class="frameBottom" colspan="3">
<script language="JavaScript">writeBottom("Bottom");</script>
</td></tr>
</table>
   </div></body>
 </xsl:template>

Table of Contents

 About This Book

 Ideas on Publishing Books using XML

 Overview of hyPub - A Simple XML Publishing Tool

 Writing Book Contents in XHTML Source Files

Transforming Book Source Files with XSL Technology

 What Is XSL (eXtensible Style Language)?

 Introduction to XSL Templates?

 xalan - XSL Transformation Processing Engine

How XSL Technology Is Used in hyPub?

 Designing Web Page Layouts with Tables

 Controlling Web Page Appearance with CSS

 Sharing HTML Codes with JavaScript Files

 Generating Web Pages with hyPub

 Formatting Printable Documents with XSL-FO

 Generating PDF Documents with hyPub

 Areas of Future Improvements

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2007
How XSL Technology Is Used in hyPub?