Delete GSDI.wiki
[jalview.git] / forester / phyloxml / accessories / xmlverbatimwrapper.xsl
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2
3 <!--
4     XML to HTML Verbatim Formatter with Syntax Highlighting
5     Version 1.1
6
7     Copyright 2002 Oliver Becker
8     ob@obqo.de
9
10     Licensed under the Apache License, Version 2.0 (the "License"); 
11     you may not use this file except in compliance with the License.
12     You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
13     Unless required by applicable law or agreed to in writing, software distributed
14     under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
15     CONDITIONS OF ANY KIND, either express or implied. See the License for the
16     specific language governing permissions and limitations under the License.
17
18     Alternatively, this software may be used under the terms of the 
19     GNU Lesser General Public License (LGPL).
20 -->
21
22 <xsl:stylesheet version="1.0"
23                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
24
25    <xsl:import href="xmlverbatim.xsl" />
26
27    <xsl:output method="html"
28                doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" />
29
30    <!-- select the name of an element that should be formatted
31         (print only these elements and their contents) -->
32    <xsl:param name="select" />
33
34    <!-- CSS Stylesheet -->
35    <xsl:param name="css-stylesheet" select="'xmlverbatim.css'" />
36
37    <!-- root -->
38    <xsl:template match="/">
39       <xsl:apply-templates select="/" mode="xmlverbwrapper" />
40    </xsl:template>
41
42    <xsl:template match="/" mode="xmlverbwrapper">
43       <html>
44          <head>
45             <title>XML source view</title>
46             <link rel="stylesheet" type="text/css" 
47                   href="{$css-stylesheet}" />
48          </head>
49          <body class="xmlverb-default">
50             <tt>
51                <xsl:choose>
52                   <!-- "select" parameter present? -->
53                   <xsl:when test="$select">
54                      <xsl:apply-templates mode="xmlverbwrapper" />
55                   </xsl:when>
56                   <xsl:otherwise>
57                      <xsl:apply-templates select="." mode="xmlverb" />
58                   </xsl:otherwise>
59                </xsl:choose>
60             </tt>
61          </body>
62       </html>
63       <xsl:text>&#xA;</xsl:text>
64    </xsl:template>
65
66    <xsl:template match="*" mode="xmlverbwrapper">
67       <xsl:choose>
68          <xsl:when test="name()=$select">
69             <!-- switch to render mode -->
70             <!-- print indent -->
71             <span class="xmlverb-text">
72                <xsl:call-template name="preformatted-output">
73                   <xsl:with-param name="text">
74                      <xsl:call-template name="find-last-line">
75                         <xsl:with-param name="text"
76                               select="preceding-sibling::node()[1][self::text()]" />
77                      </xsl:call-template>
78                   </xsl:with-param>
79                </xsl:call-template>
80             </span>
81             <!-- print element -->
82             <xsl:apply-templates select="." mode="xmlverb" />
83             <br /><br />
84          </xsl:when>
85          <xsl:otherwise>
86             <!-- look for the selected element among the children -->
87             <xsl:apply-templates select="*" mode="xmlverbwrapper" />
88          </xsl:otherwise>
89       </xsl:choose>
90    </xsl:template>
91
92    <!-- return the last line (after newline) in parameter $text -->
93    <xsl:template name="find-last-line">
94       <xsl:param name="text" />
95       <xsl:choose>
96          <xsl:when test="contains($text,'&#xA;')">
97             <xsl:call-template name="find-last-line">
98                <xsl:with-param name="text"
99                     select="substring-after($text,'&#xA;')" />
100             </xsl:call-template>
101          </xsl:when>
102          <xsl:otherwise>
103             <xsl:value-of select="$text" />
104          </xsl:otherwise>
105       </xsl:choose>
106    </xsl:template>
107
108 </xsl:stylesheet>