/[vps]/baselayout-vserver/trunk/src/core/scripts/svn2cl.xsl
Gentoo

Contents of /baselayout-vserver/trunk/src/core/scripts/svn2cl.xsl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 236 - (show annotations) (download) (as text)
Tue Feb 14 13:00:44 2006 UTC (8 years, 10 months ago) by phreak
File MIME type: application/xml
File size: 10780 byte(s)
Merging r1881
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <!--
4
5 svn2cl.xsl - xslt stylesheet for converting svn log to a normal
6 changelog
7
8 Usage (replace ++ with two minus signs which aren't allowed
9 inside xml comments):
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 svn2cl.xsl - > ChangeLog
16
17 This file is based on several implementations of this conversion
18 that I was not completely happy with and some other common
19 xslt constructs found on the web.
20
21 Copyright (C) 2004, 2005 Arthur de Jong.
22
23 Redistribution and use in source and binary forms, with or without
24 modification, are permitted provided that the following conditions
25 are met:
26 1. Redistributions of source code must retain the above copyright
27 notice, this list of conditions and the following disclaimer.
28 2. Redistributions in binary form must reproduce the above copyright
29 notice, this list of conditions and the following disclaimer in
30 the documentation and/or other materials provided with the
31 distribution.
32 3. The name of the author may not be used to endorse or promote
33 products derived from this software without specific prior
34 written permission.
35
36 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
37 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
40 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
44 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
45 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
46 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47
48 -->
49
50 <!DOCTYPE page [
51 <!ENTITY tab "&#9;">
52 <!ENTITY newl "&#10;">
53 <!ENTITY space "&#32;">
54 ]>
55
56 <xsl:stylesheet
57 version="1.0"
58 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
59
60 <xsl:output
61 method="text"
62 encoding="utf-8"
63 media-type="text/plain"
64 omit-xml-declaration="yes"
65 standalone="yes"
66 indent="no" />
67
68 <xsl:strip-space elements="*" />
69
70 <!-- the prefix of pathnames to strip -->
71 <xsl:param name="strip-prefix" select="'/'" />
72
73 <!-- the length of a line to wrap messages at -->
74 <xsl:param name="linelen" select="75" />
75
76 <!-- whether entries should be grouped by day -->
77 <xsl:param name="groupbyday" select="'no'" />
78
79 <!-- whether entries should be grouped by day -->
80 <xsl:param name="include-rev" select="'no'" />
81
82 <!-- add newlines at the end of the changelog -->
83 <xsl:template match="log">
84 <xsl:apply-templates/>
85 <xsl:text>&newl;</xsl:text>
86 </xsl:template>
87
88 <!-- format one entry from the log -->
89 <xsl:template match="logentry">
90 <!-- save log entry number -->
91 <xsl:variable name="pos" select="position()" />
92 <!-- fetch previous entry's date -->
93 <xsl:variable name="prevdate">
94 <xsl:apply-templates select="../logentry[position()=(($pos)-1)]/date" />
95 </xsl:variable>
96 <!-- fetch previous entry's author -->
97 <xsl:variable name="prevauthor">
98 <xsl:apply-templates select="../logentry[position()=(($pos)-1)]/author" />
99 </xsl:variable>
100 <!-- fetch this entry's date -->
101 <xsl:variable name="date">
102 <xsl:apply-templates select="date" />
103 </xsl:variable>
104 <!-- fetch this entry's author -->
105 <xsl:variable name="author">
106 <xsl:apply-templates select="author" />
107 </xsl:variable>
108 <!-- check if header is changed -->
109 <xsl:if test="($prevdate!=$date) or ($prevauthor!=$author)">
110 <!-- add newline -->
111 <xsl:if test="not(position()=1)">
112 <xsl:text>&newl;</xsl:text>
113 </xsl:if>
114 <!-- date -->
115 <xsl:apply-templates select="date" />
116 <!-- two spaces -->
117 <xsl:text>&space;&space;</xsl:text>
118 <!-- author's name -->
119 <xsl:apply-templates select="author" />
120 <!-- two newlines -->
121 <xsl:text>&newl;&newl;</xsl:text>
122 </xsl:if>
123 <!-- get paths string -->
124 <xsl:variable name="paths">
125 <xsl:apply-templates select="paths" />
126 <xsl:text>:&space;</xsl:text>
127 </xsl:variable>
128 <!-- get revision number -->
129 <xsl:variable name="rev">
130 <xsl:if test="$include-rev='yes'">
131 <xsl:text>[r</xsl:text>
132 <xsl:value-of select="@revision" />
133 <xsl:text>]&space;</xsl:text>
134 </xsl:if>
135 </xsl:variable>
136 <!-- trim trailing newlines -->
137 <xsl:variable name="msg">
138 <xsl:call-template name="trim-newln">
139 <xsl:with-param name="txt" select="msg" />
140 </xsl:call-template>
141 </xsl:variable>
142 <!-- first line is indented (other indents are done in wrap template) -->
143 <xsl:text>&tab;*&space;</xsl:text>
144 <!-- print the paths and message nicely wrapped -->
145 <xsl:call-template name="wrap">
146 <xsl:with-param name="txt" select="concat($rev,$paths,$msg)" />
147 </xsl:call-template>
148 </xsl:template>
149
150 <!-- format date -->
151 <xsl:template match="date">
152 <xsl:variable name="date" select="normalize-space(.)" />
153 <!-- output date part -->
154 <xsl:value-of select="substring($date,1,10)" />
155 <!-- output time part -->
156 <xsl:if test="$groupbyday!='yes'">
157 <xsl:text>&space;</xsl:text>
158 <xsl:value-of select="substring($date,12,5)" />
159 </xsl:if>
160 </xsl:template>
161
162 <!-- format author -->
163 <xsl:template match="author">
164 <xsl:value-of select="normalize-space(.)" />
165 </xsl:template>
166
167 <!-- present a list of paths names -->
168 <xsl:template match="paths">
169 <xsl:for-each select="path">
170 <xsl:sort select="normalize-space(.)" data-type="text" />
171 <!-- unless we are the first entry, add a comma -->
172 <xsl:if test="not(position()=1)">
173 <xsl:text>,&space;</xsl:text>
174 </xsl:if>
175 <!-- print the path name -->
176 <xsl:apply-templates select="." />
177 </xsl:for-each>
178 </xsl:template>
179
180 <!-- transform path to something printable -->
181 <xsl:template match="path">
182 <!-- fetch the pathname -->
183 <xsl:variable name="p1" select="normalize-space(.)" />
184 <!-- strip leading slash -->
185 <xsl:variable name="p2">
186 <xsl:choose>
187 <xsl:when test="starts-with($p1,'/')">
188 <xsl:value-of select="substring($p1,2)" />
189 </xsl:when>
190 <xsl:otherwise>
191 <xsl:value-of select="$p1" />
192 </xsl:otherwise>
193 </xsl:choose>
194 </xsl:variable>
195 <!-- strip trailing slash from strip-prefix -->
196 <xsl:variable name="sp">
197 <xsl:choose>
198 <xsl:when test="substring($strip-prefix,string-length($strip-prefix),1)='/'">
199 <xsl:value-of select="substring($strip-prefix,1,string-length($strip-prefix)-1)" />
200 </xsl:when>
201 <xsl:otherwise>
202 <xsl:value-of select="$strip-prefix" />
203 </xsl:otherwise>
204 </xsl:choose>
205 </xsl:variable>
206 <!-- strip strip-prefix -->
207 <xsl:variable name="p3">
208 <xsl:choose>
209 <xsl:when test="starts-with($p2,$sp)">
210 <xsl:value-of select="substring($p2,1+string-length($sp))" />
211 </xsl:when>
212 <xsl:otherwise>
213 <!-- TODO: do not print strings that do not begin with strip-prefix -->
214 <xsl:value-of select="$p2" />
215 </xsl:otherwise>
216 </xsl:choose>
217 </xsl:variable>
218 <!-- strip another slash -->
219 <xsl:variable name="p4">
220 <xsl:choose>
221 <xsl:when test="starts-with($p3,'/')">
222 <xsl:value-of select="substring($p3,2)" />
223 </xsl:when>
224 <xsl:otherwise>
225 <xsl:value-of select="$p3" />
226 </xsl:otherwise>
227 </xsl:choose>
228 </xsl:variable>
229 <!-- translate empty string to dot -->
230 <xsl:choose>
231 <xsl:when test="$p4 = ''">
232 <xsl:text>.</xsl:text>
233 </xsl:when>
234 <xsl:otherwise>
235 <xsl:value-of select="$p4" />
236 </xsl:otherwise>
237 </xsl:choose>
238 </xsl:template>
239
240 <!-- string-wrapping template -->
241 <xsl:template name="wrap">
242 <xsl:param name="txt" />
243 <xsl:choose>
244 <xsl:when test="contains($txt,'&#xa;')">
245 <!-- text contains newlines, do the first line -->
246 <xsl:call-template name="wrap">
247 <xsl:with-param name="txt" select="substring-before($txt,'&#xa;')" />
248 </xsl:call-template>
249 <!-- print tab -->
250 <xsl:text>&tab;&space;&space;</xsl:text>
251 <!-- wrap the rest of the text -->
252 <xsl:call-template name="wrap">
253 <xsl:with-param name="txt" select="substring-after($txt,'&#xa;')" />
254 </xsl:call-template>
255 </xsl:when>
256 <xsl:when test="(string-length($txt) &lt; (($linelen)-9)) or not(contains($txt,' '))">
257 <!-- this is easy, nothing to do -->
258 <xsl:value-of select="$txt" />
259 <!-- add newline -->
260 <xsl:text>&newl;</xsl:text>
261 </xsl:when>
262 <xsl:otherwise>
263 <!-- find the first line -->
264 <xsl:variable name="tmp" select="substring($txt,1,(($linelen)-10))" />
265 <xsl:variable name="line">
266 <xsl:choose>
267 <xsl:when test="contains($tmp,' ')">
268 <xsl:call-template name="find-line">
269 <xsl:with-param name="txt" select="$tmp" />
270 </xsl:call-template>
271 </xsl:when>
272 <xsl:otherwise>
273 <xsl:value-of select="substring-before($txt,' ')" />
274 </xsl:otherwise>
275 </xsl:choose>
276 </xsl:variable>
277 <!-- print newline and tab -->
278 <xsl:value-of select="$line" />
279 <xsl:text>&newl;&tab;&space;&space;</xsl:text>
280 <!-- wrap the rest of the text -->
281 <xsl:call-template name="wrap">
282 <xsl:with-param name="txt" select="substring($txt,string-length($line)+1)" />
283 </xsl:call-template>
284 </xsl:otherwise>
285 </xsl:choose>
286 </xsl:template>
287
288 <!-- template to trim line to contain space as last char -->
289 <xsl:template name="find-line">
290 <xsl:param name="txt" />
291 <xsl:choose>
292 <xsl:when test="substring($txt,string-length($txt),1) = ' '">
293 <xsl:value-of select="$txt" />
294 </xsl:when>
295 <xsl:otherwise>
296 <xsl:call-template name="find-line">
297 <xsl:with-param name="txt" select="substring($txt,1,string-length($txt)-1)" />
298 </xsl:call-template>
299 </xsl:otherwise>
300 </xsl:choose>
301 </xsl:template>
302
303 <!-- template to trim trailing and starting newlines -->
304 <xsl:template name="trim-newln">
305 <xsl:param name="txt" />
306 <xsl:choose>
307 <!-- find starting newlines -->
308 <xsl:when test="substring($txt,1,1) = '&#xa;'">
309 <xsl:call-template name="trim-newln">
310 <xsl:with-param name="txt" select="substring($txt,2)" />
311 </xsl:call-template>
312 </xsl:when>
313 <!-- find trailing newlines -->
314 <xsl:when test="substring($txt,string-length($txt),1) = '&#xa;'">
315 <xsl:call-template name="trim-newln">
316 <xsl:with-param name="txt" select="substring($txt,1,string-length($txt)-1)" />
317 </xsl:call-template>
318 </xsl:when>
319 <!-- no newlines found, we're done -->
320 <xsl:otherwise>
321 <xsl:value-of select="$txt" />
322 </xsl:otherwise>
323 </xsl:choose>
324 </xsl:template>
325
326 </xsl:stylesheet>

  ViewVC Help
Powered by ViewVC 1.1.20