1 <?xml version=
"1.0" encoding=
"utf-8"?>
5 svn2cl.xsl - xslt stylesheet for converting svn log to a normal
8 This file is based on several implementations of this conversion
9 that I was not completely happy with and some other common
10 xslt constructs found on the web.
12 Copyright (C) 2004 Arthur de Jong.
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in
21 the documentation and/or other materials provided with the
23 3. The name of the author may not be used to endorse or promote
24 products derived from this software without specific prior
27 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
31 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
35 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
37 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 - make external lookups of author names possible
44 - find a place for revision numbers
45 - mark deleted files as such
47 - make stripping of characters nicer
52 xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
53 xmlns=
"http://www.w3.org/1999/xhtml">
57 encoding=
"iso-8859-15"
58 media-type=
"text/plain"
59 omit-xml-declaration=
"yes"
63 <xsl:strip-space elements=
"*" />
65 <!-- the prefix of pathnames to strip -->
66 <xsl:param name=
"strip-prefix" select=
"'/'" />
68 <!-- format one entry from the log -->
69 <xsl:template match=
"logentry">
71 <xsl:apply-templates select=
"date" />
73 <xsl:text> </xsl:text>
74 <!-- author's name -->
75 <xsl:apply-templates select=
"author" />
80 <!-- the log message -->
81 <xsl:apply-templates select=
"msg" />
82 <!-- another two newlines -->
89 <xsl:template match=
"date">
90 <xsl:variable name=
"date" select=
"normalize-space(.)" />
91 <xsl:value-of select=
"substring($date,1,10)" />
92 <xsl:text> </xsl:text>
93 <xsl:value-of select=
"substring($date,12,5)" />
96 <!-- format author -->
97 <xsl:template match=
"author">
98 <xsl:value-of select=
"normalize-space(.)" />
101 <!-- format log message -->
102 <xsl:template match=
"msg">
103 <!-- first line is indented (other indents are done in wrap template) -->
104 <xsl:text> *
</xsl:text>
105 <!-- get paths string -->
106 <xsl:variable name=
"paths">
107 <xsl:apply-templates select=
"../paths" />
109 <!-- print the paths and message nicely wrapped -->
110 <xsl:call-template name=
"wrap">
111 <xsl:with-param name=
"txt" select=
"concat($paths,': ',normalize-space(.))" />
115 <!-- present paths nice -->
116 <xsl:template match=
"paths">
117 <xsl:for-each select=
"path">
118 <xsl:sort select=
"normalize-space(.)" data-type=
"text" />
119 <xsl:if test=
"not(position()=1)">
120 <xsl:text>,
</xsl:text>
122 <xsl:variable name=
"p1" select=
"normalize-space(.)" />
123 <xsl:variable name=
"p2">
125 <xsl:when test=
"starts-with($p1,'/')">
126 <xsl:value-of select=
"substring($p1,2)" />
129 <xsl:value-of select=
"$p1" />
133 <xsl:variable name=
"p3">
135 <xsl:when test=
"starts-with($p2,$strip-prefix)">
136 <xsl:value-of select=
"substring($p2,1+string-length($strip-prefix))" />
139 <xsl:value-of select=
"$p2" />
143 <xsl:variable name=
"p4">
145 <xsl:when test=
"starts-with($p3,'/')">
146 <xsl:value-of select=
"substring($p3,2)" />
149 <xsl:value-of select=
"$p3" />
154 <xsl:when test=
"$p4 = ''">
155 <xsl:value-of select=
"'.'" />
158 <xsl:value-of select=
"$p4" />
164 <!-- string-wrapping template -->
165 <xsl:template name=
"wrap">
166 <xsl:param name=
"txt" />
167 <xsl:variable name=
"linelen" select=
"67" />
169 <xsl:when test=
"(string-length($txt) < $linelen) or not(contains($txt,' '))">
170 <!-- this is easy, nothing to do -->
171 <xsl:value-of select=
"$txt" />
174 <!-- find the first line -->
175 <xsl:variable name=
"tmp" select=
"substring($txt,1,$linelen)" />
176 <xsl:variable name=
"line">
178 <xsl:when test=
"contains($tmp,' ')">
179 <xsl:call-template name=
"find-line">
180 <xsl:with-param name=
"txt" select=
"$tmp" />
184 <xsl:value-of select=
"substring-before($txt,' ')" />
188 <!-- print line and newline -->
189 <xsl:value-of select=
"$line" />
192 <!-- wrap the rest of the text -->
193 <xsl:call-template name=
"wrap">
194 <xsl:with-param name=
"txt" select=
"normalize-space(substring($txt,string-length($line)+1))" />
200 <!-- template to trim line to contain space as last char -->
201 <xsl:template name=
"find-line">
202 <xsl:param name=
"txt" />
204 <xsl:when test=
"substring($txt,string-length($txt),1) = ' '">
205 <xsl:value-of select=
"normalize-space($txt)" />
208 <xsl:call-template name=
"find-line">
209 <xsl:with-param name=
"txt" select=
"substring($txt,1,string-length($txt)-1)" />