def nmtoken_from_string(text):
text = text.replace('<STR_LIT:->', '<STR_LIT>')<EOL>return '<STR_LIT>'.join([(((not char.isalnum() and char not in [<EOL>'<STR_LIT:.>', '<STR_LIT:->', '<STR_LIT:_>', '<STR_LIT::>'<EOL>]) and str(ord(char))) or char) for char in text])<EOL>
Returns a Nmtoken from a string.
It is useful to produce XHTML valid values for the 'name'
attribute of an anchor.

CAUTION: the function is surjective: 2 different texts might lead to
the same result. This is improbable on a single page.

Nmtoken is the type that is a mixture of characters supported in
attributes such as 'name' in HTML 'a' tag. For example,
<a name="Articles%20%26%20Preprints"> should be tranformed to
<a name="Articles372037263720Preprints"> using this function.
http://www.w3.org/TR/2000/REC-xml-20001006#NT-Nmtoken

Also note that this function filters more characters than
specified by the definition of Nmtoken ('CombiningChar' and
'Extender' charsets are filtered out).