Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSL - Remove non breaking space

In my XSL implementation (2.0), I tried using the below statement to remove all the spaces & non breaking spaces within a text node. It works for spaces only but not for non breaking spaces whose ASCII codes are,                              ​  etc. I am using SAXON processor for execution.

Current XSL code:

translate(normalize-space($text-nodes[1]),  ' ' , '' ))

How can I have them removed. Please share your thoughts.

like image 245
Rachel Avatar asked Feb 24 '23 12:02

Rachel


1 Answers

Those codes are Unicode, not ASCII (for the most part), so you should probably use the replace function with a regex containing the Unicode separator character class:

replace($text-nodes[1], '\p{Z}+', '')

In more detail:

The regex \p{Z}+ matches one or more characters that are in the "separator" category in Unicode. \p{} is the category escape sequence, which matches a single character in the category specified within the curly braces. Z specifies the "separator" category (which includes various kinds of whitespace). + means "match the preceding regex one or more times". The replace function returns a version of its first argument with all non-overlapping substrings matching its second argument replaced with its third argument. So this returns a version of $text-nodes[1] with all sequences of separator characters replaced with the empty string, i.e. removed.

like image 137
wdebeaum Avatar answered Mar 04 '23 14:03

wdebeaum