1 <?xml version="1.0" encoding="utf-8"?>
5 svn2cl.xsl - xslt stylesheet for converting svn log to a normal
8 Usage (replace ++ with two minus signs which aren't allowed
10 svn ++verbose ++xml log | \
11 xsltproc ++stringparam strip-prefix `basename $(pwd)` \
12 ++stringparam linelen 75 \
13 ++stringparam groupbyday yes \
14 ++stringparam include-rev yes \
15 ++stringparam breakbeforemsg yes \
16 ++stringparam authorsfile FILE \
17 svn2cl.xsl - > ChangeLog
19 This file is based on several implementations of this conversion
20 that I was not completely happy with and some other common
21 xslt constructs found on the web.
23 Copyright (C) 2004, 2005, 2006 Arthur de Jong.
25 Redistribution and use in source and binary forms, with or without
26 modification, are permitted provided that the following conditions
28 1. Redistributions of source code must retain the above copyright
29 notice, this list of conditions and the following disclaimer.
30 2. Redistributions in binary form must reproduce the above copyright
31 notice, this list of conditions and the following disclaimer in
32 the documentation and/or other materials provided with the
34 3. The name of the author may not be used to endorse or promote
35 products derived from this software without specific prior
38 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
39 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
40 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
42 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
44 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
46 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
47 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
48 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 <!DOCTYPE stylesheet [
54 <!ENTITY newl " ">
55 <!ENTITY space " ">
60 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
65 media-type="text/plain"
66 omit-xml-declaration="yes"
70 <xsl:strip-space elements="*" />
72 <!-- the prefix of pathnames to strip -->
73 <xsl:param name="strip-prefix" select="'/'" />
75 <!-- the length of a line to wrap messages at -->
76 <xsl:param name="linelen" select="80" />
78 <!-- whether entries should be grouped by day -->
79 <xsl:param name="groupbyday" select="'no'" />
81 <!-- whether a revision number should be included -->
82 <xsl:param name="include-rev" select="'no'" />
84 <!-- whether the log message should start on a new line -->
85 <xsl:param name="breakbeforemsg" select="'no'" />
87 <!-- location of authors file if any -->
88 <xsl:param name="authorsfile" select="''" />
90 <!-- add newlines at the end of the changelog -->
91 <xsl:template match="log">
92 <xsl:apply-templates/>
93 <xsl:text>&newl;</xsl:text>
96 <!-- format one entry from the log -->
97 <xsl:template match="logentry">
98 <!-- save log entry number -->
99 <xsl:variable name="pos" select="position()" />
100 <!-- fetch previous entry's date -->
101 <xsl:variable name="prevdate">
102 <xsl:apply-templates select="../logentry[position()=(($pos)-1)]/date" />
104 <!-- fetch previous entry's author -->
105 <xsl:variable name="prevauthor">
106 <xsl:apply-templates select="../logentry[position()=(($pos)-1)]/author" />
108 <!-- fetch this entry's date -->
109 <xsl:variable name="date">
110 <xsl:apply-templates select="date" />
112 <!-- fetch this entry's author -->
113 <xsl:variable name="author">
114 <xsl:apply-templates select="author" />
116 <!-- check if header is changed -->
117 <xsl:if test="($prevdate!=$date) or ($prevauthor!=$author)">
119 <xsl:if test="not(position()=1)">
120 <xsl:text>&newl;</xsl:text>
123 <xsl:apply-templates select="date" />
125 <xsl:text>&space;&space;</xsl:text>
126 <!-- author's name -->
127 <xsl:apply-templates select="author" />
128 <!-- two newlines -->
129 <xsl:text>&newl;&newl;</xsl:text>
131 <!-- get paths string -->
132 <xsl:variable name="paths">
133 <xsl:apply-templates select="paths" />
134 <xsl:text>:&space;</xsl:text>
136 <!-- get revision number -->
137 <xsl:variable name="rev">
138 <xsl:if test="$include-rev='yes'">
139 <xsl:text>[r</xsl:text>
140 <xsl:value-of select="@revision" />
141 <xsl:text>]&space;</xsl:text>
144 <!-- trim trailing newlines -->
145 <xsl:variable name="msg">
146 <!-- add a line break before the log message -->
147 <xsl:if test="$breakbeforemsg='yes'">
148 <xsl:text>&newl;</xsl:text>
150 <xsl:call-template name="trim-newln">
151 <xsl:with-param name="txt" select="msg" />
154 <!-- first line is indented (other indents are done in wrap template) -->
155 <xsl:text>&tab;</xsl:text>
156 <!-- print the paths and message nicely wrapped -->
157 <xsl:call-template name="wrap">
158 <xsl:with-param name="txt" select="concat($rev,$msg)" />
163 <xsl:template match="date">
164 <xsl:variable name="date" select="normalize-space(.)" />
165 <!-- output date part -->
166 <xsl:value-of select="substring($date,1,10)" />
167 <!-- output time part -->
168 <xsl:if test="$groupbyday!='yes'">
169 <xsl:text>&space;</xsl:text>
170 <xsl:value-of select="substring($date,12,5)" />
174 <!-- format author -->
175 <xsl:template match="author">
176 <xsl:variable name="author" select="normalize-space(.)" />
178 <!-- try to look up the author in the authorsfile -->
179 <xsl:when test="$authorsfile!='' and document($authorsfile)//author[@uid=$author]">
180 <xsl:value-of select="normalize-space(document($authorsfile)//author[@uid=$author])" />
182 <!-- just use the author name as given by svn -->
184 <xsl:value-of select="$author" />
189 <!-- present a list of paths names -->
190 <xsl:template match="paths">
191 <xsl:for-each select="path">
192 <xsl:sort select="normalize-space(.)" data-type="text" />
193 <!-- unless we are the first entry, add a comma -->
194 <xsl:if test="not(position()=1)">
195 <xsl:text>,&space;</xsl:text>
197 <!-- print the path name -->
198 <xsl:apply-templates select="." />
202 <!-- transform path to something printable -->
203 <xsl:template match="path">
204 <!-- fetch the pathname -->
205 <xsl:variable name="p1" select="normalize-space(.)" />
206 <!-- strip leading slash -->
207 <xsl:variable name="p2">
209 <xsl:when test="starts-with($p1,'/')">
210 <xsl:value-of select="substring($p1,2)" />
213 <xsl:value-of select="$p1" />
217 <!-- strip trailing slash from strip-prefix -->
218 <xsl:variable name="sp">
220 <xsl:when test="substring($strip-prefix,string-length($strip-prefix),1)='/'">
221 <xsl:value-of select="substring($strip-prefix,1,string-length($strip-prefix)-1)" />
224 <xsl:value-of select="$strip-prefix" />
228 <!-- strip strip-prefix -->
229 <xsl:variable name="p3">
231 <xsl:when test="starts-with($p2,$sp)">
232 <xsl:value-of select="substring($p2,1+string-length($sp))" />
235 <!-- TODO: do not print strings that do not begin with strip-prefix -->
236 <xsl:value-of select="$p2" />
240 <!-- strip another slash -->
241 <xsl:variable name="p4">
243 <xsl:when test="starts-with($p3,'/')">
244 <xsl:value-of select="substring($p3,2)" />
247 <xsl:value-of select="$p3" />
251 <!-- translate empty string to dot -->
253 <xsl:when test="$p4 = ''">
254 <xsl:text>.</xsl:text>
257 <xsl:value-of select="$p4" />
262 <!-- string-wrapping template -->
263 <xsl:template name="wrap">
264 <xsl:param name="txt" />
266 <xsl:when test="contains($txt,'&newl;')">
267 <!-- text contains newlines, do the first line -->
268 <xsl:call-template name="wrap">
269 <xsl:with-param name="txt" select="substring-before($txt,'&newl;')" />
272 <xsl:text>&tab;</xsl:text>
273 <!-- wrap the rest of the text -->
274 <xsl:call-template name="wrap">
275 <xsl:with-param name="txt" select="substring-after($txt,'&newl;')" />
278 <xsl:when test="(string-length($txt) < (($linelen)-9)) or not(contains($txt,' '))">
279 <!-- this is easy, nothing to do -->
280 <xsl:value-of select="normalize-space($txt)" />
282 <xsl:text>&newl;</xsl:text>
285 <!-- find the first line -->
286 <xsl:variable name="tmp" select="substring($txt,1,(($linelen)-10))" />
287 <xsl:variable name="line">
289 <xsl:when test="contains($tmp,' ')">
290 <xsl:call-template name="find-line">
291 <xsl:with-param name="txt" select="$tmp" />
295 <xsl:value-of select="normalize-space(substring-before($txt,' '))" />
299 <!-- print newline and tab -->
300 <xsl:value-of select="normalize-space($line)" />
301 <xsl:text>&newl;&tab;</xsl:text>
302 <!-- wrap the rest of the text -->
303 <xsl:call-template name="wrap">
304 <xsl:with-param name="txt" select="substring($txt,string-length($line)+1)" />
310 <!-- template to trim line to contain space as last char -->
311 <xsl:template name="find-line">
312 <xsl:param name="txt" />
314 <xsl:when test="substring($txt,string-length($txt),1) = ' '">
315 <xsl:value-of select="$txt" />
318 <xsl:call-template name="find-line">
319 <xsl:with-param name="txt" select="substring($txt,1,string-length($txt)-1)" />
325 <!-- template to trim trailing and starting newlines -->
326 <xsl:template name="trim-newln">
327 <xsl:param name="txt" />
329 <!-- find starting newlines -->
330 <xsl:when test="substring($txt,1,1) = '&newl;'">
331 <xsl:call-template name="trim-newln">
332 <xsl:with-param name="txt" select="substring($txt,2)" />
335 <!-- find trailing newlines -->
336 <xsl:when test="substring($txt,string-length($txt),1) = '&newl;'">
337 <xsl:call-template name="trim-newln">
338 <xsl:with-param name="txt" select="substring($txt,1,string-length($txt)-1)" />
341 <!-- no newlines found, we're done -->
343 <xsl:value-of select="$txt" />