use long int format
[rrdtool.git] / svn2cl.xsl
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    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.
11
12    Copyright (C) 2004 Arthur de Jong.
13
14    Redistribution and use in source and binary forms, with or without
15    modification, are permitted provided that the following conditions
16    are met:
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
22       distribution.
23    3. The name of the author may not be used to endorse or promote
24       products derived from this software without specific prior
25       written permission.
26
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.
38
39 -->
40
41 <!--
42    TODO
43    - make external lookups of author names possible
44    - find a place for revision numbers
45    - mark deleted files as such
46    - combine paths
47    - make stripping of characters nicer
48 -->
49
50 <xsl:stylesheet
51   version="1.0"
52   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
53   xmlns="http://www.w3.org/1999/xhtml">
54
55  <xsl:output
56    method="text"
57    encoding="iso-8859-15"
58    media-type="text/plain"
59    omit-xml-declaration="yes"
60    standalone="yes"
61    indent="no" />
62
63  <xsl:strip-space elements="*" />
64
65  <!-- the prefix of pathnames to strip -->
66  <xsl:param name="strip-prefix" select="'/'" />
67
68  <!-- format one entry from the log -->
69  <xsl:template match="logentry">
70   <!-- date -->
71   <xsl:apply-templates select="date" />
72   <!-- two spaces -->
73   <xsl:text>  </xsl:text>
74   <!-- author's name -->
75   <xsl:apply-templates select="author" />
76   <!-- two newlines -->
77   <xsl:text>
78
79 </xsl:text>
80   <!-- the log message -->
81   <xsl:apply-templates select="msg" />
82   <!-- another two newlines -->
83   <xsl:text>
84
85 </xsl:text>
86  </xsl:template>
87
88  <!-- format date -->
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)" />
94  </xsl:template>
95
96  <!-- format author -->
97  <xsl:template match="author">
98   <xsl:value-of select="normalize-space(.)" />
99  </xsl:template>
100
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" />
108   </xsl:variable>
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(.))" />
112   </xsl:call-template>
113  </xsl:template>
114
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>
121    </xsl:if>
122    <xsl:variable name="p1" select="normalize-space(.)" />
123    <xsl:variable name="p2">
124     <xsl:choose>
125      <xsl:when test="starts-with($p1,'/')">
126       <xsl:value-of select="substring($p1,2)" />
127      </xsl:when>
128      <xsl:otherwise>
129       <xsl:value-of select="$p1" />
130      </xsl:otherwise>
131     </xsl:choose>
132    </xsl:variable>
133    <xsl:variable name="p3">
134     <xsl:choose>
135      <xsl:when test="starts-with($p2,$strip-prefix)">
136       <xsl:value-of select="substring($p2,1+string-length($strip-prefix))" />
137      </xsl:when>
138      <xsl:otherwise>
139       <xsl:value-of select="$p2" />
140      </xsl:otherwise>
141     </xsl:choose>
142    </xsl:variable>
143    <xsl:variable name="p4">
144     <xsl:choose>
145      <xsl:when test="starts-with($p3,'/')">
146       <xsl:value-of select="substring($p3,2)" />
147      </xsl:when>
148      <xsl:otherwise>
149       <xsl:value-of select="$p3" />
150      </xsl:otherwise>
151     </xsl:choose>
152    </xsl:variable>
153    <xsl:choose>
154     <xsl:when test="$p4 = ''">
155      <xsl:value-of select="'.'" />
156     </xsl:when>
157     <xsl:otherwise>
158      <xsl:value-of select="$p4" />
159     </xsl:otherwise>
160    </xsl:choose>
161   </xsl:for-each>
162  </xsl:template>
163
164  <!-- string-wrapping template -->
165  <xsl:template name="wrap">
166   <xsl:param name="txt" />
167   <xsl:variable name="linelen" select="67" />
168   <xsl:choose>
169    <xsl:when test="(string-length($txt) &lt; $linelen) or not(contains($txt,' '))">
170     <!-- this is easy, nothing to do -->
171     <xsl:value-of select="$txt" />
172    </xsl:when>
173    <xsl:otherwise>
174     <!-- find the first line -->
175     <xsl:variable name="tmp" select="substring($txt,1,$linelen)" />
176     <xsl:variable name="line">
177      <xsl:choose>
178       <xsl:when test="contains($tmp,' ')">
179        <xsl:call-template name="find-line">
180         <xsl:with-param name="txt" select="$tmp" />
181        </xsl:call-template>
182       </xsl:when>
183       <xsl:otherwise>
184        <xsl:value-of select="substring-before($txt,' ')" />
185       </xsl:otherwise>
186      </xsl:choose>
187     </xsl:variable>
188     <!-- print line and newline -->
189     <xsl:value-of select="$line" />
190     <xsl:text>
191           </xsl:text>
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))" />
195     </xsl:call-template>
196    </xsl:otherwise>
197   </xsl:choose>
198  </xsl:template>
199
200  <!-- template to trim line to contain space as last char -->
201  <xsl:template name="find-line">
202   <xsl:param name="txt" />
203   <xsl:choose>
204    <xsl:when test="substring($txt,string-length($txt),1) = ' '">
205     <xsl:value-of select="normalize-space($txt)" />
206    </xsl:when>
207    <xsl:otherwise>
208     <xsl:call-template name="find-line">
209      <xsl:with-param name="txt" select="substring($txt,1,string-length($txt)-1)" />
210     </xsl:call-template>
211    </xsl:otherwise>
212   </xsl:choose>
213  </xsl:template>
214
215 </xsl:stylesheet>