Schematron: spacing before <ph> element

Post here questions and problems related to editing and publishing DITA content.
pieterjan_vdw
Posts: 41
Joined: Wed Jun 20, 2018 11:30 am

Schematron: spacing before <ph> element

Post 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 975 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 975 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 975 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.
Radu
Posts: 9045
Joined: Fri Jul 09, 2004 5:18 pm

Re: Schematron: spacing before <ph> element

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
pieterjan_vdw
Posts: 41
Joined: Wed Jun 20, 2018 11:30 am

Re: Schematron: spacing before <ph> element

Post by pieterjan_vdw »

Thank you Radu. I'll try to update it with your suggestions.
Pieterjan
Post Reply