Products Downloads


French version


 

Description

This library groups several functions and macros used to define XSL-FO-style attribute groups and cascade them to the XSL-FO tags of a document similar to CSS (Cascading Style Sheet) with the HTML tags.

These directives must be called by specifying the namespace "hardisCSS":

<@hardisCSS.toolMacro parameters>...</@hardisCSS.toolMacro>
 ${ hardisCSS.toolFunction(...) }

 

CSS knowledge is required in order to use this library.

 

The macros and functions of this library can only be used with XSL-FO document templates defined entirely with the aid of hardisFo library macros (and not with the standard XSL-FO tags <fo:xxx>).

 

This library is used to define layout style rules. Unlike HTML, XSL-FO does not have its own style definition language: XSL-FO style rules will be based directly on XSL-FO tag attributes (e.g. font-family, padding, text-align, etc.).

 

Each style rule selector must be written using the CSS 2.1. specification. Certain HTML-specific selectors or child selectors are not supported, namely:

  • Pseudo-classes (e.g. :hover, :visited, :focus, :nth-last-of-type(), :last-child, etc.),
  • Pseudo-elements (e.g. ::after, ::first-letter, etc.).

 

The other selectors are supported, namely:

  • (Tag) element selectors. For example "foBlock" for all hardisFo.foBlock elements of the document.
  • Class selectors. For example ".greenClass". hardisFo macros representing an XSL-FO tag have a "class" attribute enabling a class to be associated with it.
  • ID (identifier) selectors. For example "#totalBlock". hardisFo macros representing an XSL-FO tag have an "id" attribute enabling an identifier to be associated with it.
  • The universal selector "*".
  • Attribute selectors. For example [break-after], [character=C].
  • Combination selectors. For example A, B or A B or A > B or A + B or A ~ B where A and B are selectors.

 

When processing a template, all the "rule" macros defining the XSL-FO style rules must be executed before the XSL-FO document the FreeMarker engine must know the style rules before processing the XSL-FO document): the "rule" macros need to be placed "before" the hardisFo.foRoot macro either by inserting them in the header (between the XML prolog and the hardisFo.foRoot macro) in the main template (by analogy with CSS, in a <style> tag contained in the <head> tag), or by placing them in an .ftlx sub-template, which will be included (via the <#include> directive) in the header of the main template (by analogy with CSS, in a style sheet included via the <link> tag).

↑ Top of page

Template example

<?xml version="1.0" encoding="utf-8"?>
<#-- CSS rules declaration -->
<@hardisCSS.rule selectors = ".title" >
	<@hardisCSS.declaration property = "font-size" >14pt</@hardisCSS.declaration>
	<@hardisCSS.declaration property = "border" >solid red 3pt</@hardisCSS.declaration>
	<@hardisCSS.declaration property = "text-align" >center</@hardisCSS.declaration>
	<@hardisCSS.declaration property = "fox:border-radius" >5pt</@hardisCSS.declaration>
</@hardisCSS.rule>
<@hardisCSS.rule selectors = "foBlock foInline" >
	<@hardisCSS.declaration property = "text-transform" >uppercase</@hardisCSS.declaration>
</@hardisCSS.rule>
<@hardisCSS.rule selectors = "#specialText" >
	<@hardisCSS.declaration property = "color" >green</@hardisCSS.declaration>
</@hardisCSS.rule>
<#-- XSL-FO document using hardisFo macros -->
	<@hardisFo.foRoot xmlns\:fox = "http://xmlgraphics.apache.org/fop/extensions" >
		<@hardisFo.foLayoutMasterSet>
			<@hardisFo.foSimplePageMaster masterName = "sampleLayout" pageHeight = "29.7cm" pageWidth = "21cm" marginTop = "2.5cm" marginBottom = "2.5cm" marginLeft = "1cm" marginRight = "1cm" >
				<@hardisFo.foRegionBody/>
			</@hardisFo.foSimplePageMaster>
	</@hardisFo.foLayoutMasterSet>
	<@hardisFo.foPageSequence masterReference = "sampleLayout" >
		<@hardisFo.foFlow flowName = "xsl-region-body" >
				<@hardisFo.foBlock class = "title" > Sample of CSS use</@hardisFo.foBlock>
				<@hardisFo.foBlock>
					In this block, every inline text is <@hardisFo.foInline>uppercase</@hardisFo.foInline>
				<@hardisFo.foBlock>
					This is the <@hardisFo.foInline>second</@hardisFo.foInline> sentence.
				</@hardisFo.foBlock>
				<@hardisFo.foBlock>
					This is the third sentence with a particular <@hardisFo.foInline id = "specialText" >inline text</@hardisFo.foInline>.
				</@hardisFo.foBlock>
			</@hardisFo.foBlock>
		</@hardisFo.foFlow>
	</@hardisFo.foPageSequence>
</@hardisFo.foRoot>

↑ Top of page

Macros

declaration

Associates a value with an XSL-FO tag attribute name. The attribute name is the value of the "property" parameter and the attribute value is the tag content. The attribute value must correspond to the attribute type as defined in the Extensible Stylesheet Language (XSL) Version 1.1 specification (click here for more details). By analogy with CSS, this macro defines a CSS declaration (CSS property: value).

This macro can only be used inside the "rule" macro.

Like in CSS, the XSL-FO attribute value can be suffixed with "!important": this indicates that this attribute (and its value) has a higher priority than any other attribute of the same name (and of a different value) from another applicable rule on a given tag.


Empty directive: No

 

Parameters

String

property

XSL-FO tag attribute name

Mandatory

 

For example

<#-- Associate the "green" value with the color attribute -->
<@hardisCSS.declaration property="color">green</@hardisCSS.declaration>
<#-- Associate the "14p" value with the font-size attribute -->
<@hardisCSS.declaration property="font-size">14pt</@hardisCSS.declaration>
<#-- Associate the "solid red 10pt" value with the "fox:border-radius" attribute -->
<@hardisCSS.declaration property="fox:border-radius">solid red 10pt</@hardisCSS.declaration>
<#-- Associate the "#a1e2bc" value with the "background-color" attribute with a stronger priority -->
<@hardisCSS.declaration property="background-color">#a1e2bc !important</@hardisCSS.declaration>

↑ Top of page

rule

Defines an XSL-FO-style rule. By analogy with CSS, a rule is defined by:

  • selectors,
  • a block or set of declarations.

 

With this macro, the selectors are defined by the "selectors" parameter. Each declaration is defined by a call to the "declaration" macro, which should be found inside the "declaration" macro.

 

Example of syntax:

<#-- Defines a rule associated with the .greenTitleClass selector -->
<@hardisCSS.rule selectors=".greenTitleClass">
<#-- which contains 3 declarations -->
<@hardisCSS.declaration property="text-align">center</@hardisCSS.declaration>
<@hardisCSS.declaration property="font-style">italic</@hardisCSS.declaration>
<@hardisCSS.declaration property="color">green</@hardisCSS.declaration>
</@hardisCSS.rule>

 


Empty directive: No


Parameters

String

selectors

CSS syntax rule selector or set of selectors

Mandatory


For example

<@hardisCSS.rule selectors=".class1">
<@hardisCSS.declaration property="color">red</@hardisCSS.declaration>
</@hardisCSS.rule>
<@hardisCSS.rule selectors=".class2">
<@hardisCSS.declaration property="background-color">pink</@hardisCSS.declaration>
<@hardisCSS.declaration property="color">blue</@hardisCSS.declaration>
</@hardisCSS.rule>
<@hardisCSS.rule selectors=".class2 > .class1">
<@hardisCSS.declaration property="background-color">aqua</@hardisCSS.declaration>
</@hardisCSS.rule>
<@hardisCSS.rule selectors=".class3 , .class4 > foBlock ">
<@hardisCSS.declaration property="display-align">center</@hardisCSS.declaration>
<@hardisCSS.declaration property="text-align">center</@hardisCSS.declaration>
</@hardisCSS.rule>
 

Functions

None.

↑ Top of page

  • Aucune étiquette