0,0 → 1,151 |
<?xml version="1.0" encoding="UTF-8"?> |
<xsl:stylesheet version="1.0" |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict"> |
<xsl:output method="text" indent="no" media-type="text/plain" encoding="UTF-8" /> |
<xsl:strip-space elements="*" /> |
|
<xsl:template match="/"> |
<xsl:text># vim:set fileencoding=utf-8 tabstop=2 shiftwidth=2 softtabstop=2 expandtab: |
</xsl:text> |
<xsl:apply-templates /> |
</xsl:template> |
|
<xsl:template match="Rule"> |
<xsl:variable |
name="supported_rule" |
select="@linkmode = 'OR' or (@linkmode = 'AND' and not(Expression[2]))" /> |
<xsl:variable |
name="killfiled" |
select="Action[@type='SETSCORE']/@value <= -100" /> |
|
<xsl:if test="$supported_rule and $killfiled"> |
<!-- <xsl:text># </xsl:text> |
<xsl:value-of select="@name" /> |
<xsl:text> |
</xsl:text> --> |
<xsl:apply-templates /> |
</xsl:if> |
</xsl:template> |
|
<xsl:template match="Expression"> |
<xsl:variable name="ignored_headers"> |
<header name="Newsgroups"/> |
<header name="Followup-To"/> |
</xsl:variable> |
<xsl:variable name="allowed_header"> |
<xsl:value-of |
select="not(document('')//xsl:variable[@name = 'ignored_headers']/@name[text() = @header])"/> |
</xsl:variable> |
|
<xsl:if test="@neg != '1' and $allowed_header"> |
<xsl:variable name="expr"> |
<xsl:choose> |
<xsl:when test="@type = 'MATCH'"> |
<xsl:value-of select="@expr" /> |
</xsl:when> |
<xsl:otherwise> |
<xsl:call-template name="string-pcre-escape"> |
<xsl:with-param name="text" select="@expr" /> |
</xsl:call-template> |
</xsl:otherwise> |
</xsl:choose> |
</xsl:variable> |
|
<xsl:text>^</xsl:text> |
<xsl:value-of select="@header" /> |
<xsl:text>:.*</xsl:text> |
<xsl:call-template name="string-char-escape"> |
<xsl:with-param name="text" select="$expr" /> |
</xsl:call-template> |
<xsl:text> |
</xsl:text> |
</xsl:if> |
</xsl:template> |
|
<xsl:template name="string-pcre-escape"> |
<xsl:param name="text" /> |
<xsl:call-template name="string-translate-all"> |
<xsl:with-param name="text" select="$text" /> |
<xsl:with-param name="replace" select="'.|+'" /> |
<xsl:with-param name="by" select="'\.|\+'" /> |
<xsl:with-param name="separator" select="'|'" /> |
</xsl:call-template> |
</xsl:template> |
|
<xsl:template name="string-char-escape"> |
<xsl:param name="text" /> |
<xsl:call-template name="string-translate-all"> |
<xsl:with-param name="text" select="$text" /> |
<xsl:with-param name="replace" select="'ä|ë|é|é |ö|ü| '" /> |
<xsl:with-param name="by" select="'.+|.+|.+|.+|.+|.+|.+'" /> |
<xsl:with-param name="separator" select="'|'" /> |
</xsl:call-template> |
</xsl:template> |
|
<xsl:template name="string-translate-all"> |
<xsl:param name="text" /> |
<xsl:param name="replace" /> |
<xsl:param name="by" /> |
<xsl:param name="separator" /> |
<xsl:choose> |
<xsl:when test="$separator and contains($replace, $separator)"> |
<xsl:variable name="text2"> |
<xsl:call-template name="string-translate-all"> |
<xsl:with-param name="text" select="$text" /> |
<xsl:with-param name="replace" |
select="substring-before($replace, $separator)" /> |
<xsl:with-param name="by" |
select="substring-before($by, $separator)" /> |
<xsl:with-param name="separator" select="$separator" /> |
</xsl:call-template> |
</xsl:variable> |
<xsl:call-template name="string-translate-all"> |
<xsl:with-param name="text" select="$text2" /> |
<xsl:with-param name="replace" |
select="substring-after($replace, $separator)" /> |
<xsl:with-param name="by" |
select="substring-after($by, $separator)" /> |
<xsl:with-param name="separator" select="$separator" /> |
</xsl:call-template> |
</xsl:when> |
<xsl:otherwise> |
<xsl:choose> |
<xsl:when test="contains($text, $replace)"> |
<xsl:value-of select="substring-before($text,$replace)" /> |
<xsl:value-of select="$by" /> |
<xsl:call-template name="string-replace-all"> |
<xsl:with-param name="text" |
select="substring-after($text,$replace)" /> |
<xsl:with-param name="replace" select="$replace" /> |
<xsl:with-param name="by" select="$by" /> |
</xsl:call-template> |
</xsl:when> |
<xsl:otherwise> |
<xsl:value-of select="$text" /> |
</xsl:otherwise> |
</xsl:choose> |
</xsl:otherwise> |
</xsl:choose> |
</xsl:template> |
|
<xsl:template name="string-replace-all"> |
<xsl:param name="text" /> |
<xsl:param name="replace" /> |
<xsl:param name="by" /> |
<xsl:choose> |
<xsl:when test="contains($text, $replace)"> |
<xsl:value-of select="substring-before($text, $replace)" /> |
<xsl:value-of select="$by" /> |
<xsl:call-template name="string-replace-all"> |
<xsl:with-param name="text" |
select="substring-after($text, $replace)" /> |
<xsl:with-param name="replace" select="$replace" /> |
<xsl:with-param name="by" select="$by" /> |
</xsl:call-template> |
</xsl:when> |
<xsl:otherwise> |
<xsl:value-of select="$text" /> |
</xsl:otherwise> |
</xsl:choose> |
</xsl:template> |
</xsl:stylesheet> |
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: network/news/newsstat/scorefile2filters.py |
=================================================================== |
--- network/news/newsstat/scorefile2filters.py (nonexistent) |
+++ network/news/newsstat/scorefile2filters.py (revision 54) |
@@ -0,0 +1,14 @@ |
+#!/usr/bin/env python3 |
+ |
+from sys import argv |
+from lxml import etree |
+from os.path import dirname |
+ |
+if __name__ == "__main__": |
+ with open(argv[1]) as scorefile: |
+ scorefile_tree = etree.parse(scorefile) |
+ with open(dirname(argv[0]) + '/scorefile2filters.xsl') as stylesheet: |
+ stylesheet_tree = etree.parse(stylesheet) |
+ transform = etree.XSLT(stylesheet_tree) |
+ filterfile_text = transform(scorefile_tree) |
+ print(filterfile_text) |