XslBricks is an XSLT/XSL-FO template library that serves three main purposes:
Create simple Serna XSL stylesheets for arbitrary XML documents very easy and rapidly (from 5 to 30 minutes).
XSL stylesheet that uses XslBricks produces not only XSL-FO, but also HTML.
XslBricks contains popular, reusable XSL modules, e.g. XHTML, CALS tables, etc.
XslBricks provides a set of templates that cover most popular set of decorations that HTML has. Therefore it has templates like: div, para, pre, h1, etc. Also it has modules for drawing images, lists and tables.
XslBricks is not the ultimate XSL library to build tricky stylesheets. It is good for quick and easy start-up. If you want to create a sophisticated template, create your own in place of simple XslBrick.
XslBricks is not the panacea to create mighty stylesheets for both XSL-FO and HTML. However, it works fine for simple use cases.
XslBricks idea is simple. There are two XSL libraries (backends), one for XSL-FO generation, and another one is for HTML. Each of the backends contains the same list of templates. Every template is called by its name. Here is an example:
Suppose we want element emphasis to be rendered as bold inline. In our stylesheet myspecs.xsl we write a template:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="emphasis"> <xsl:call-template name="bold.inline"/> </xsl:template> </xsl:stylesheet>
Now, if we want to generate XSL-FO, we include the XSL-FO backend:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:include href="path_to_xsl_bricks/fo/fo.xsl"/> <xsl:template match="emphasis"> <xsl:call-template name="bold.inline"/> </xsl:template> </xsl:stylesheet>
That's all! Now, you can open your document in Serna with this stylesheet, and emphasis elements will be shown bold, while all others will be rendered with default templates. The default templates, page setup templates, default parameters and all other things are included with fo.xsl from XSL-FO backend. If you want other elements to look pretty ASAP, just use other XslBricks templates!
Find a more detailed example you in sernaInstallationPath/examples/xslbricks. Try to open example.xml with myfoexample.xsl stylesheet, or produce HTML with myhtmlexample.xsl.
Once you have a simple stylesheet for your documents, you will probably want more complexity for your stylesheet. For example, section numbering, sophisticated itemized lists, etc. You can either add complexity within your stylesheet, or replace simple XslBrick with your code one after another.
It may happen that finally you will not use anything from XslBricks. But it allowed you to make quickly something that really works.
Usually you want to organize your XslBricks stylesheet in three files:
This file contains all the match rules, applied to your document. The templates there must be invariant, e.g. work for both XSL-FO and HTML backends, which is achieved by calling XslBricks templates that make the decoration job.
For example, myspecs.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:strip-space elements="*"/> <xsl:template match="emphasis"> <xsl:call-template name="bold.inline"/> </xsl:template> <xsl:template match="section"> <xsl:call-template name="div"/> </xsl:template> </xsl:stylesheet>
These specifications say only that emphasis will be rendered as bold inline area, and section as a plain block.
This is a very small file that includes the main specification module, and imports XSL-FO backend module. Default XSL-FO parameters or templates may also be overridden here. For example, myfodriver.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:import href="path_to_xsl_bricks/fo/fo.xsl"/> <xsl:include href="myspec.xsl"/> </xsl:stylesheet>
Just as XSL-FO driver module, a very small file that includes the main specification module, and imports HTML backend module. Default HTML parameters or templates may also be overridden here. For example, myhtmldriver.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:import href="path_to_xsl_bricks/html/html.xsl"/> <xsl:include href="myspec.xsl"/> </xsl:stylesheet>
Now you can:
Open your document with myspec.xsl stylesheet in Serna.
Produce PDF with your favourite XSL-FO formatter, e.g. with FOP:
fop.sh -xml mydocument.xml -xsl myfodriver.xsl -pdf mydocument.pdf
Produce HTML with your favourite XSLT processor, e.g with Saxon:
saxon.sh mydocument.xml myhtmldriver.xsl mydocument.html
List of all available XslBricks templates see in Reference Guide.
There are two general hub files that include all the FO and HTML backends: fo/fo.xsl, and html/html.xsl. Include this or the other file to your specifications for generating FO or HTML output.
Each (FO and HTML) backends introduce the same set of names and semantics of templates. However parameters for FO and HTML backends significantly differ.
Some files from both backends my be reused as a standalone module. The description of each file in both backends follow below:
Parameters that drive the area presentation and minor stylesheet behaviour.
Set up a very simple page sequence for FO, and miscellaneous head/meta content for HTML.
A default rule for showing elements that were not provided explicit templates. In particular, this helps to show documents with XslBricks stylesheet without any user-defined templates.
Inline area generating templates.
Block area generating templates.
Templates for drawing simple numbered and itemized lists.
Trivial table model templates.
This module is not included to fo/fo.xsl and html/html.xsl. You can reuse this module if your document supports XHTML table model.
The following modules constitute FO backend, and absent in HTML templates:
Easy switch for page height and width, determined with well-known page format identifiers.
Templates for processing common attributes.
generate plain inline area
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate inline area similarly to i HTML tag.
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate inline area similarly to b HTML tag.
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate bold-weight and italic-style inline area.
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate blue underlined inline area (similar to "hyper-links" in HTML browsers).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate monospace font inline area (similar to HTML code).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate smaller font inline area (similar to HTML small).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate larger font inline area (similar to HTML big).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate strike-through inline area (similar to HTML strike).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate underlined inline area (similar to HTML u).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate superscripted inline area (similar to HTML sup).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate subscripted inline area (similar to HTML sub).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate quoted inline area (similar to HTML q).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate inline image (similar inline HTML img).
Name | Default | Notes |
---|---|---|
url | empty string | a string with image url value |
generate arbitrary inline area.
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
background-color | empty string | background color name/code |
color | empty string | font color name/code |
vertical | empty string | baseline shift value |
font-{style|family|weight|size} | empty string | respective font properties |
text-decoration | empty string | text decoration value (e.g. underline) |
border-width | 0 | border width value |
border-color | black | border color value |
border-style | solid | border style value |
padding | empty-string | padding value |
generate paragraph (similar to HTML p).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
class | local-name() | a class identifier (HTML only) |
generate pre-formatted block (similar to HTML pre).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
class | local-name() | a class identifier (HTML only) |
generate a block (similar to HTML div).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
class | local-name() | a class identifier (HTML only) |
background-color | empty-string | background color code/name |
generate a paragraph block with arbitrary properties.
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
class | local-name() | a class identifier (HTML only) |
text-align | empty string | text align value |
background-color | empty-string | background color code/name |
color | empty string | font color name/code |
font-{style|family|weight|size} | empty string | respective font properties |
text-decoration | empty string | text decoration value (e.g. underline) |
padding | empty-string | padding value |
border-width | 0 | border width value |
border-color | black | border color value |
border-style | solid | border style value |
start-indent | empty string | start indent value |
end-indent | empty string | end indent value |
generate a pre block with arbitrary properties.
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
class | local-name() | a class identifier (HTML only) |
text-align | empty string | text align value |
background-color | empty-string | background color code/name |
color | empty string | font color name/code |
font-{style|family|weight|size} | empty string | respective font properties |
text-decoration | empty string | text decoration value (e.g. underline) |
padding | empty-string | padding value |
border-width | 0 | border width value |
border-color | black | border color value |
border-style | solid | border style value |
start-indent | empty string | start indent value |
end-indent | empty string | end indent value |
generate a div block with arbitrary properties.
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
class | local-name() | a class identifier (HTML only) |
text-align | empty string | text align value |
background-color | empty-string | background color code/name |
color | empty string | font color name/code |
font-{style|family|weight|size} | empty string | respective font properties |
text-decoration | empty string | text decoration value (e.g. underline) |
padding | empty-string | padding value |
border-width | 0 | border width value |
border-color | black | border color value |
border-style | solid | border style value |
start-indent | empty string | start indent value |
end-indent | empty string | end indent value |
generate header block (similar to HTML h1- h6).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
class | local-name() | a class identifier (HTML only) |
generate block image (similar to block HTML img).
Name | Default | Notes |
---|---|---|
url | empty string | a string with image url value |
height | empty string | height value |
width | empty string | width value |
generate block similar to HTML blockquote.
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
class | local-name() | a class identifier (HTML only) |
generate unordered list (similar to HTML ul).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
same as ul, but for lists within lists (padding-top is set to 0).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate ordered list (similar to HTML ol).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
generate table (similar to HTML table).
Name | Default | Notes |
---|---|---|
rows | child nodes with name row | If your table has row elements with name other than row, select these elements and pass them with this parameter. |
text-align | empty string | text align value |
background-color | empty-string | background color code/name |
color | empty string | font color name/code |
font-{style|family|weight|size} | empty string | respective font properties |
text-decoration | empty string | text decoration value (e.g. underline) |
padding | empty-string | padding value |
border-width | 0 | border width value |
border-color | black | border color value |
border-style | solid | border style value |
generate table row (similar to HTML tr).
Name | Default | Notes |
---|---|---|
cells | child nodes with name cell | If your table has cell elements with name other than cell, select these elements and pass them with this parameter. |
text-align | empty string | text align value |
background-color | empty-string | background color code/name |
color | empty string | font color name/code |
font-{style|family|weight|size} | empty string | respective font properties |
text-decoration | empty string | text decoration value (e.g. underline) |
border-width | 0 | border width value |
border-color | black | border color value |
border-style | solid | border style value |
generate table cell (similar to HTML td).
Name | Default | Notes |
---|---|---|
content | empty node-set | nodes for canned context |
span | empty string | number of columns spanned |
border-width | 0 | border width value |
border-color | black | border color value |
border-style | solid | border style value |
text-align | empty string | text align value |
padding | 2pt | padding value |
background-color | empty-string | background color code/name |
color | empty string | font color name/code |
font-{style|family|weight|size} | empty string | respective font properties |
text-decoration | empty string | text decoration value (e.g. underline) |