/
admonitions.xsl
107 lines (95 loc) · 4.14 KB
/
admonitions.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:f="http://docbook.org/xslt/ns/extension"
xmlns:m="http://docbook.org/xslt/ns/mode"
xmlns:t="http://docbook.org/xslt/ns/template"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:db="http://docbook.org/ns/docbook"
exclude-result-prefixes="f m fn db t"
version="2.0">
<xsl:template match="db:note|db:important|db:warning|db:caution|db:tip">
<xsl:choose>
<xsl:when test="$admonition.graphics">
<xsl:call-template name="t:graphical-admonition"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="t:nongraphical-admonition"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:function name="f:admon-graphic-width">
<xsl:param name="node"/>
<xsl:sequence select="'36pt'"/>
</xsl:function>
<xsl:function name="f:admon-graphic">
<xsl:param name="node"/>
<xsl:variable name="filename">
<xsl:value-of select="$admonition.graphics.path"/>
<xsl:choose>
<xsl:when test="$node/self::db:note">note</xsl:when>
<xsl:when test="$node/self::db:warning">warning</xsl:when>
<xsl:when test="$node/self::db:caution">caution</xsl:when>
<xsl:when test="$node/self::db:tip">tip</xsl:when>
<xsl:when test="$node/self::db:important">important</xsl:when>
<xsl:otherwise>note</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$admonition.graphics.extension"/>
</xsl:variable>
<xsl:sequence select="f:fo-external-image($filename)"/>
</xsl:function>
<xsl:template name="t:graphical-admonition">
<xsl:variable name="id" select="f:node-id(.)"/>
<xsl:variable name="graphic.width" select="f:admon-graphic-width(.)"/>
<fo:block id="{$id}"
xsl:use-attribute-sets="graphical.admonition.properties">
<fo:list-block provisional-distance-between-starts="{$graphic.width} + 18pt"
provisional-label-separation="18pt">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
<fo:external-graphic width="auto" height="auto"
content-width="{$graphic.width}" >
<xsl:attribute name="src" select="f:admon-graphic(.)"/>
</fo:external-graphic>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<xsl:if test="$admonition.textlabel or title or info/title">
<fo:block xsl:use-attribute-sets="admonition.title.properties">
<xsl:apply-templates select="." mode="m:object-title-markup">
<xsl:with-param name="allow-anchors" select="true()"/>
</xsl:apply-templates>
</fo:block>
</xsl:if>
<fo:block xsl:use-attribute-sets="admonition.properties">
<xsl:apply-templates/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</xsl:template>
<xsl:template name="t:nongraphical-admonition">
<xsl:variable name="id" select="f:node-id(.)"/>
<fo:block id="{$id}"
xsl:use-attribute-sets="nongraphical.admonition.properties">
<xsl:if test="$admonition.textlabel or db:title or db:info/db:title">
<fo:block keep-with-next.within-column='always'
xsl:use-attribute-sets="admonition.title.properties">
<xsl:apply-templates select="." mode="m:object-title-markup">
<xsl:with-param name="allow-anchors" select="true()"/>
</xsl:apply-templates>
</fo:block>
</xsl:if>
<fo:block xsl:use-attribute-sets="admonition.properties">
<xsl:apply-templates/>
</fo:block>
</fo:block>
</xsl:template>
<xsl:template match="db:note/db:title"></xsl:template>
<xsl:template match="db:important/db:title"></xsl:template>
<xsl:template match="db:warning/db:title"></xsl:template>
<xsl:template match="db:caution/db:title"></xsl:template>
<xsl:template match="db:tip/db:title"></xsl:template>
</xsl:stylesheet>