XSL - Remove Unused Space

In my implementation of XSL (2.0), I tried to use the operator below to remove all spaces and inextricable spaces in node text. It works only for spaces, but not for inextricable spaces, ASCII codes are                               ​                                ​  etc. I am using a SAXON processor to execute.

Current XSL Code:

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

How can I delete them. Please share your thoughts.

+4
source share
1 answer

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

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

More details:

The regular expression \p{Z}+ matches one or more characters that are in the Unicode separator category. \p{} is an escape category that matches a single character in the category indicated in curly braces. Z indicates the category "delimiter" (which includes various types of spaces). + means "match the previous regular expression one or more times." The replace function returns the version of its first argument with all nonoverlapping substrings matching the second argument, replaced by the third argument. Thus, this returns the version of $text-nodes[1] , while all sequences of separator characters are replaced by an empty string, ie Are deleted.

+8
source

Source: https://habr.com/ru/post/1347778/


All Articles