| 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 |
<xsl:param name="citation.natbib.use" select="'0'"/> |
| 9 |
<xsl:param name="citation.natbib.options"/> |
| 10 |
<xsl:param name="citation.default.style"/> |
| 11 |
|
| 12 |
|
| 13 |
<!-- Loads the natbib package if required --> |
| 14 |
<xsl:template name="citation.setup"> |
| 15 |
<xsl:if test="$citation.natbib.use!='0'"> |
| 16 |
<xsl:text>\usepackage</xsl:text> |
| 17 |
<xsl:if test="$citation.natbib.options!=''"> |
| 18 |
<xsl:text>[</xsl:text> |
| 19 |
<xsl:value-of select="$citation.natbib.options"/> |
| 20 |
<xsl:text>]</xsl:text> |
| 21 |
</xsl:if> |
| 22 |
<xsl:text>{natbib} </xsl:text> |
| 23 |
</xsl:if> |
| 24 |
</xsl:template> |
| 25 |
|
| 26 |
|
| 27 |
<!-- Parses a cite macro like \citep[...][...] so that the bracket contents |
| 28 |
are converted safely to latex strings. Special care about the optional |
| 29 |
enclosing curly braces telling to use this content block [{...}] so that |
| 30 |
you can put some '[...]' in it. --> |
| 31 |
|
| 32 |
<xsl:template name="cite-parse"> |
| 33 |
<xsl:param name="macro"/> |
| 34 |
|
| 35 |
<xsl:variable name="brackets"> |
| 36 |
<xsl:choose> |
| 37 |
<xsl:when test="contains($macro,'[{') and |
| 38 |
contains(substring-after($macro,'[{'),'}]')"> |
| 39 |
<xsl:value-of select="'[{ }]'"/> |
| 40 |
</xsl:when> |
| 41 |
<xsl:when test="contains($macro,'[') and |
| 42 |
contains(substring-after($macro,'['),']')"> |
| 43 |
<xsl:value-of select="'[ ]'"/> |
| 44 |
</xsl:when> |
| 45 |
</xsl:choose> |
| 46 |
</xsl:variable> |
| 47 |
|
| 48 |
<xsl:choose> |
| 49 |
<xsl:when test="$brackets!=''"> |
| 50 |
<xsl:variable name="bs" select="substring-before($brackets,' ')"/> |
| 51 |
<xsl:variable name="be" select="substring-after($brackets,' ')"/> |
| 52 |
<xsl:variable name="opt" |
| 53 |
select="substring-before(substring-after($macro,$bs),$be)"/> |
| 54 |
<xsl:value-of select="substring-before($macro,$bs)"/> |
| 55 |
<xsl:value-of select="$bs"/> |
| 56 |
<!-- escape brackets content --> |
| 57 |
<xsl:call-template name="normalize-scape"> |
| 58 |
<xsl:with-param name="string" select="$opt"/> |
| 59 |
</xsl:call-template> |
| 60 |
<xsl:value-of select="$be"/> |
| 61 |
<xsl:call-template name="cite-parse"> |
| 62 |
<xsl:with-param name="macro" |
| 63 |
select="substring-after($macro,concat($bs,$opt,$be))"/> |
| 64 |
</xsl:call-template> |
| 65 |
</xsl:when> |
| 66 |
<xsl:otherwise> |
| 67 |
<xsl:value-of select="$macro"/> |
| 68 |
</xsl:otherwise> |
| 69 |
</xsl:choose> |
| 70 |
</xsl:template> |
| 71 |
|
| 72 |
|
| 73 |
<!-- Format a specific citation style from @role, a PI, or the default style. |
| 74 |
The citation styles are disabled if natbib is not used --> |
| 75 |
|
| 76 |
<xsl:template match="citation" mode="cite-style"> |
| 77 |
<!-- maybe a citation style from PI --> |
| 78 |
<xsl:variable name="pi"> |
| 79 |
<xsl:call-template name="pi.dblatex_citestyle"/> |
| 80 |
</xsl:variable> |
| 81 |
|
| 82 |
<xsl:choose> |
| 83 |
<xsl:when test="$citation.natbib.use='0'"> |
| 84 |
<xsl:text>\cite</xsl:text> |
| 85 |
</xsl:when> |
| 86 |
<xsl:when test="@role and (starts-with(@role,'\cite') or |
| 87 |
starts-with(@role,'\Cite'))"> |
| 88 |
<!-- a natbib citation style from @role --> |
| 89 |
<xsl:call-template name="cite-parse"> |
| 90 |
<xsl:with-param name="macro" select="@role"/> |
| 91 |
</xsl:call-template> |
| 92 |
</xsl:when> |
| 93 |
<xsl:when test="starts-with($pi,'\cite') or starts-with($pi,'\Cite')"> |
| 94 |
<!-- a natbib citation style from PI --> |
| 95 |
<xsl:call-template name="cite-parse"> |
| 96 |
<xsl:with-param name="macro" select="$pi"/> |
| 97 |
</xsl:call-template> |
| 98 |
</xsl:when> |
| 99 |
<xsl:when test="$citation.default.style!=''"> |
| 100 |
<!-- the default natbib citation style --> |
| 101 |
<xsl:call-template name="cite-parse"> |
| 102 |
<xsl:with-param name="macro" select="$citation.default.style"/> |
| 103 |
</xsl:call-template> |
| 104 |
</xsl:when> |
| 105 |
<xsl:otherwise> |
| 106 |
<xsl:text>\cite</xsl:text> |
| 107 |
</xsl:otherwise> |
| 108 |
</xsl:choose> |
| 109 |
</xsl:template> |
| 110 |
|
| 111 |
|
| 112 |
<xsl:template match="citation"> |
| 113 |
<xsl:apply-templates select="." mode="cite-style"/> |
| 114 |
<xsl:text>{</xsl:text> |
| 115 |
<!-- we take the raw text: we don't want that "_" becomes "\_" --> |
| 116 |
<xsl:value-of select="."/> |
| 117 |
<xsl:text>}</xsl:text> |
| 118 |
</xsl:template> |
| 119 |
|
| 120 |
</xsl:stylesheet> |