source: documentation/trunk/tutorials/processing/common.xsl@ 25472

Last change on this file since 25472 was 25472, checked in by ak19, 12 years ago
  1. ApplyXSLT takes an additional parameter: the Greenstone major version number, or sets this to 2 if none is provided. This is then passed onto the XSLT files. 2. generate-html.sh/bat will pass any commandline parameters on to ApplyXSLT.java. 3. Simplified the generate-html.bat file with a for loop to avoid code duplication. 4. The MajorVersion element will now be processed by processing/common.xsl: anything in a MajorVersion element whose number matches the Greenstone major version number specified to generate-html.sh/bat (or ApplyXSLT.java) will be output to html, if the MajorVersion number does not match, it won't be output.
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:dict="http://xml.apache.org/xalan/java/Dictionary"
5 exclude-result-prefixes="dict">
6
7 <!--The following strips newlines introduced by elements, in particular introduced around the MajorVersion template match
8 See http://stackoverflow.com/questions/3265244/removing-blank-lines-in-xslt
9 and http://msdn.microsoft.com/en-us/library/ms256107.aspx -->
10 <xsl:strip-space elements="*"/>
11
12 <xsl:variable name="diction" select="dict:new('en')"/>
13
14 <xsl:template match="Heading">
15 <p><b><i><xsl:apply-templates select="Text"/></i></b></p>
16 </xsl:template>
17
18 <xsl:template match="NumberedItem">
19 <ol><xsl:attribute name="start"><xsl:number/></xsl:attribute>
20 <li>
21 <xsl:for-each select="node()">
22 <xsl:apply-templates select="."/><!--<xsl:if test="self::Text and preceding-sibling::Text"><p/></xsl:if>-->
23 </xsl:for-each>
24 </li>
25 </ol>
26 </xsl:template>
27
28 <xsl:template match="BulletList">
29 <ul style="list-style-type: disc;">
30 <xsl:for-each select="Bullet">
31 <li><xsl:apply-templates/></li>
32 </xsl:for-each>
33 </ul>
34 <p/>
35 </xsl:template>
36
37 <xsl:template match="Text">
38 <xsl:apply-templates/><xsl:if test="parent::Content|parent::NumberedItem"><p/></xsl:if>
39 </xsl:template>
40
41 <xsl:template match="Comment">
42 <p><i><xsl:apply-templates/></i></p>
43 </xsl:template>
44
45 <xsl:template match="Indent">
46 <p><div style="margin-left: 2em;">
47 <xsl:apply-templates/>
48 </div></p>
49 </xsl:template>
50
51 <xsl:template match="span|img|table|b|br|td|tr|u">
52 <xsl:copy><xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
53 <xsl:apply-templates/>
54 </xsl:copy>
55 </xsl:template>
56
57 <xsl:template match="i">
58 <xsl:choose>
59 <xsl:when test="ancestor::Comment">
60 <span style="font-style:normal;"><xsl:apply-templates/></span>
61 </xsl:when>
62 <xsl:otherwise>
63 <i><xsl:apply-templates/></i>
64 </xsl:otherwise>
65 </xsl:choose>
66 </xsl:template>
67
68 <xsl:template match="Link">
69 <xsl:choose>
70 <xsl:when test="not(parent::Text)">
71 <p><div style="margin-left: 2em;">
72 <a><xsl:attribute name="href"><xsl:choose><xsl:when test="@url"><xsl:value-of select="@url"/></xsl:when><xsl:otherwise><xsl:value-of select="."/></xsl:otherwise></xsl:choose></xsl:attribute><xsl:value-of select="."/></a>
73 </div></p>
74 </xsl:when>
75 <xsl:otherwise>
76 <a><xsl:attribute name="href"><xsl:choose><xsl:when test="@url"><xsl:value-of select="@url"/></xsl:when><xsl:otherwise><xsl:value-of select="."/></xsl:otherwise></xsl:choose></xsl:attribute><xsl:value-of select="."/></a>
77 </xsl:otherwise>
78 </xsl:choose>
79 </xsl:template>
80
81 <xsl:template match="TutorialRef">
82 <xsl:variable name="ref" select="@id"/>
83 <a href="{@id}.htm"><xsl:value-of select="/TutorialList/Tutorial[@id=$ref]/Title/Text"/></a>
84 </xsl:template>
85
86 <xsl:template match="Path">
87 <xsl:choose>
88 <xsl:when test="not(parent::Text)">
89 <p><div style="margin-left: 2em;">
90 <i><xsl:value-of select="."/></i>
91 </div></p>
92 </xsl:when>
93 <xsl:otherwise>
94 <i><xsl:value-of select="."/></i>
95 </xsl:otherwise>
96 </xsl:choose>
97 </xsl:template>
98
99
100 <xsl:template match="Menu">
101 <xsl:choose>
102 <xsl:when test="not(parent::Text)">
103 <p><div style="margin-left: 2em;">
104 <b><xsl:apply-templates/></b>
105 </div></p>
106 </xsl:when>
107 <xsl:otherwise>
108 <b><xsl:apply-templates/></b>
109 </xsl:otherwise>
110 </xsl:choose>
111 </xsl:template>
112
113
114 <xsl:template match="Format|Command">
115 <xsl:choose>
116 <xsl:when test="not(parent::Text)">
117 <p><div style="margin-left: 2em;">
118 <small><tt><xsl:apply-templates/></tt></small>
119 </div></p>
120 </xsl:when>
121 <xsl:otherwise>
122 <small><tt><xsl:apply-templates/></tt></small>
123 </xsl:otherwise>
124 </xsl:choose>
125 </xsl:template>
126
127 <xsl:template match="Indent">
128 <div style="margin-left: 2em;">
129 <xsl:apply-templates/>
130 </div>
131 <p/>
132 </xsl:template>
133
134 <xsl:template match="highlight">
135 <span style="background-color: lightgrey;"><xsl:apply-templates/></span>
136 </xsl:template>
137
138<!-- old question and answer templates
139 <xsl:template match="Question">
140 <span style="float:right;text-align:right;"><i><xsl:apply-templates select="following-sibling::Answer" mode="output"/></i></span><xsl:apply-templates/>
141 </xsl:template>
142
143 <xsl:template match="Answer" mode="output">
144 <xsl:apply-templates/>
145 </xsl:template>
146-->
147
148 <!-- Don't output the Answers, or the Updated tags-->
149 <xsl:template match="Answer|Updated"/>
150
151 <!-- the supplementary bits -->
152 <xsl:template match="Prerequisite" mode="individual">
153 <xsl:variable name="ref" select="@id"/>
154 <xsl:apply-templates select="/TutorialList/SupplementaryText/Text[@id='prereq']"/><xsl:text> </xsl:text><a href="{@id}.htm"><xsl:value-of select="/TutorialList/Tutorial[@id=$ref]/Title/Text"/></a><br/>
155 </xsl:template>
156
157 <xsl:template match="Prerequisite" mode="combined">
158 <xsl:variable name="ref" select="@id"/>
159 <xsl:apply-templates select="/TutorialList/SupplementaryText/Text[@id='prereq']"/><xsl:text> </xsl:text><a href="#{@id}"><xsl:value-of select="/TutorialList/Tutorial[@id=$ref]/Title/Text"/></a><br/>
160 </xsl:template>
161
162 <xsl:template match="Version">
163 <xsl:apply-templates select="/TutorialList/SupplementaryText/Text[@id='original']"/><xsl:text> </xsl:text><xsl:value-of select="@initial"/><br/>
164 <xsl:if test="not(@current=@initial)"><xsl:apply-templates select="/TutorialList/SupplementaryText/Text[@id='current']"/><xsl:text> </xsl:text><xsl:value-of select="@current"/></xsl:if>
165 </xsl:template>
166
167 <!-- Do not process any elements marked with MajorVersion and whose version does not
168 specifically match the requested greenstone major version (2 or 3) -->
169 <!--To avoid multiple lines of whitespace around output, use
170 <xsl:for-each select="node()"><xsl:apply-templates/></xsl:for-each>
171 This outputs the contents on its own separate line.
172 To avoid thinking about unnecessary newlines and to avoid omitting any sub-xml items
173 that need to be processed, we can instead have the following at the top of the file:
174 <xsl:strip-space elements="*"/> -->
175 <xsl:template match="MajorVersion">
176 <xsl:if test="$gs-major-version=@number">
177 <xsl:apply-templates/>
178 </xsl:if>
179 </xsl:template>
180
181 <xsl:template name="SampleFiles">
182 <xsl:param name="mode">web</xsl:param>
183 <xsl:choose><xsl:when test="$mode='wiki'">
184 <xsl:apply-templates select="/TutorialList/SupplementaryText/Text[@id='sample']"/><xsl:text> </xsl:text><xsl:for-each select="SampleFiles"><a href="../sample_files/{@folder}.zip"><xsl:value-of select="@folder"/>.zip</a><xsl:text> </xsl:text></xsl:for-each><br/>
185 </xsl:when>
186 <xsl:otherwise>
187 <xsl:apply-templates select="/TutorialList/SupplementaryText/Text[@id='sample']"/><xsl:text> </xsl:text><xsl:for-each select="SampleFiles"><xsl:value-of select="@folder"/><xsl:text> </xsl:text></xsl:for-each><br/>
188 </xsl:otherwise>
189 </xsl:choose>
190 </xsl:template>
191
192 <xsl:template name="IndexLink">
193 <xsl:param name="mode">individual</xsl:param>
194 <xsl:choose><xsl:when test="$mode='individual'">
195 <a href="index.html"><xsl:apply-templates select="/TutorialList/SupplementaryText/Text[@id='index']"/></a><br/>
196 </xsl:when>
197 <xsl:otherwise>
198 <a href="#index"><xsl:apply-templates select="/TutorialList/SupplementaryText/Text[@id='index']"/></a><br/>
199 </xsl:otherwise>
200 </xsl:choose>
201
202 </xsl:template>
203
204 <xsl:template name="WikiLink">
205 <a href="http://greenstone.sourceforge.net/wiki/index.php/Tutorial_exercises"><xsl:apply-templates select="/TutorialList/SupplementaryText/Text[@id='wiki']"/></a><br/>
206 </xsl:template>
207
208 <xsl:template match="AutoText">
209 <xsl:variable name="value"><xsl:choose><xsl:when test="@key"><xsl:variable name="key" select="@key"/><xsl:variable name="args" select="@args"/><xsl:value-of select="dict:get($diction, $key, $args)"/></xsl:when><xsl:otherwise><xsl:value-of select="@text"/></xsl:otherwise></xsl:choose></xsl:variable>
210 <xsl:choose>
211 <xsl:when test="@type='button'">
212 <b>&lt;<xsl:value-of select="$value"/>&gt;</b>
213 </xsl:when>
214 <xsl:when test="@type='quoted'">
215 <xsl:text>"</xsl:text><xsl:value-of select="$value"/><xsl:text>"</xsl:text>
216 </xsl:when>
217 <xsl:when test="@type='italics'">
218 <i><xsl:value-of select="$value"/></i>
219 </xsl:when>
220 <xsl:when test="@type='plain'">
221 <xsl:value-of select="$value"/>
222 </xsl:when>
223 <xsl:otherwise>
224 <b><xsl:value-of select="$value"/></b>
225 </xsl:otherwise>
226 </xsl:choose>
227 </xsl:template>
228
229</xsl:stylesheet>
230
Note: See TracBrowser for help on using the repository browser.