Preserve Whitespace For Elements with Specific Text

Having trouble installing Oxygen? Got a bug to report? Post it all here.
dreifsnider
Posts: 105
Joined: Thu Aug 30, 2018 10:06 pm

Preserve Whitespace For Elements with Specific Text

Post by dreifsnider »

Hi Oxygen Folks,

I'm attempting to use the Preserve space list in the Preferences under Editor / Format / XML / Elements Spacing to preserve spaces for elements that contain specific text; however, this does not work as expected.

Specifically, I'd like to be able to preserve the space for any ph element that contains text wrapped in quotation marks. The Xpath that I'm attempting to use is:

Code: Select all

ph[text()[matches(., '"[a-z|A-Z|\s]*"')]]
This Xpath works as expected when using the Xpath/Xquery Builder view, meaning that the ph elements are selected. However, any ph elements that contain matching text are still broken into multiple lines when using the Format and Indent operation.

For context why I'd like to preserve the space in ph elements that have text wrapped in quotation marks, we have an additional transformation post-processing tool that identifies text wrapped in quotation marks and compares it to a list of web page titles. If a matching title is found the tool builds a link between the text and the page. However, this tool does not work for text that spans across multiple lines and thus we want to preserve the spaces (and ultimately lines) for this text.

Thank you!
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Preserve Whitespace For Elements with Specific Text

Post by Radu »

Hi,
In the Oxygen Preferences->"Editor / Format / XML / Elements Spacing" there is this message on top of the list of defined elements:
Screenshot 2024-02-05 at 07.43.31.png
Screenshot 2024-02-05 at 07.43.31.png (71.07 KiB) Viewed 408 times
So the XPath expressions need to be simple (name and attribute tests). We do not support pattern matching on the text content of elements.
Ideally you would mark such ph elements with a certain "outputclass" attribute value and then match them based on that outputclass value.

https://www.oxygenxml.com/doc/ug-editor ... ng-section

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
dreifsnider
Posts: 105
Joined: Thu Aug 30, 2018 10:06 pm

Re: Preserve Whitespace For Elements with Specific Text

Post by dreifsnider »

Hi Radu,

Thank you for the reply! I understand about the name and attribute test, although I found the term "simple" to be ambiguous, hence my question.

Would it be possible to support more advanced XPath expressions in a future version? It would be nice if we had even greater granular control over determining what is affected by the Format and Indent operation.

Thank you!

Daniel
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Preserve Whitespace For Elements with Specific Text

Post by Radu »

Hi Daniel,

I added an internal issue based on your request, pasting the issue ID for future reference:

EXM-54178 Improve xpath evaluation for preserve space elements to check in elements text

I'm skeptical the issue will get implement, we are not running the XPath expressions with the XSLT processor, we have our small engine which runs very simple expressions.
For example for your xpath:

Code: Select all

ph[text()[matches(., '"[a-z|A-Z|\s]*"')]]
our small engine would need to start supporting the text() function and a matches() function with regular expressions.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Preserve Whitespace For Elements with Specific Text

Post by chrispitude »

Hi dreifsnider,

What language is your post-processing tool written in? Maybe it can be upgraded to normalize spaces in each string before it compares them?

"Normalizing spaces" typically means replace multiple spaces/newlines with a single space, and removing leading/trailing whitespace completely.
dreifsnider
Posts: 105
Joined: Thu Aug 30, 2018 10:06 pm

Re: Preserve Whitespace For Elements with Specific Text

Post by dreifsnider »

Hi Radu,
I'm skeptical the issue will get implement, we are not running the XPath expressions with the XSLT processor, we have our small engine which runs very simple expressions.
I understand your standpoint. My team would still find it a valuable addition, as we've discovered that the Preserve text as is option does not consistently work for non-roman characters, specifically Japanese. Therefore, we've been hoping to use more advanced Xpath and Regex expressions to better identify multi-alphabet characters.

Hi chrispitude,
What language is your post-processing tool written in? Maybe it can be upgraded to normalize spaces in each string before it compares them?
I'm not the original developer of the post processing tool, so I'm unsure what language it was written in or if it is even still is actively maintained. I'll reach out to some of my contacts with this suggestion though, as it would indeed be a better experience than requiring the XML text be formatted a specific way.

Thanks!
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Preserve Whitespace For Elements with Specific Text

Post by Radu »

Hi Daniel,
About this remark:
My team would still find it a valuable addition, as we've discovered that the Preserve text as is option does not consistently work for non-roman characters, specifically Japanese.
Could you elaborate maybe with some steps and an example?
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
dreifsnider
Posts: 105
Joined: Thu Aug 30, 2018 10:06 pm

Re: Preserve Whitespace For Elements with Specific Text

Post by dreifsnider »

Hi Radu,

I'll check with my Japanese colleagues to see if they can reproduce this.

Thanks,

Daniel
Post Reply