Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
54 | PointedEar | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <xsl:stylesheet version="1.0" |
||
3 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict"> |
||
4 | <xsl:output method="text" indent="no" media-type="text/plain" encoding="UTF-8" /> |
||
5 | <xsl:strip-space elements="*" /> |
||
6 | |||
7 | <xsl:template match="/"> |
||
8 | <xsl:text># vim:set fileencoding=utf-8 tabstop=2 shiftwidth=2 softtabstop=2 expandtab: |
||
9 | </xsl:text> |
||
10 | <xsl:apply-templates /> |
||
11 | </xsl:template> |
||
12 | |||
13 | <xsl:template match="Rule"> |
||
14 | <xsl:variable |
||
15 | name="supported_rule" |
||
16 | select="@linkmode = 'OR' or (@linkmode = 'AND' and not(Expression[2]))" /> |
||
17 | <xsl:variable |
||
18 | name="killfiled" |
||
19 | select="Action[@type='SETSCORE']/@value <= -100" /> |
||
20 | |||
21 | <xsl:if test="$supported_rule and $killfiled"> |
||
22 | <!-- <xsl:text># </xsl:text> |
||
23 | <xsl:value-of select="@name" /> |
||
24 | <xsl:text> |
||
25 | </xsl:text> --> |
||
26 | <xsl:apply-templates /> |
||
27 | </xsl:if> |
||
28 | </xsl:template> |
||
29 | |||
30 | <xsl:template match="Expression"> |
||
31 | <xsl:variable name="ignored_headers"> |
||
32 | <header name="Newsgroups"/> |
||
33 | <header name="Followup-To"/> |
||
34 | </xsl:variable> |
||
35 | <xsl:variable name="allowed_header"> |
||
36 | <xsl:value-of |
||
37 | select="not(document('')//xsl:variable[@name = 'ignored_headers']/@name[text() = @header])"/> |
||
38 | </xsl:variable> |
||
39 | |||
40 | <xsl:if test="@neg != '1' and $allowed_header"> |
||
41 | <xsl:variable name="expr"> |
||
42 | <xsl:choose> |
||
43 | <xsl:when test="@type = 'MATCH'"> |
||
44 | <xsl:value-of select="@expr" /> |
||
45 | </xsl:when> |
||
46 | <xsl:otherwise> |
||
47 | <xsl:call-template name="string-pcre-escape"> |
||
48 | <xsl:with-param name="text" select="@expr" /> |
||
49 | </xsl:call-template> |
||
50 | </xsl:otherwise> |
||
51 | </xsl:choose> |
||
52 | </xsl:variable> |
||
53 | |||
54 | <xsl:text>^</xsl:text> |
||
55 | <xsl:value-of select="@header" /> |
||
56 | <xsl:text>:.*</xsl:text> |
||
57 | <xsl:call-template name="string-char-escape"> |
||
58 | <xsl:with-param name="text" select="$expr" /> |
||
59 | </xsl:call-template> |
||
60 | <xsl:text> |
||
61 | </xsl:text> |
||
62 | </xsl:if> |
||
63 | </xsl:template> |
||
64 | |||
65 | <xsl:template name="string-pcre-escape"> |
||
66 | <xsl:param name="text" /> |
||
67 | <xsl:call-template name="string-translate-all"> |
||
68 | <xsl:with-param name="text" select="$text" /> |
||
69 | <xsl:with-param name="replace" select="'.|+'" /> |
||
70 | <xsl:with-param name="by" select="'\.|\+'" /> |
||
71 | <xsl:with-param name="separator" select="'|'" /> |
||
72 | </xsl:call-template> |
||
73 | </xsl:template> |
||
74 | |||
75 | <xsl:template name="string-char-escape"> |
||
76 | <xsl:param name="text" /> |
||
77 | <xsl:call-template name="string-translate-all"> |
||
78 | <xsl:with-param name="text" select="$text" /> |
||
79 | <xsl:with-param name="replace" select="'ä|ë|é|é |ö|ü| '" /> |
||
80 | <xsl:with-param name="by" select="'.+|.+|.+|.+|.+|.+|.+'" /> |
||
81 | <xsl:with-param name="separator" select="'|'" /> |
||
82 | </xsl:call-template> |
||
83 | </xsl:template> |
||
84 | |||
85 | <xsl:template name="string-translate-all"> |
||
86 | <xsl:param name="text" /> |
||
87 | <xsl:param name="replace" /> |
||
88 | <xsl:param name="by" /> |
||
89 | <xsl:param name="separator" /> |
||
90 | <xsl:choose> |
||
91 | <xsl:when test="$separator and contains($replace, $separator)"> |
||
92 | <xsl:variable name="text2"> |
||
93 | <xsl:call-template name="string-translate-all"> |
||
94 | <xsl:with-param name="text" select="$text" /> |
||
95 | <xsl:with-param name="replace" |
||
96 | select="substring-before($replace, $separator)" /> |
||
97 | <xsl:with-param name="by" |
||
98 | select="substring-before($by, $separator)" /> |
||
99 | <xsl:with-param name="separator" select="$separator" /> |
||
100 | </xsl:call-template> |
||
101 | </xsl:variable> |
||
102 | <xsl:call-template name="string-translate-all"> |
||
103 | <xsl:with-param name="text" select="$text2" /> |
||
104 | <xsl:with-param name="replace" |
||
105 | select="substring-after($replace, $separator)" /> |
||
106 | <xsl:with-param name="by" |
||
107 | select="substring-after($by, $separator)" /> |
||
108 | <xsl:with-param name="separator" select="$separator" /> |
||
109 | </xsl:call-template> |
||
110 | </xsl:when> |
||
111 | <xsl:otherwise> |
||
112 | <xsl:choose> |
||
113 | <xsl:when test="contains($text, $replace)"> |
||
114 | <xsl:value-of select="substring-before($text,$replace)" /> |
||
115 | <xsl:value-of select="$by" /> |
||
116 | <xsl:call-template name="string-replace-all"> |
||
117 | <xsl:with-param name="text" |
||
118 | select="substring-after($text,$replace)" /> |
||
119 | <xsl:with-param name="replace" select="$replace" /> |
||
120 | <xsl:with-param name="by" select="$by" /> |
||
121 | </xsl:call-template> |
||
122 | </xsl:when> |
||
123 | <xsl:otherwise> |
||
124 | <xsl:value-of select="$text" /> |
||
125 | </xsl:otherwise> |
||
126 | </xsl:choose> |
||
127 | </xsl:otherwise> |
||
128 | </xsl:choose> |
||
129 | </xsl:template> |
||
130 | |||
131 | <xsl:template name="string-replace-all"> |
||
132 | <xsl:param name="text" /> |
||
133 | <xsl:param name="replace" /> |
||
134 | <xsl:param name="by" /> |
||
135 | <xsl:choose> |
||
136 | <xsl:when test="contains($text, $replace)"> |
||
137 | <xsl:value-of select="substring-before($text, $replace)" /> |
||
138 | <xsl:value-of select="$by" /> |
||
139 | <xsl:call-template name="string-replace-all"> |
||
140 | <xsl:with-param name="text" |
||
141 | select="substring-after($text, $replace)" /> |
||
142 | <xsl:with-param name="replace" select="$replace" /> |
||
143 | <xsl:with-param name="by" select="$by" /> |
||
144 | </xsl:call-template> |
||
145 | </xsl:when> |
||
146 | <xsl:otherwise> |
||
147 | <xsl:value-of select="$text" /> |
||
148 | </xsl:otherwise> |
||
149 | </xsl:choose> |
||
150 | </xsl:template> |
||
151 | </xsl:stylesheet> |