I have a source document with backslashes in the file name (windows paths). But there are also lots of other characters that would be invalid. I propose replacing all non-valid characters with underscores.
I transcribed the rules as close as possible to the W3 Recommendation ruleset to make it easier to verify.
The full ID rules are a little more restrictive (some of the allowed chars above are not valid as the first chars), but this is a good compromise for simplicity.
I have a source document with backslashes in the file name (windows paths). But there are also lots of other characters that would be invalid. I propose replacing all non-valid characters with underscores. I transcribed the rules as close as possible to the W3 Recommendation ruleset to make it easier to verify. The full ID rules are a little more restrictive (some of the allowed chars above are not valid as the first chars), but this is a good compromise for simplicity.