Named styles are specified in an XML file conforming to the styles.xsd
schema. The recommended extension for this kind of file is ".xfc
". Simple example, sample0.xfc
:
<styles xmlns="http://www.xmlmind.com/foconverter/xsl/extensions"
xmlns:xfc="http://www.xmlmind.com/foconverter/xsl/extensions">
<text-style name="Warning" font-weight="bold" color="red" />
</styles>
The location of the .xfc
file containing the style definitions must be passed as the value of the styles
parameter to XFC, for example by the means of the /sty
command-line option.
The named styled is referenced by the means of the xfc:user-style
extension attribute. Simple example, sample0.fo
:
<fo:block>During take-off and landing,
<fo:inline xfc:user-style="Warning">always keep your seat belt
fastened</fo:inline>.</fo:block>
Command-line example:
fo2docx /sty sample0.xfc sample0.fo sample0.docx
If set on a fo:inline
element, attribute xfc:user-style
must reference the name of an existing xfc:text-style
element. If set on a fo:block
element, attribute xfc:user-style
must reference the name of an existing xfc:paragraph-style
element.
The following fo:inline
element
<fo:inline xfc:user-style="Warning">always keep your seat belt
fastened</fo:inline>
is rendered by the target word processor exactly as if it was specified as[10]:
<fo:inline font-weight="bold" color="red">always keep your seat belt
fastened</fo:inline>
The main difference between the two specifications is that, with the first specification, the user of the word processor may use the style editor to specify, for example, that all warning text runs are to be rendered in orange rather than in red.
The second specification is said to generate direct style properties on the resulting text run. When this is the case, there is no way for the user of the word processor to use the style editor to specify that all warning text runs are to be rendered in orange rather than in red.
It's of course possible, and often useful, to mix xfc:user-style
with standard XSL-FO attributes:
In the following example, redundant attributes such as font-weight="bold"
an color="red"
(already contained in the "Warning" text-style
) are simply ignored by XFC:
<fo:inline xfc:user-style="Warning"
font-weight="bold" color="red">always keep your seat belt
fastened</fo:inline>
This is an important feature as we'll see it in Section 5, “Adding named styles support to an existing XSLT stylesheet”.
With the following snippet, the resulting warning text run will be rendered using a bold, italic, font and a red color:
<fo:inline xfc:user-style="Warning"
font-style="italic">always keep your seat belt
fastened</fo:inline>
With the following snippet, the resulting warning text run will be rendered using a bold font and a blue color:
<fo:inline xfc:user-style="Warning"
color="blue">always keep your seat belt
fastened</fo:inline>
Directly specified attribute color="blue"
overrides the color="red"
attribute found in the "Warning" text-style
.
With the following snippet, the resulting warning text run will be rendered using a bold, italic, larger font and a red color:
<fo:block font-weight="normal"
font-style="italic" font-size="larger">During take-off and landing,
<fo:inline xfc:user-style="Warning">always keep your seat belt
fastened</fo:inline>.</fo:block>
Attributes font-weight="normal"
, font-style="italic"
and font-size="larger"
are inherited by the fo:inline
from its parent fo:block
. However, inherited attribute font-weight="normal"
has no effect on the resulting warning text run as the "Warning" text-style
contains attribute font-weight="bold"
.
[10] XFC named styles are similar to XSLT xsl:attribute-set
s. However xsl:attribute-set
elements are processed by the XSLT engine, while text-style
and paragraph-style
elements are processed by XFC (which is an XSL-FO processor, and not an XSLT engine).