Page 1 of 1
Preserve Whitespace For Elements with Specific Text
Posted: Fri Feb 02, 2024 10:59 pm
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!
Re: Preserve Whitespace For Elements with Specific Text
Posted: Mon Feb 05, 2024 8:46 am
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
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
Re: Preserve Whitespace For Elements with Specific Text
Posted: Mon Feb 05, 2024 10:38 pm
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
Re: Preserve Whitespace For Elements with Specific Text
Posted: Tue Feb 06, 2024 8:53 am
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
Re: Preserve Whitespace For Elements with Specific Text
Posted: Sun Feb 11, 2024 4:21 pm
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.
Re: Preserve Whitespace For Elements with Specific Text
Posted: Wed Feb 14, 2024 2:18 am
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!
Re: Preserve Whitespace For Elements with Specific Text
Posted: Thu Feb 15, 2024 8:52 am
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
Re: Preserve Whitespace For Elements with Specific Text
Posted: Tue Feb 20, 2024 10:01 pm
by dreifsnider
Hi Radu,
I'll check with my Japanese colleagues to see if they can reproduce this.
Thanks,
Daniel