Unit Test: xref.004.xml
1. Customize individual cross references
Most kinds of generated text apply across an entire document: do you want chapters to be numbered? Should generated text be in English or French? What form should numbered and unnumbered sections have? The mechanisms for changing this generated control the formatting of cross references.
But it’s sometimes desirable to be able to change the format of a cross reference on an individual basis (that is, on the basis of the context in which the reference occurs, not the nature of what is referenced). You might, for example, want to shorten a cross reference to just a label if it’s already been referenced several times.
Consider a cross reference to a section:
see <xref linkend="syntax-highlighting"/>
.
In the localization style of this guide, that is rendered like this:
see Section 2, “Syntax highlighting”.
The text that is generated by a cross reference can be customized
for individual references with the xrefstyle
attribute.
For example,
see <xref linkend="syntax-highlighting" xrefstyle="%l"/>
,
will produce a result like this:
see 2.
You can use the %c
, %l
and
%p
values in
xrefstyle
. There is also an additional
%label
for the full Label, which is
the component`s name and number. The use of these percent-values is
explained in the following table, where all cross references target
the next section called Syntax highlighting.
Value of xref/@xrefstyle | Result | Remark |
---|---|---|
(@xrefstyle is absent) | Section 2, “Syntax highlighting” | Default |
%c | Syntax highlighting | Content, e. g. title of target |
%l | 2 | Label, ususally the targets number. |
%label | Section 2 | The full Label, ususally the targets number and name. |
%p | Page number in print output (PDF). Displayed as “#” in HTML. | |
%label (%c) | Section 2 (Syntax highlighting) | You can use different %-letters and combine with text |
Legacy values for xrefstyle
In order to support migration from XSLT 1.0 Stylesheets, xslTNG supports the
template:
Syntax which is explained in
“Customizing
with an xrefstyle attribute / Using template:” in
the book “DocBook XSL: The Complete
Guide”. This is summarized in the following
table.
Value of xref/@xrefstyle | Result | Remark |
---|---|---|
template:the chapter numbered %n | the chapter numbered 2 | XSLT 1.0 Legacy Syntax |
template:the chapter called %t | the chapter called Syntax highlighting | XSLT 1.0 Legacy Syntax |
2. Syntax highlighting
Program listings and other verbatim environments can be “syntax highlighted”, that is, the significant tokens in the listing can be colored differently (keywords in red, quoted strings in blue, that sort of thing).