From 9880da710603fe1d18dfac732b904bca4cc26f5f Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Wed, 25 Nov 2015 23:28:12 +0100 Subject: utils_xslt: xslt_id_friendly: new helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some offending ASCII characters are translated to '_', the remaining ones (all or almost) are simply removed. Signed-off-by: Jan Pokorný --- utils_xslt.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utils_xslt.py b/utils_xslt.py index 2e09582..de4ec02 100644 --- a/utils_xslt.py +++ b/utils_xslt.py @@ -41,3 +41,18 @@ def xslt_params(**d): k, xslt_boolean(v) if isinstance(v, bool) else v ) return ret + + +def xslt_id_friendly(inner): + """Make the passed XPath expression yielding string XML ID friendly""" + # XXX apostrophe missing + return '''\ + translate( + translate( + {0}, + ' -/:', + '____' + ), + '!"#$%&()*+,;<=>?@[\]^`{{|}}~', + '' + )'''.format(inner) -- cgit