summaryrefslogtreecommitdiffstats
path: root/xsl/xmlverbatimwrapper.xsl
blob: 48714f0296f6f81799c14c3f904cc35b686e2470 (plain)
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
<?xml version="1.0" encoding="ISO-8859-1"?>

<!--
    XML to HTML Verbatim Formatter with Syntax Highlighting
    Version 1.1

    Copyright 2002 Oliver Becker
    ob@obqo.de

    Licensed under the Apache License, Version 2.0 (the "License"); 
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software distributed
    under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
    CONDITIONS OF ANY KIND, either express or implied. See the License for the
    specific language governing permissions and limitations under the License.

    Alternatively, this software may be used under the terms of the 
    GNU Lesser General Public License (LGPL).
-->
<!-- 
Modified by dman 2012-11-27
Brought the external css into the head to avoid relative link issues.
 -->

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:import href="xmlverbatim.xsl" />

   <xsl:output method="html"
               doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" />

   <!-- select the name of an element that should be formatted
        (print only these elements and their contents) -->
   <xsl:param name="select" />

   <!-- CSS Stylesheet -->
   <xsl:param name="css-stylesheet" select="'xmlverbatim.css'" />
   
   <xsl:param name="indent-elements" select="false()" />
   

   <!-- root -->
   <xsl:template match="/">
      <xsl:apply-templates select="/" mode="xmlverbwrapper" />
   </xsl:template>

   <xsl:template match="/" mode="xmlverbwrapper">
      <html>
         <head>
            <title>XML source view</title>
            <style>
.xmlverb-default          { color: #333333; background-color: #ffffff;
                            font-family: monospace }
.xmlverb-element-name     { color: #990000 }
.xmlverb-element-nsprefix { color: #666600 }
.xmlverb-attr-name        { color: #660000 }
.xmlverb-attr-content     { color: #000099; font-weight: bold }
.xmlverb-ns-name          { color: #666600 }
.xmlverb-ns-uri           { color: #330099 }
.xmlverb-text             { color: #000000; font-weight: bold }
.xmlverb-comment          { color: #006600; font-style: italic }
.xmlverb-pi-name          { color: #006600; font-style: italic }
.xmlverb-pi-content       { color: #006666; font-style: italic }

            </style>
            <style type="text/css" media="print">@import url("<xsl:value-of select="$base"/>/xmlverbatim.css");</style>
            
         </head>
         <body class="xmlverb-default">
            <tt>
               <xsl:choose>
                  <!-- "select" parameter present? -->
                  <xsl:when test="$select">
                     <xsl:apply-templates mode="xmlverbwrapper" >
                       <xsl:with-param name="indent-elements" select="$indent-elements" />
                     </xsl:apply-templates>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:apply-templates select="." mode="xmlverb" >
                       <xsl:with-param name="indent-elements" select="$indent-elements" />
                     </xsl:apply-templates>
                  </xsl:otherwise>
               </xsl:choose>
            </tt>
         </body>
      </html>
      <xsl:text>&#xA;</xsl:text>
   </xsl:template>

   <xsl:template match="*" mode="xmlverbwrapper">
      <xsl:choose>
         <xsl:when test="name()=$select">
            <!-- switch to render mode -->
            <!-- print indent -->
            <span class="xmlverb-text">
               <xsl:call-template name="preformatted-output">
                  <xsl:with-param name="text">
                     <xsl:call-template name="find-last-line">
                        <xsl:with-param name="text"
                              select="preceding-sibling::node()[1][self::text()]" />
                     </xsl:call-template>
                  </xsl:with-param>
               </xsl:call-template>
            </span>
            <!-- print element -->
            <xsl:apply-templates select="." mode="xmlverb" />
            <br /><br />
         </xsl:when>
         <xsl:otherwise>
            <!-- look for the selected element among the children -->
            <xsl:apply-templates select="*" mode="xmlverbwrapper" />
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <!-- return the last line (after newline) in parameter $text -->
   <xsl:template name="find-last-line">
      <xsl:param name="text" />
      <xsl:choose>
         <xsl:when test="contains($text,'&#xA;')">
            <xsl:call-template name="find-last-line">
               <xsl:with-param name="text"
                    select="substring-after($text,'&#xA;')" />
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="$text" />
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

</xsl:stylesheet>