forked from ivoa-std/ivoatex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vo-dml2ivoatex.xslt
349 lines (294 loc) · 12.4 KB
/
vo-dml2ivoatex.xslt
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:vo-dml="http://www.ivoa.net/xml/VODML/v1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<!--
XSLT to translate VO-dml/XML content to an ivoatex file
which can be inported to the primary document (${DOCNAME}.tex)
* provides content for some of the Title Page elements
* followed by the document body:
o Section for Model and each Package
o SubSection for each ObjectType, DataType, Enumeration, Primitive
o SubSubSection for each type 'attribute' (attribute, composition, reference)
-->
<xsl:output method="text" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />
<!-- Main Template -->
<xsl:template match="vo-dml:model">
<xsl:apply-templates select="." mode="TitlePage"/>
<xsl:apply-templates select="." mode="Section"/>
</xsl:template>
<!-- Title Page -->
<xsl:template match="vo-dml:model" mode="TitlePage">
% -------------------------------------------
% Items to substitute into the ivoatex document template.
%
%\ivoagroup{Data Model Working Group}
%\title{<xsl:value-of select="title"/>}
<xsl:call-template name="AuthorList">
<xsl:with-param name="text" select="author"/>
</xsl:call-template>
<xsl:variable name="text"><xsl:value-of select="previousVersion"/></xsl:variable>
<xsl:if test="string-length($text)">
<xsl:choose>
<xsl:when test="starts-with($text, 'http')">
%\previousversion[<xsl:value-of select="normalize-space($text)"/>]{}
</xsl:when>
<xsl:otherwise>
%\previousversion{<xsl:value-of select="normalize-space($text)"/>}
</xsl:otherwise>
</xsl:choose>
</xsl:if>
% -------------------------------------------
</xsl:template>
<!-- Section Template(s) -->
<xsl:template match="vo-dml:model" mode="Section">
\pagebreak
\section{Model: <xsl:value-of select="name"/> }
<xsl:variable name="model_prefix"><xsl:value-of select="name"/>:</xsl:variable>
% INSERT FIGURE HERE
%\begin{figure}[h]
%\begin{center}
% \includegraphics[width=\textwidth]{????.png}
% \caption{???}\label{fig:????}
%\end{center}
%\end{figure}
<xsl:apply-templates select="." mode="Description"/>
<xsl:for-each select="objectType|dataType">
<xsl:sort select="name"/>
<xsl:apply-templates select="." mode="SubSection"><xsl:with-param name="model_prefix" select="$model_prefix"/></xsl:apply-templates>
</xsl:for-each>
<xsl:apply-templates select="primitiveType" mode="SubSection"/>
<xsl:apply-templates select="enumeration" mode="SubSection"/>
<!-- check for packages -->
<xsl:apply-templates select="package" mode="Section"/>
</xsl:template>
<xsl:template match="package" mode="Section">
\pagebreak
\section{Package: <xsl:value-of select="vodml-id"/> }
% INSERT FIGURE HERE
%\begin{figure}[h]
%\begin{center}
% \includegraphics[width=\textwidth]{????.png}
% \caption{???}\label{fig:????}
%\end{center}
%\end{figure}
<xsl:apply-templates select="." mode="Description"/>
<xsl:for-each select="objectType|dataType">
<xsl:sort select="name"/>
<xsl:apply-templates select="." mode="SubSection"/>
</xsl:for-each>
<xsl:apply-templates select="primitiveType" mode="SubSection"/>
<xsl:apply-templates select="enumeration" mode="SubSection"/>
<!-- check for packages -->
<xsl:apply-templates select="package" mode="Section"/>
</xsl:template>
<!-- Subsection Template -->
<xsl:template match="objectType|dataType" mode="SubSection">
<xsl:param name="model_prefix"/>
\subsection{<xsl:value-of select="name"/><xsl:apply-templates select="." name="abstract"/>}
\label{sect:<xsl:value-of select="vodml-id"/>}
<xsl:apply-templates select="." mode="Description"/>
<xsl:if test="constraint[@xsi:type='vo-dml:SubsettedRole']">
<xsl:apply-templates select="constraint[@xsi:type='vo-dml:SubsettedRole']" mode="Subsets"/>
</xsl:if>
<xsl:if test="constraint[not(@xsi:type='vo-dml:SubsettedRole')]">
<xsl:apply-templates select="constraint[not(@xsi:type='vo-dml:SubsettedRole')]" mode="Constraints"/>
</xsl:if>
<xsl:for-each select="attribute|composition|reference">
<xsl:apply-templates select="." mode="SubSubSection"><xsl:with-param name="model_prefix" select="$model_prefix"/></xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<xsl:template match="primitiveType" mode="SubSection">
\subsection{<xsl:value-of select="name"/><xsl:apply-templates select="." name="abstract"/>}
\label{sect:<xsl:value-of select="vodml-id"/>}
<xsl:apply-templates select="." mode="Description"/>
</xsl:template>
<xsl:template match="enumeration" mode="SubSection">
\subsection{<xsl:value-of select="name"/><xsl:apply-templates select="." name="abstract"/>}
\label{sect:<xsl:value-of select="vodml-id"/>}
<xsl:apply-templates select="." mode="Description"/>
\noindent \underline{Enumeration Literals}
\vspace{-\parsep}
\small
\begin{itemize}
<xsl:for-each select="literal">
<xsl:variable name="cname">
<xsl:call-template name="Underscore">
<xsl:with-param name="text" select="name"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cvodml">
<xsl:call-template name="Underscore">
<xsl:with-param name="text" select="vodml-id"/>
</xsl:call-template>
</xsl:variable>
\item[\textbf{<xsl:value-of select="$cname"/>}]: \textbf{vodml-id:} <xsl:value-of select="$cvodml"/> \newline
\textbf{description:} <xsl:apply-templates select="." mode="Description"/>
</xsl:for-each>
\end{itemize}
\normalsize
</xsl:template>
<!-- SubSubsection Template(s) -->
<xsl:template match="attribute|composition|reference" mode="SubSubSection">
<xsl:param name="model_prefix"/>
<xsl:variable name="isOrdered">
<xsl:if test="./isOrdered"><xsl:value-of select="./isOrdered"/></xsl:if>
</xsl:variable>
<!-- generates internal reference to the element type in the PDF file -->
<xsl:variable name="dtype"><xsl:value-of select="datatype/vodml-ref"/></xsl:variable>
<xsl:variable name="typeWithRef">
<xsl:choose>
<xsl:when test="starts-with($dtype,'ivoa:')">\hyperref[sect:ivoa]{<xsl:value-of select="$dtype"/>}</xsl:when>
<xsl:when test="starts-with($dtype, $model_prefix)">\hyperref[sect:<xsl:value-of select="substring-after($dtype,':')"/>]{<xsl:value-of select="$dtype"/>}</xsl:when>
<xsl:otherwise><xsl:value-of select="$dtype"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="semanticconcept">
\subsubsection{<xsl:value-of select="../name"/>.<xsl:value-of select="name"/>}
\textbf{vodml-id: <xsl:value-of select="vodml-id"/>} \newline
\textbf{type: <xsl:value-of select="$typeWithRef"/>} \newline
\textbf{vocabulary: <xsl:value-of select="semanticconcept/vocabularyURI"/>} \newline
\textbf{multiplicity: <xsl:apply-templates select="multiplicity" mode="tostring"/>} \newline
</xsl:when>
<xsl:otherwise>
\subsubsection{<xsl:value-of select="../name"/>.<xsl:value-of select="name"/>}
\textbf{vodml-id: <xsl:value-of select="vodml-id"/>} \newline
\textbf{type: <xsl:value-of select="$typeWithRef"/>} \newline
\textbf{multiplicity: <xsl:apply-templates select="multiplicity" mode="tostring"/> <xsl:if test="string-length($isOrdered)"> (ordered)</xsl:if>} \newline
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="." mode="Description"/>
</xsl:template>
<!-- template to process Author list -->
<xsl:template name="AuthorList">
<xsl:param name="text"/>
<xsl:if test="string-length($text)">
<xsl:variable name="item"><xsl:value-of select="substring-before(concat($text,','),',')"/></xsl:variable>
%\author{<xsl:value-of select="normalize-space($item)"/>}
<xsl:call-template name="AuthorList">
<xsl:with-param name="text" select="substring-after($text, ',')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- template to process description fields -->
<xsl:template match="*" mode="Description">
<xsl:choose>
<xsl:when test="description">
<xsl:variable name="t1">
<xsl:apply-templates select="description" name="Strip"/>
</xsl:variable>
<xsl:variable name="t2">
<xsl:call-template name="Underscore">
<xsl:with-param name="text" select="$t1"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="t3">
<xsl:call-template name="Caret">
<xsl:with-param name="text" select="$t2"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="Ampersand">
<xsl:with-param name="text" select="$t3"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>[TODO add description!]</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- template for constraints (subsetting) -->
<xsl:template match="constraint" mode="Subsets">
\noindent \textbf{subset} \newline
\indent \textbf{role: <xsl:value-of select="role/vodml-ref"/>} \newline
\indent \textbf{type: <xsl:value-of select="datatype/vodml-ref"/>} \newline
</xsl:template>
<!-- template for constraints (simple constraint) -->
<xsl:template match="constraint" mode="Constraints">
\noindent \textbf{constraint} \newline
\indent \textbf{detail: <xsl:value-of select="../name"/>.<xsl:value-of select="description"/> }\newline
</xsl:template>
<!-- template to convert multiplicity node into simple string -->
<xsl:template match="multiplicity" mode="tostring">
<xsl:variable name="lower">
<xsl:choose>
<xsl:when test="minOccurs"><xsl:value-of select="minOccurs"/></xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="upper">
<xsl:choose>
<xsl:when test="not(maxOccurs)"><xsl:value-of select="'1'"/></xsl:when>
<xsl:when test="number(maxOccurs) < 0"><xsl:value-of select="'*'"/></xsl:when>
<xsl:otherwise><xsl:value-of select="maxOccurs"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$lower = $upper"><xsl:value-of select="$lower"/></xsl:when>
<xsl:otherwise><xsl:value-of select="concat($lower,'..',$upper)"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- template test for Abstract Type -->
<xsl:template match="objectType|dataType|enumeration|primitiveType" name="abstract">
<xsl:variable name="isAbstract"><xsl:value-of select="@abstract"/></xsl:variable>
<xsl:if test="$isAbstract='true'"> (Abstract)</xsl:if>
</xsl:template>
<!-- ************ Generic Utility Templates ****************** -->
<!-- template to strips leading/trailing white space from text -->
<xsl:template match="text()" name="Strip">
<xsl:value-of select='normalize-space()'/>
</xsl:template>
<!-- template to escape underscores in text -->
<!-- replace() is only in XSLT 2.0; got this substitute off the web and modified for this particular -->
<xsl:template name="Ampersand">
<xsl:param name="text"/>
<xsl:variable name="replace">&</xsl:variable>
<xsl:variable name="by">\&</xsl:variable>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="Ampersand">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="Caret">
<xsl:param name="text"/>
<xsl:variable name="replace">^</xsl:variable>
<xsl:variable name="by">\^</xsl:variable>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="Underscore">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="Underscore">
<xsl:param name="text"/>
<xsl:variable name="replace">_</xsl:variable>
<xsl:variable name="by">\_</xsl:variable>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="Underscore">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>