comparison docs/xslt/changes.xslt @ 4047:3e706fcccbf3 stable-1.0

Merge of r3996, r3998, r4015, r4023, r4025, r4026, r4027: Changes log build procedure fixes: *) using sed instead of perl *) support <br/> in the middle of input *) fixed "<br>" lookup (eliminates the need in " <br/>" hacks) *) fixed maximum length for unbreakable input *) fixed space lookup (allows a space at column 77 to break a line) *) traling spaces removal in text CHANGES files.
author Igor Sysoev <igor@sysoev.ru>
date Mon, 29 Aug 2011 13:57:43 +0000
parents 551102312e19
children f872a86a655c
comparison
equal deleted inserted replaced
4046:fd6f821d3fa2 4047:3e706fcccbf3
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3 3
4 <xsl:output encoding="koi8-r" method="text"/> 4 <xsl:output encoding="koi8-r" method="text"/>
5 5
6 <xsl:param select="'en'" name="lang"/> 6 <xsl:param select="'en'" name="lang"/>
7
7 <xsl:param select="'../xml/change_log_conf.xml'" name="configuration"/> 8 <xsl:param select="'../xml/change_log_conf.xml'" name="configuration"/>
8 9
9 <xsl:variable select="document($configuration)/configuration" name="conf"/> 10 <xsl:variable select="document($configuration)/configuration" name="conf"/>
11
10 <xsl:variable select="$conf/start" name="start"/> 12 <xsl:variable select="$conf/start" name="start"/>
13
11 <xsl:variable select="$conf/indent" name="indent"/> 14 <xsl:variable select="$conf/indent" name="indent"/>
15
12 <xsl:variable select="$conf/length" name="max"/> 16 <xsl:variable select="$conf/length" name="max"/>
17
13 <xsl:variable name="br">&lt;br&gt;</xsl:variable> 18 <xsl:variable name="br">&lt;br&gt;</xsl:variable>
14 19
15 <xsl:template match="/"> 20 <xsl:template match="/">
16 <xsl:apply-templates select="change_log"/> 21 <xsl:apply-templates select="change_log"/>
17 </xsl:template> 22 </xsl:template>
18 23
19 <xsl:template match="change_log"> 24 <xsl:template match="change_log">
20 <xsl:apply-templates select="changes"/> 25 <xsl:apply-templates select="changes"/>
21 </xsl:template> 26 </xsl:template>
22 27
23 <xsl:template match="changes"> 28 <xsl:template match="changes">
29
24 <xsl:text> 30 <xsl:text>
25 </xsl:text> 31 </xsl:text>
26 32
27 <xsl:value-of select="substring(concat($conf/changes[@lang=$lang]/title, //change_log/@title, ' ', @ver, ' '), 1, $conf/changes[@lang=$lang]/length)"/> 33 <xsl:value-of select="substring(concat($conf/changes[@lang=$lang]/title, //change_log/@title, ' ', @ver, ' '), 1, $conf/changes[@lang=$lang]/length)"/>
28 34
29 <xsl:if test="$lang='ru'"> 35 <xsl:if test="$lang='ru'">
30 <xsl:value-of select="@date"/> 36 <xsl:value-of select="@date"/>
31 </xsl:if> 37 </xsl:if>
32 38
33 <xsl:if test="$lang='en'"> 39 <xsl:if test="$lang='en'">
40
34 <xsl:value-of select="substring(@date, 1, 2)"/> 41 <xsl:value-of select="substring(@date, 1, 2)"/>
42
35 <xsl:value-of select="$conf/changes[@lang=$lang]/month[number(substring(current()/@date, 4, 2))]"/> 43 <xsl:value-of select="$conf/changes[@lang=$lang]/month[number(substring(current()/@date, 4, 2))]"/>
44
36 <xsl:value-of select="substring(@date, 7, 4)"/> 45 <xsl:value-of select="substring(@date, 7, 4)"/>
37 </xsl:if> 46 </xsl:if>
47
38 <xsl:text> 48 <xsl:text>
39 </xsl:text> 49 </xsl:text>
40 50
41 <xsl:apply-templates select="change"/> 51 <xsl:apply-templates select="change"/>
42 52
43 <xsl:text> 53 <xsl:text>
44 </xsl:text> 54 </xsl:text>
45 </xsl:template> 55 </xsl:template>
46 56
47
48 <xsl:template match="change"> 57 <xsl:template match="change">
58
49 <xsl:variable select="$conf/changes[@lang=$lang]/*[local-name(.)=current()/@type]" name="prefix"/> 59 <xsl:variable select="$conf/changes[@lang=$lang]/*[local-name(.)=current()/@type]" name="prefix"/>
50 60
51 <xsl:variable name="postfix"> 61 <xsl:variable name="postfix">
52 <xsl:if test="$prefix"> 62 <xsl:if test="$prefix">
53 <xsl:text>: </xsl:text> 63 <xsl:text>: </xsl:text>
57 <xsl:apply-templates select="para[@lang=$lang]"> 67 <xsl:apply-templates select="para[@lang=$lang]">
58 <xsl:with-param select="concat($start, $prefix, $postfix)" name="prefix"/> 68 <xsl:with-param select="concat($start, $prefix, $postfix)" name="prefix"/>
59 </xsl:apply-templates> 69 </xsl:apply-templates>
60 </xsl:template> 70 </xsl:template>
61 71
62
63 <xsl:template match="para" name="para"> 72 <xsl:template match="para" name="para">
64 <xsl:param name="prefix"/> 73 <xsl:param name="prefix"/>
74
65 <xsl:variable name="text"> 75 <xsl:variable name="text">
66 <xsl:apply-templates/> 76 <xsl:apply-templates/>
67 </xsl:variable> 77 </xsl:variable>
68 78
69 <xsl:text> 79 <xsl:text>
71 81
72 <xsl:call-template name="wrap"> 82 <xsl:call-template name="wrap">
73 <xsl:with-param select="normalize-space($text)" name="text"/> 83 <xsl:with-param select="normalize-space($text)" name="text"/>
74 <xsl:with-param name="prefix"> 84 <xsl:with-param name="prefix">
75 <xsl:choose> 85 <xsl:choose>
86
76 <xsl:when test="position() = 1"> 87 <xsl:when test="position() = 1">
77 <xsl:value-of select="$prefix"/> 88 <xsl:value-of select="$prefix"/>
78 </xsl:when> 89 </xsl:when>
79 <xsl:otherwise> 90 <xsl:otherwise>
80 <xsl:value-of select="$indent"/> 91 <xsl:value-of select="$indent"/>
82 </xsl:choose> 93 </xsl:choose>
83 </xsl:with-param> 94 </xsl:with-param>
84 </xsl:call-template> 95 </xsl:call-template>
85 </xsl:template> 96 </xsl:template>
86 97
87
88 <xsl:template name="wrap"> 98 <xsl:template name="wrap">
89 <xsl:param name="text"/> 99 <xsl:param name="text"/>
90 <xsl:param name="prefix"/> 100 <xsl:param name="prefix"/>
101
91 <xsl:if test="$text"> 102 <xsl:if test="$text">
103
92 <xsl:variable name="offset"> 104 <xsl:variable name="offset">
105
93 <xsl:choose> 106 <xsl:choose>
94 <xsl:when test="starts-with($text, concat($br, ' '))"> 107 <xsl:when test="starts-with($text, concat($br, ' '))">
95 <xsl:value-of select="string-length($br) + 2"/> 108 <xsl:value-of select="string-length($br) + 2"/>
96 </xsl:when> 109 </xsl:when>
110 <xsl:when test="starts-with($text, $br)">
111 <xsl:value-of select="string-length($br) + 1"/>
112 </xsl:when>
97 <xsl:otherwise> 113 <xsl:otherwise>
98 1</xsl:otherwise> 114 1</xsl:otherwise>
99 </xsl:choose> 115 </xsl:choose>
100 </xsl:variable> 116 </xsl:variable>
101 117
102 <xsl:variable name="length"> 118 <xsl:variable name="length">
119
103 <xsl:call-template name="length"> 120 <xsl:call-template name="length">
104 <xsl:with-param select="substring($text, $offset)" name="text"/> 121 <xsl:with-param select="substring($text, $offset)" name="text"/>
105 <xsl:with-param select="string-length($prefix)" name="prefix"/> 122 <xsl:with-param select="string-length($prefix)" name="prefix"/>
106 <xsl:with-param select="$max" name="length"/> 123 <xsl:with-param select="$max" name="length"/>
107 </xsl:call-template> 124 </xsl:call-template>
108 </xsl:variable> 125 </xsl:variable>
126
109 <xsl:value-of select="$prefix"/> 127 <xsl:value-of select="$prefix"/>
110 128
111 <xsl:value-of select="translate(substring($text, $offset, $length), ' ', ' ')"/> 129 <xsl:value-of select="normalize-space(translate(substring($text, $offset, $length), ' ', ' '))"/>
112 130
113 <xsl:text> 131 <xsl:text>
114 </xsl:text> 132 </xsl:text>
115 133
116 <xsl:call-template name="wrap"> 134 <xsl:call-template name="wrap">
117 <xsl:with-param select="substring($text, $length + $offset)" name="text"/> 135 <xsl:with-param select="substring($text, $length + $offset)" name="text"/>
118 <xsl:with-param select="$indent" name="prefix"/> 136 <xsl:with-param select="$indent" name="prefix"/>
119 </xsl:call-template> 137 </xsl:call-template>
120 </xsl:if> 138 </xsl:if>
121 </xsl:template> 139 </xsl:template>
122 140
123 <xsl:template name="length"> 141 <xsl:template name="length">
124 <xsl:param name="text"/> 142 <xsl:param name="text"/>
125 <xsl:param name="prefix"/> 143 <xsl:param name="prefix"/>
126 <xsl:param name="length"/> 144 <xsl:param name="length"/>
127 <xsl:variable select="substring-before(substring($text, 1, $length - $prefix), $br)" name="break"/> 145
146 <xsl:variable select="substring-before(substring($text, 1, $length - $prefix + string-length($br)), $br)" name="break"/>
147
128 <xsl:choose> 148 <xsl:choose>
129 <xsl:when test="$break"> 149 <xsl:when test="$break">
130 <xsl:value-of select="string-length($break)"/> 150 <xsl:value-of select="string-length($break)"/>
131 </xsl:when> 151 </xsl:when>
132 <xsl:when test="$length = 0"> 152 <xsl:when test="$length = 0">
133 <xsl:value-of select="$max"/> 153 <xsl:value-of select="$max - $prefix"/>
134 </xsl:when> 154 </xsl:when>
135 <xsl:when test="string-length($text) + $prefix &lt;= $length or substring($text, $length - $prefix, 1) = ' '"> 155 <xsl:when test="string-length($text) + $prefix &lt;= $length">
136 <xsl:value-of select="$length - $prefix"/> 156 <xsl:value-of select="$length - $prefix"/>
137 </xsl:when> 157 </xsl:when>
158 <xsl:when test="substring($text, $length - $prefix + 1, 1) = ' '">
159 <xsl:value-of select="$length - $prefix + 1"/>
160 </xsl:when>
138 <xsl:otherwise> 161 <xsl:otherwise>
162
139 <xsl:call-template name="length"> 163 <xsl:call-template name="length">
140 <xsl:with-param select="$text" name="text"/> 164 <xsl:with-param select="$text" name="text"/>
141 <xsl:with-param select="$prefix" name="prefix"/> 165 <xsl:with-param select="$prefix" name="prefix"/>
142 <xsl:with-param select="$length - 1" name="length"/> 166 <xsl:with-param select="$length - 1" name="length"/>
143 </xsl:call-template> 167 </xsl:call-template>
144 </xsl:otherwise> 168 </xsl:otherwise>
145 </xsl:choose> 169 </xsl:choose>
146 </xsl:template> 170 </xsl:template>
147 171
148
149 <xsl:template match="at">@</xsl:template> 172 <xsl:template match="at">@</xsl:template>
150 173
151 <xsl:template match="br"> 174 <xsl:template match="br">
152 <xsl:value-of select="$br"/> 175 <xsl:value-of select="$br"/>
153 </xsl:template> 176 </xsl:template>
154 177
155 <xsl:template match="nobr"> 178 <xsl:template match="nobr">
156 <xsl:value-of select="translate(., ' ', ' ')"/> 179 <xsl:value-of select="translate(., ' ', ' ')"/>
157 </xsl:template> 180 </xsl:template>
181
158 </xsl:stylesheet> 182 </xsl:stylesheet>