| 1 |
<?xml version='1.0'?> |
| 2 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> |
| 3 |
|
| 4 |
<!--############################################################################ |
| 5 |
XSLT Stylesheet DocBook -> LaTeX |
| 6 |
############################################################################ --> |
| 7 |
|
| 8 |
<!-- Figure parameters --> |
| 9 |
<xsl:param name="figure.title.top">0</xsl:param> |
| 10 |
<xsl:param name="figure.anchor.top" select="$figure.title.top"/> |
| 11 |
<xsl:param name="figure.default.position">[htbp]</xsl:param> |
| 12 |
<xsl:param name="figure.default.align">center</xsl:param> |
| 13 |
|
| 14 |
|
| 15 |
<xsl:template match="figure"> |
| 16 |
<xsl:text>\begin{figure}</xsl:text> |
| 17 |
<!-- figure placement preference --> |
| 18 |
<xsl:choose> |
| 19 |
<xsl:when test="@floatstyle != ''"> |
| 20 |
<xsl:value-of select="@floatstyle"/> |
| 21 |
</xsl:when> |
| 22 |
<xsl:when test="not(@float) or (@float and @float='0')"> |
| 23 |
<xsl:text>[H]</xsl:text> |
| 24 |
</xsl:when> |
| 25 |
<xsl:otherwise> |
| 26 |
<xsl:value-of select="$figure.default.position"/> |
| 27 |
</xsl:otherwise> |
| 28 |
</xsl:choose> |
| 29 |
<xsl:text> </xsl:text> |
| 30 |
|
| 31 |
<!-- title caption before the image --> |
| 32 |
<xsl:apply-templates select="." mode="caption.and.label"> |
| 33 |
<xsl:with-param name="position.top" select="1"/> |
| 34 |
</xsl:apply-templates> |
| 35 |
|
| 36 |
<!-- <xsl:text> \centering </xsl:text> --> |
| 37 |
<xsl:call-template name="figure.begin"/> |
| 38 |
<xsl:apply-templates select="*[not(self::title)]"/> |
| 39 |
<xsl:call-template name="figure.end"/> |
| 40 |
|
| 41 |
<!-- title caption after the image --> |
| 42 |
<xsl:apply-templates select="." mode="caption.and.label"> |
| 43 |
<xsl:with-param name="position.top" select="0"/> |
| 44 |
</xsl:apply-templates> |
| 45 |
<xsl:text>\end{figure} </xsl:text> |
| 46 |
</xsl:template> |
| 47 |
|
| 48 |
|
| 49 |
<xsl:template match="informalfigure"> |
| 50 |
<xsl:call-template name="figure.begin"/> |
| 51 |
<xsl:apply-templates/> |
| 52 |
<xsl:call-template name="figure.end"/> |
| 53 |
</xsl:template> |
| 54 |
|
| 55 |
|
| 56 |
<xsl:template name="figure.begin"> |
| 57 |
<xsl:param name="align" select="$figure.default.align"/> |
| 58 |
<xsl:value-of select="concat(' \begin{',$align,'} ')"/> |
| 59 |
</xsl:template> |
| 60 |
|
| 61 |
<xsl:template name="figure.end"> |
| 62 |
<xsl:param name="align" select="$figure.default.align"/> |
| 63 |
<xsl:value-of select="concat(' \end{',$align,'} ')"/> |
| 64 |
</xsl:template> |
| 65 |
|
| 66 |
|
| 67 |
<!-- Caption and label must be handled at the same time because \caption |
| 68 |
increments the label counter and puts an anchor. Therefore putting a |
| 69 |
label *before* the related caption needs to manipulate the counters |
| 70 |
|
| 71 |
Limitation: it is not possible to put a caption on the top, and the |
| 72 |
label anchor at the bottom. The first caption anchor at the top prevails. |
| 73 |
Putting a label before the caption is possible because the |
| 74 |
duplicated label name when \caption is called is ignored |
| 75 |
(see latex warnings) --> |
| 76 |
|
| 77 |
<xsl:template match="figure" mode="caption.and.label"> |
| 78 |
<xsl:param name="position.top"/> |
| 79 |
|
| 80 |
<xsl:choose> |
| 81 |
<xsl:when test="$figure.title.top='1'"> |
| 82 |
|
| 83 |
<xsl:if test="$position.top='1'"> |
| 84 |
<xsl:text>\caption</xsl:text> |
| 85 |
<xsl:apply-templates select="title" mode="format.title"/> |
| 86 |
</xsl:if> |
| 87 |
|
| 88 |
<xsl:if test="$figure.anchor.top=$position.top"> |
| 89 |
<xsl:call-template name="label.id"> |
| 90 |
<xsl:with-param name="object" select="."/> |
| 91 |
</xsl:call-template> |
| 92 |
</xsl:if> |
| 93 |
|
| 94 |
</xsl:when> |
| 95 |
<xsl:when test="$figure.title.top='0'"> |
| 96 |
|
| 97 |
<xsl:choose> |
| 98 |
<xsl:when test="$position.top='1'"> |
| 99 |
<xsl:if test="$figure.anchor.top='1'"> |
| 100 |
<xsl:text>\refstepcounter{figure}</xsl:text> |
| 101 |
<xsl:call-template name="label.id"> |
| 102 |
<xsl:with-param name="object" select="."/> |
| 103 |
</xsl:call-template> |
| 104 |
</xsl:if> |
| 105 |
</xsl:when> |
| 106 |
|
| 107 |
<xsl:otherwise> |
| 108 |
<xsl:if test="$figure.anchor.top='1'"> |
| 109 |
<xsl:text>\addtocounter{figure}{-1}</xsl:text> |
| 110 |
</xsl:if> |
| 111 |
|
| 112 |
<xsl:text>\caption</xsl:text> |
| 113 |
<xsl:apply-templates select="title" mode="format.title"/> |
| 114 |
|
| 115 |
<xsl:if test="$figure.anchor.top='0'"> |
| 116 |
<xsl:call-template name="label.id"> |
| 117 |
<xsl:with-param name="object" select="."/> |
| 118 |
</xsl:call-template> |
| 119 |
</xsl:if> |
| 120 |
</xsl:otherwise> |
| 121 |
</xsl:choose> |
| 122 |
</xsl:when> |
| 123 |
</xsl:choose> |
| 124 |
</xsl:template> |
| 125 |
|
| 126 |
</xsl:stylesheet> |
| 127 |
|