Instead of generating a lot of static HTML documents, it is sufficient for AxKit to provide the XML source with a reference to a style sheet, which determines what is to be presented and how. Listing 3 contains the first lines of the XML source, listing 4 shows those of the style sheet.
For dictionary.xml the same thing goes as for the letter mentioned above: the only change is the reference to a style sheet, in this case dictionary.xsl. Referencing the DTD is not necessary for AxKit (see above). In the style sheet the output format is set to HTML (in xsl:output). Here the attribute encoding should not appear, because the result in the browser would be UTF-8 instead of ISO-Latin1 then.
<xsl:param name="myentry"/>
is meant to allow a parameter to be "sent" to the style sheet, in order to display single entries instead of the entire document. The parameter is only defined, it doesn't have a value yet. This is of importance in the root template, because here the style sheet decides upon which way to go. Either a table of contents is to be shown - via the template for dictionary -, or the entry with a matching id is displayed - via select="//entry[@id=$myentry]". Calling
http://xml.heise.de/ix/xslt/dictionary/dictionary.xml
means that myentry doesn't have a value, therefore the style sheet chooses the branch of the dictionary template. There, the table of contents will be prepared as you can see in [[bild_url3] picture 2]. The template can be found in listing 5. The crucial line there is
<xsl:apply-templates select="//acro" mode="toc"/>
It has the effect that starting from the element dictionary all elements acro will be displayed (as links), following the mode of the toc mode="toc".
|
Listing 5 shows the making of the ToC. The result contains links to the entries, which are generated in the template for acro (not in listing 5) with mode toc. |
If myentry is not empty, xsl:otherwise will be used in the root template ([list4.html listing 4]), and the XSLT processor will deliver the data of the entry in question (the attribute's value). In the case of myentry=xslt the result will look like [[bild_url6] picture 3]. With
select="//entry[@id=$myentry]"
the style sheet searches the document for an entry with the id of $myentry. Only, if two are the same, the entry's data is displayed. And since an id may appear only once in an XML document, it is clear that one and only one entry will make up the resulting HTML.
|
For each single entry there will be generated a ToC as well, on the left hand side. On the right you will see the details regarding a specific entry. |
Note: different from the first two parts of the tutorial the style sheets are not modular, but all templates reside in a single file. The reason is that Sablot(ron), the XSLT processor used (version 0.50 at the time of writing), doesn't know xsl:include yet.
Dieser Text ist der Zeitschriften-Ausgabe 03/2001 von iX entnommen.
iOS, Android, Windows Phone 7 und HTML5 - das neue Sonderheft von heise Developer führt Einsteiger und Profis in die Programmierung mobiler Geräte ein.