Code von dita2chm.xsl
XSLT-Datei direkt laden
1: <?xml version="1.0" encoding="ISO-8859-1"?>
2: <!DOCTYPE xsl:stylesheet [
3: <!ENTITY li_anf "">
4: <!ENTITY li_end "">
5: <!ENTITY ob_anf "">
6: <!ENTITY ob_end "">
7: ]><!-- Entitys für Character-Map "li_ob" -->
8:
9: <!--
10: XSLT 2.0-Stylesheet zur automatisierten Umsetzung von CHM-Hilfeprojekten auf der Basis von DITA-Topics
11: Realisierung: Dr. Thomas Meinike 07/2007 | http://www.iks.hs-merseburg.de/~meinike/
12:
13: Zweck: Mit dieser Vorlage lassen sich in DITA-Map-Dokumenten abgelegte Strukturen in die für den
14: HTML-Help-Compiler relevanten Dateien transformieren. Dazu wird ein XSLT 2.0-Prozessor benötigt [getestet
15: mit Saxon 8.9B (http://saxon.sourceforge.net/) und AltovaXML 2007 (http://www.altova.com/altovaxml.html)].
16:
17: Über die erzeugten Projektdateien (*.hhp, *.hhc, *.hhk) lassen sich die pro DITA-Topic ausgegebenen XHTML-
18: Dokumente unter Einbindung der CSS- und Bilddateien direkt in filename.chm kompilieren [Aufruf: "hhc filename.hhp"].
19: -->
20:
21: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22: xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"
23: xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="fn xs">
24:
25:
26: <!-- Vorgaben für Dateien und Verzeichnisse -->
27: <xsl:param name="filename" select="'demohelp'"/><!-- Basisname für *.hhp, *.hhc und *.hhk -->
28: <xsl:param name="destdir" select="'chmout'"/><!-- Zielverzeichnis, muss existieren und sollte Bilder sowie CSS-Datei enthalten -->
29: <xsl:param name="imgdir" select="'bilder'"/><!-- Verzeichnis für einzubindende Bilder - im Zielverzeichnis ablegen -->
30: <xsl:param name="cssfile" select="'default.css'"/><!-- Standard-CSS-Vorlage für XHTML-Ergebniselemente - im Zielverzeichnis ablegen -->
31: <xsl:param name="srcxsl" select="fn:replace(fn:document-uri(fn:doc('')),'\\','/')"/>
32: <xsl:param name="srcdir" select="fn:tokenize($srcxsl,'/')[fn:last()-1]"/>
33: <xsl:param name="outdir" select="fn:concat(fn:substring-before($srcxsl,$srcdir),$destdir)"/>
34:
35:
36: <!-- Vorgaben für auszugebende Dateitypen -->
37: <xsl:output method="text" name="project" encoding="ISO-8859-1"/>
38: <xsl:output method="html" name="sitemap" encoding="ISO-8859-1" indent="yes" use-character-maps="li_ob"
39: doctype-public="-//IETF//DTD HTML//EN"/>
40: <xsl:output method="xhtml" name="html_file" encoding="ISO-8859-1" indent="yes" omit-xml-declaration="yes"
41: doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
42:
43:
44: <xsl:character-map name="li_ob">
45: <xsl:output-character character="" string="<li>"/>
46: <xsl:output-character character="" string="</li>"/>
47: <xsl:output-character character="" string="<object type="text/sitemap">"/>
48: <xsl:output-character character="" string="</object>"/>
49: </xsl:character-map>
50: <!-- Hinweis: <xsl:text>&li_anf;</xsl:text> enstspricht <xsl:text disable-output-escaping="yes"><li></xsl:text> -->
51:
52:
53: <xsl:template match="map"><!-- DITA-Map auswerten -->
54:
55: <xsl:variable name="map_title" select="@title"/>
56: <xsl:variable name="map_hrefs" select="//topicref/@href"/><!-- Sequenz von DITA-Topicfiles aus der Map -->
57:
58: <!-- Help-Project-File (.hhp) erstellen -->
59: <xsl:call-template name="hhp_out">
60: <xsl:with-param name="default_topic" select="fn:replace(topicref[1]/@href,'\.xml','.html')"/>
61: <xsl:with-param name="chm_title" select="$map_title"/>
62: <xsl:with-param name="map_hrefs" select="$map_hrefs"/>
63: </xsl:call-template>
64:
65:
66: <!-- Help-TOC-File (.hhc) erstellen -->
67: <xsl:call-template name="toc_out"/>
68:
69:
70: <!-- Help-Index-File (.hhk) erstellen -->
71: <xsl:call-template name="index_out">
72: <xsl:with-param name="map_hrefs" select="$map_hrefs"/>
73: </xsl:call-template>
74:
75:
76: <!-- pro Topic-File eine HTML-Datei erzeugen -->
77: <xsl:call-template name="html_out">
78: <xsl:with-param name="map_hrefs" select="$map_hrefs"/>
79: </xsl:call-template>
80:
81: </xsl:template>
82:
83:
84: <xsl:template name="hhp_out"><!-- HHP-Projectfile erzeugen -->
85:
86: <xsl:param name="default_topic"/>
87: <xsl:param name="chm_title"/>
88: <xsl:param name="map_hrefs"/>
89:
90: <xsl:result-document format="project" href="{$outdir}/{$filename}.hhp">
91:
92: <xsl:text>[OPTIONS]
</xsl:text>
93: <xsl:text>Compatibility=1.1 or later
</xsl:text>
94: <xsl:text>Display compile progress=No
</xsl:text>
95: <xsl:text>Full-text search=Yes
</xsl:text>
96: <xsl:text>Language=0x407 Deutsch (Deutschland)
</xsl:text>
97: <xsl:text>Compiled file=</xsl:text><xsl:value-of select="fn:concat($filename,'.chm','
')"/>
98: <xsl:text>Contents file=</xsl:text><xsl:value-of select="fn:concat($filename,'.hhc','
')"/>
99: <xsl:text>Index file=</xsl:text><xsl:value-of select="fn:concat($filename,'.hhk','
')"/>
100: <xsl:text>Default topic=</xsl:text><xsl:value-of select="fn:concat($default_topic,'
')"/>
101: <xsl:text>Title=</xsl:text><xsl:value-of select="fn:concat($chm_title,'
')"/>
102: <xsl:text>
</xsl:text>
103: <xsl:text>[FILES]
</xsl:text>
104:
105: <xsl:for-each select="$map_hrefs">
106: <xsl:value-of select="fn:replace(.,'\.xml','.html')"/><xsl:text>
</xsl:text>
107: </xsl:for-each>
108:
109: <xsl:text>
[MERGE FILES]
</xsl:text>
110: <xsl:value-of select="$cssfile"/><xsl:text>
</xsl:text>
111:
112: <xsl:text>
</xsl:text>
113: <xsl:text>[INFOTYPES]
</xsl:text>
114:
115: </xsl:result-document>
116:
117: </xsl:template>
118:
119:
120: <xsl:template name="toc_out"><!-- TOC-File erzeugen -->
121:
122: <xsl:result-document format="sitemap" href="{$outdir}/{$filename}.hhc">
123:
124: <html>
125: <head>
126: <title>TOC-File</title>
127: <meta name="generator" content="dita2chm.xsl by TM 2007"/>
128: <xsl:comment> Sitemap 1.0 </xsl:comment>
129: </head>
130: <body>
131: <object type="text/site properties">
132: <param name="ImageType" value="Toc"/><!-- alternativ "Folder" -->
133: <param name="Window Styles" value="0x801427"/>
134: </object>
135: <ul>
136: <xsl:apply-templates select="topicref"/>
137: </ul>
138: </body>
139: </html>
140:
141: </xsl:result-document>
142:
143: </xsl:template>
144:
145:
146: <xsl:template match="topicref"><!-- topicref-Einträge der Map als TOC verarbeiten -->
147:
148: <!-- <li><object> wird vom HWS in einer Zeile erwartet, bricht aber um und funktioniert nicht! -->
149: <xsl:text>&li_anf;&ob_anf;</xsl:text>
150: <param name="Name" value="{@navtitle}"/>
151: <param name="Local" value="{fn:replace(@href,'\.xml','.html')}"/>
152: <xsl:text>
&ob_end;
</xsl:text>
153:
154: <xsl:if test="fn:count(topicref) > 1"><!-- ggf. verschachtelte Topics umsetzen -->
155: <ul>
156: <xsl:apply-templates select="topicref"/>
157: </ul>
158: </xsl:if>
159:
160: </xsl:template>
161:
162:
163: <xsl:template name="index_out"><!-- HHK-Index-File erzeugen -->
164:
165: <xsl:param name="map_hrefs"/>
166:
167: <xsl:result-document format="sitemap" href="{$outdir}/{$filename}.hhk">
168:
169: <html>
170: <head>
171: <title>Index-File</title>
172: <meta name="generator" content="dita2chm.xsl by TM 2007"/>
173: <xsl:comment> Sitemap 1.0 </xsl:comment>
174: </head>
175: <body>
176: <ul>
177:
178: <xsl:for-each select="$map_hrefs">
179:
180: <xsl:if test="fn:doc-available(.)">
181: <xsl:variable name="akt_topic_file" select="fn:doc(.)"/>
182: <xsl:variable name="akt_html_file" select="fn:replace(.,'\.xml','.html')"/>
183:
184: <xsl:for-each select="$akt_topic_file//keywords/keyword | $akt_topic_file//keywords/indexterm">
185:
186: <!-- Sortierung nicht zwingend, da automatisch vom CHM-Viewer vorgenommen - nachfolgende Sortierung
187: bezieht sich nur formal auf mehrere Vorkommen von keyword bzw. indexterm pro Topic/Task -->
188: <xsl:sort select="text()" data-type="text" order="ascending"/>
189:
190: <!-- Start des Eintrags nur bei Existenz von mindestens einem keyword- oder indexterm-Element ausgeben -->
191: <xsl:if test="fn:count($akt_topic_file//keywords/keyword) > 0 or fn:count($akt_topic_file//keywords/indexterm) > 0">
192: <!-- <li><object> wird vom HWS in einer Zeile erwartet! -->
193: <xsl:text>&li_anf;&ob_anf;</xsl:text>
194: </xsl:if>
195:
196: <!-- nur keyword-Elemente mit Inhalt einbeziehen -->
197: <xsl:if test="fn:string-length(.) > 0">
198: <param name="Name" value="{.}"/>
199: </xsl:if>
200:
201: <!-- Ende des Eintrags nur bei Existenz von mind. einem keyword-Elemente ausgeben -->
202: <xsl:if test="fn:count($akt_topic_file//keywords/keyword) > 0 or fn:count($akt_topic_file//keywords/indexterm) > 0">
203: <param name="Local" value="{$akt_html_file}"/>
204: <xsl:text>
&ob_end;&li_end;
</xsl:text>
205: </xsl:if>
206:
207: </xsl:for-each>
208: </xsl:if>
209:
210: </xsl:for-each>
211:
212: </ul>
213: </body>
214: </html>
215:
216: </xsl:result-document>
217:
218: </xsl:template>
219:
220:
221: <xsl:template name="html_out"><!-- HTML-Dokumente aus den einzelnen Topics erzeugen -->
222:
223: <xsl:param name="map_hrefs"/>
224:
225: <xsl:for-each select="$map_hrefs">
226:
227: <xsl:variable name="akt_topic_file" select="if(fn:doc-available(.)) then fn:doc(.) else()"/>
228: <xsl:variable name="akt_html_file" select="fn:replace(.,'\.xml','.html')"/>
229:
230: <xsl:result-document format="html_file" href="{$outdir}/{$akt_html_file}">
231:
232: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
233: <head>
234: <meta name="generator" content="dita2chm.xsl by TM 2007"/>
235: <link rel="stylesheet" href="{$cssfile}" type="text/css"/>
236: <title><xsl:value-of select="fn:substring-before($akt_html_file,'.html')"/></title>
237: </head>
238: <body>
239: <xsl:choose>
240: <xsl:when test="$akt_topic_file">
241: <xsl:apply-templates select="$akt_topic_file/topic | $akt_topic_file/task"/>
242: </xsl:when>
243: <xsl:otherwise>
244: <h1>Kein DITA-Topic-File vorhanden</h1>
245: <p><em>Platzhalter-HTML-Dokument wurde verwendet.</em></p>
246: </xsl:otherwise>
247: </xsl:choose>
248: </body>
249: </html>
250:
251: </xsl:result-document>
252:
253: </xsl:for-each>
254:
255: </xsl:template>
256:
257:
258: <!-- weitere Templates zur Umsetzung ausgewählter DITA-Elemente (Topic- und Task-Strukturen) nach XHTML -->
259: <xsl:template match="topic">
260:
261: <h1><xsl:value-of select="title"/></h1>
262: <p><em><xsl:value-of select="shortdesc"/></em></p>
263: <xsl:apply-templates select="body"/>
264:
265: </xsl:template>
266:
267:
268: <xsl:template match="task">
269:
270: <h1><xsl:value-of select="title"/></h1>
271: <p><em><xsl:value-of select="shortdesc"/></em></p>
272: <xsl:apply-templates select="taskbody"/>
273:
274: </xsl:template>
275:
276:
277: <xsl:template match="body">
278:
279: <xsl:apply-templates select="section"/>
280:
281: </xsl:template>
282:
283:
284: <xsl:template match="taskbody">
285:
286: <xsl:apply-templates select="steps"/>
287: <xsl:apply-templates select="result"/>
288:
289: </xsl:template>
290:
291:
292: <xsl:template match="steps">
293:
294: <ol><xsl:apply-templates select="step"/></ol>
295:
296: </xsl:template>
297:
298:
299: <xsl:template match="step">
300:
301: <li><xsl:apply-templates select="cmd"/><br/>
302: <xsl:text>(</xsl:text>
303: <xsl:apply-templates select="stepresult"/>
304: <xsl:text>)</xsl:text></li>
305:
306: </xsl:template>
307:
308:
309: <xsl:template match="result">
310:
311: <p><xsl:apply-templates/></p>
312:
313: </xsl:template>
314:
315:
316: <xsl:template match="section">
317:
318: <h2><xsl:value-of select="title"/></h2>
319: <xsl:apply-templates select="p|ul|ol|image|xref|table"/><!-- hier ggf. weitere DITA-Elemente angeben -->
320:
321: </xsl:template>
322:
323:
324: <xsl:template match="p">
325:
326: <p><xsl:apply-templates/></p>
327:
328: </xsl:template>
329:
330:
331: <xsl:template match="ul">
332:
333: <ul><xsl:apply-templates/></ul>
334:
335: </xsl:template>
336:
337:
338: <xsl:template match="ol">
339:
340: <ol><xsl:apply-templates/></ol>
341:
342: </xsl:template>
343:
344:
345: <xsl:template match="li">
346:
347: <li><xsl:value-of select="."/></li>
348:
349: </xsl:template>
350:
351:
352: <xsl:template match="image">
353:
354: <img src="{$imgdir}/{@href}" width="{@width}" height="{@height}" alt="{@alt}"/>
355:
356: </xsl:template>
357:
358:
359: <xsl:template match="xref">
360:
361: <a href="{@href}">
362: <xsl:if test="fn:starts-with(@href,'http://')">
363: <xsl:attribute name="onclick" select="'window.open(this.href);return false'"/>
364: </xsl:if>
365: <xsl:apply-templates/>
366: </a>
367:
368: </xsl:template>
369:
370:
371: <xsl:template match="table/tgroup">
372:
373: <table><xsl:apply-templates/></table>
374:
375: </xsl:template>
376:
377:
378: <xsl:template match="thead">
379:
380: <thead><xsl:apply-templates select="row"/></thead>
381:
382: </xsl:template>
383:
384:
385: <xsl:template match="tbody">
386:
387: <tbody><xsl:apply-templates select="row"/></tbody>
388:
389: </xsl:template>
390:
391:
392: <xsl:template match="row">
393:
394: <tr><xsl:apply-templates select="entry"/></tr>
395:
396: </xsl:template>
397:
398:
399: <xsl:template match="entry">
400:
401: <xsl:if test="fn:local-name(parent::node()/parent::node())='thead'">
402: <th><xsl:value-of select="."/></th>
403: </xsl:if>
404: <xsl:if test="fn:local-name(parent::node()/parent::node())='tbody'">
405: <td><xsl:value-of select="."/></td>
406: </xsl:if>
407:
408: </xsl:template>
409:
410:
411: <xsl:template match="b">
412:
413: <strong><xsl:value-of select="."/></strong>
414:
415: </xsl:template>
416:
417:
418: <xsl:template match="i">
419:
420: <em><xsl:value-of select="."/></em>
421:
422: </xsl:template>
423:
424:
425: </xsl:stylesheet>