Debian Codegraph @

xsl/annotation.xsl

raw
1 <?xml version="1.0"?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 version="1.0">
4
5 <!--############################################################################
6 XSLT Stylesheet DocBook -> LaTeX
7 ############################################################################ -->
8
9 <!-- Annotation support mostly taken from the DocBook Project stylesheets. Only
10 The inlined output and the annotation content output are different (use
11 of attachfile macros, and latex file output). -->
12
13 <xsl:param name="annotation.support" select="'0'"/>
14
15 <xsl:key name="gid" match="*" use="generate-id()"/>
16
17 <!-- Content of the annotation file -->
18 <xsl:template match="annotation" mode="write">
19 <xsl:text>\documentclass</xsl:text>
20 <xsl:if test="$latex.class.options!=''">
21 <xsl:text>[</xsl:text>
22 <xsl:value-of select="$latex.class.options"/>
23 <xsl:text>]</xsl:text>
24 </xsl:if>
25 <xsl:text>{article}&#10;</xsl:text>
26 <xsl:text>\usepackage[T1]{fontenc}&#10;</xsl:text>
27 <xsl:text>\usepackage[latin1]{inputenc}&#10;</xsl:text>
28
29 <xsl:call-template name="font.setup"/>
30 <xsl:text>\usepackage[hyperlink]{</xsl:text>
31 <xsl:value-of select="$latex.style"/>
32 <xsl:text>}&#10;</xsl:text>
33
34 <xsl:call-template name="citation.setup"/>
35 <xsl:call-template name="lang.setup"/>
36
37 <xsl:text>\pagestyle{empty}&#10;</xsl:text>
38
39 <xsl:text>\begin{document}&#10;</xsl:text>
40 <xsl:apply-templates/>
41 <xsl:text>\end{document}&#10;</xsl:text>
42 </xsl:template>
43
44 <!-- Build the annotation latex file -->
45 <xsl:template match="annotation" mode="build.texfile">
46 <xsl:call-template name="write.text.chunk">
47 <xsl:with-param name="filename">
48 <xsl:text>annot_</xsl:text>
49 <xsl:value-of select="generate-id()"/>
50 <xsl:text>.rtex</xsl:text>
51 </xsl:with-param>
52 <xsl:with-param name="method" select="'text'"/>
53 <xsl:with-param name="content">
54 <xsl:apply-templates select="." mode="write"/>
55 </xsl:with-param>
56 <xsl:with-param name="encoding" select="$chunker.output.encoding"/>
57 </xsl:call-template>
58 </xsl:template>
59
60 <xsl:template match="annotation"/>
61
62 <!-- Show the annotations (if any) related to this element -->
63 <xsl:template match="*" mode="annotation.links">
64 <xsl:if test="$annotation.support != '0'">
65 <xsl:variable name="id" select="(@id|@xml:id)[1]"/>
66 <!-- do any annotations apply to the context node? -->
67
68 <xsl:variable name="aids">
69 <xsl:if test="$id!=''">
70 <xsl:for-each select="//annotation">
71 <xsl:if test="contains(concat(' ',@annotates,' '),concat(' ',$id,' '))">
72 <xsl:value-of select="generate-id()"/>
73 <xsl:text> </xsl:text>
74 </xsl:if>
75 </xsl:for-each>
76 </xsl:if>
77 <xsl:if test="normalize-space(@annotations) != ''">
78 <xsl:call-template name="annotations-pointed-to">
79 <xsl:with-param name="annotations"
80 select="normalize-space(@annotations)"/>
81 </xsl:call-template>
82 </xsl:if>
83 </xsl:variable>
84
85 <xsl:if test="$aids != ''">
86 <xsl:call-template name="apply-annotations-by-gid">
87 <xsl:with-param name="gids" select="normalize-space($aids)"/>
88 </xsl:call-template>
89 </xsl:if>
90 </xsl:if>
91 </xsl:template>
92
93 <xsl:template name="annotations-pointed-to">
94 <xsl:param name="annotations"/>
95 <xsl:choose>
96 <xsl:when test="contains($annotations, ' ')">
97 <xsl:variable name='a'
98 select="key('id', substring-before($annotations, ' '))"/>
99 <xsl:if test="$a">
100 <xsl:value-of select="generate-id($a)"/>
101 <xsl:text> </xsl:text>
102 </xsl:if>
103 <xsl:call-template name="annotations-pointed-to">
104 <xsl:with-param name="annotations"
105 select="substring-after($annotations, ' ')"/>
106 </xsl:call-template>
107 </xsl:when>
108 <xsl:otherwise>
109 <xsl:variable name='a'
110 select="key('id', $annotations)"/>
111 <xsl:if test="$a">
112 <xsl:value-of select="generate-id($a)"/>
113 <xsl:text> </xsl:text>
114 </xsl:if>
115 </xsl:otherwise>
116 </xsl:choose>
117 </xsl:template>
118
119 <xsl:template name="apply-annotations-by-gid">
120 <xsl:param name="gids"/>
121
122 <xsl:choose>
123 <xsl:when test="contains($gids, ' ')">
124 <xsl:variable name="gid" select="substring-before($gids, ' ')"/>
125 <xsl:apply-templates select="key('gid', $gid)"
126 mode="annotation-inline"/>
127 <xsl:call-template name="apply-annotations-by-gid">
128 <xsl:with-param name="gids" select="substring-after($gids, ' ')"/>
129 </xsl:call-template>
130 </xsl:when>
131 <xsl:otherwise>
132 <xsl:apply-templates select="key('gid', $gids)"
133 mode="annotation-inline"/>
134 </xsl:otherwise>
135 </xsl:choose>
136 </xsl:template>
137
138 <xsl:template match="annotation" mode="annotation-inline">
139 <xsl:text>\attachfile</xsl:text>
140 <xsl:if test="title">
141 <xsl:text>[</xsl:text>
142 <xsl:text>subject={</xsl:text>
143 <xsl:call-template name="normalize-scape">
144 <xsl:with-param name="string" select="title"/>
145 </xsl:call-template>
146 <xsl:text>}]</xsl:text>
147 </xsl:if>
148 <xsl:text>{</xsl:text>
149 <xsl:text>annot_</xsl:text>
150 <xsl:value-of select="generate-id()"/>
151 <xsl:text>.pdf</xsl:text>
152 <xsl:text>}&#10;</xsl:text>
153 </xsl:template>
154
155
156 <!-- load the needed package, and build the annotation files -->
157 <xsl:template name="annotation.setup">
158 <xsl:if test="$annotation.support != '0' and .//annotation">
159 <xsl:text>\usepackage{attachfile}&#10;</xsl:text>
160 <xsl:apply-templates select=".//annotation" mode="build.texfile"/>
161 </xsl:if>
162 </xsl:template>
163
164 </xsl:stylesheet>