Page 1 of 1

Schematron: spacing before <ph> element

Posted: Fri Apr 23, 2021 2:47 pm
by pieterjan_vdw
I found a Schematron rule on Stack Overflow to check spaces before inline elements which is very handy.
https://stackoverflow.com/questions/375 ... schematron

Code: Select all

	<sch:pattern id="space-inline-elements-before">
		<sch:rule context="ph">
			<sch:assert test="ends-with(preceding::text()[1], ' ')" 
				role="warning" 
				sqf:fix="add-space-before-ph">Add space before &lt;ph&gt;</sch:assert>
			<sqf:fix id="add-space-before-ph">
				<sqf:description>
					<sqf:title>Add space before &lt;ph&gt;</sqf:title>
				</sqf:description>
				<sqf:add position="before" match="." select="' '"/>
			</sqf:fix>
		</sch:rule>
	</sch:pattern>
	

It helps me to find spaces around <ph> tags.
However it doesn't work when the Indent inline elements is ticked in the preferences.
indent-line-elements.png
indent-line-elements.png (12.29 KiB) Viewed 981 times
This is how it looks like in Author mode with Indent inline elements option ticked:
example-author-mode.png
example-author-mode.png (5.84 KiB) Viewed 981 times
This is the same example in Text mode with Indent inline elements option ticked:
example-text-mode.png
example-text-mode.png (32.48 KiB) Viewed 981 times
How can I update the rule in such a way that it doens't show this message when the Indent inline elements is ticked? Because in the Author mode I can see a space.

Re: Schematron: spacing before <ph> element

Posted: Mon Apr 26, 2021 4:23 pm
by Radu
Hi Pieterjan,

The Author mode does not present the content exactly as it is in the XML, if it did you would have a lot of indentation and line breaks in the visual editor. So it normalizes consecutive new lines and spaces in the XML content and presents them as a single space.
Your Schematron is applied on the serialized XML content so it needs to be flexible enough to take any case into account, maybe have the condition check if the string length of the previous text is > 0 but the string length of the "normalize-space()" of the previous text is 0.

Regards,
Radu

Re: Schematron: spacing before <ph> element

Posted: Wed Apr 28, 2021 4:27 pm
by pieterjan_vdw
Thank you Radu. I'll try to update it with your suggestions.
Pieterjan