Search code examples
xsltnon-ascii-characters

Create an xslt function for checking if a string contains non-ASCI characters


i want to check via and xslt function if a string of an..17 and if a character like this fould it will be replaced with underscore _. My problem is that i dont know how to implement with the specific set of non ASCI characters. Should i create a set of the non ASCI characters and iterate through the string? Any ideas?


Solution

  • In XSLT 2.0 or higher you can do:

    replace($yourString, '[^\p{IsBasic_Latin}]', '_')
    

    to replace all non-ASCII characters with an underscore.

    Note that this will preserve all ASCII characters - including non-printable control codes.