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
This is how it looks like in Author mode with Indent inline elements option ticked:
example-author-mode.png
This is the same example in Text mode with Indent inline elements option ticked:
example-text-mode.png
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

Re: Schematron: spacing before <ph> element

Posted: Mon Feb 03, 2025 7:02 pm
by LASSE_MLE
<oXygen/> XML Editor 26.1, build 2024031806
Hello all!
I've used this solution to detect the missing spaces between <uicontrol> and it works perfectly.
But I never succeed doing the same thing with the <abbreviated-form> tags? Do you have an idea ?
Using

Code: Select all

  <sch:pattern>
    <sch:rule context="(ph|uicontrol|userinput|wintitle|q|cmdname|systemoutput|filepath|abbreviated-form)">
      <sch:assert test="ends-with(preceding::text()[1], ' ')" role="warning" sqf:fix="add-space-before">Add space before &lt;&gt;</sch:assert>
      <sqf:fix id="add-space-before">
        <sqf:description>
          <sqf:title>Add space before &lt;&gt;</sqf:title>
        </sqf:description>
        <sqf:add position="before" match="." select="' '"/>
      </sqf:fix>
    </sch:rule>
  </sch:pattern>
The following dita code:

Code: Select all

    <taskbody>
        <prereq><uicontrol>A</uicontrol><uicontrol>B</uicontrol></prereq>
        <context><ph>A</ph><ph>B</ph> <ul id="ul_fq3_vrd_g2c">
            <li><abbreviated-form keyref="A"/><abbreviated-form keyref="B"/></li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            </ul> </context>
        <steps>
            <step>
will raise warnings for the <uicontrol> and <ph> but not for the <abbreviated-form>? Strange no ?
Thank you for your help!
BR
Mathieu

Re: Schematron: spacing before <ph> element

Posted: Tue Feb 04, 2025 8:13 am
by Radu
Hi Mathieu,
In such cases you can experiment running the xpath expression directly in Oxygen, open the DITA task, place the caret directly inside the tag and then use the "XPath" toolbar to run the expression "preceding::text()[1]" to see what the XPath engine returns as a result.
The definition of the "preceding" axis:
preceding::
The preceding axis contains all nodes in the same document as the context node that are before the context node in document order, excluding any ancestors and excluding attribute nodes and namespace nodes.
So in the case of "abbreviated-form" it locates the indentation text before the <li> element

Code: Select all

                <li>
.

Regards,
Radu

Re: Schematron: spacing before <ph> element

Posted: Tue Feb 04, 2025 10:32 am
by LASSE_MLE
Hello Radu,

Thank you for your answer. Quick and sharp as usual :)
I've, at least, learn the XPath trick on Oxygen but, it's my fault, I did not specify my root need. More than adding a space before, my wish is to avoid the lack of spaces between abbreviated-form (and emphasized item in general)!
So, whatever its location, I'd like that oxygen and schematron indicates that

Code: Select all

<abbreviated-form keyref="A"/><abbreviated-form keyref="B"/>
is not correct.
I'm not sure to see have clearly understood your advice...

Re: Schematron: spacing before <ph> element

Posted: Tue Feb 04, 2025 10:34 am
by LASSE_MLE
I've just test something and

Code: Select all

<abbreviated-form keyref="A">A</abbreviated-form><abbreviated-form keyref="B"/>
is raising the warning I want...
Do I have to rewrite all my glossary entries ? :(

Re: Schematron: spacing before <ph> element

Posted: Tue Feb 04, 2025 10:42 am
by LASSE_MLE
I'm going to watch the Developing Schematrin Rules onyour YouTube channel, there is clearly something I've not understand...

Re: Schematron: spacing before <ph> element

Posted: Tue Feb 04, 2025 11:22 am
by Radu
Hi,
The Schematron schema is applied over the XML structure which does not have keyrefs or conrefs expanded.
I would probably try an xpath expression like this:

Code: Select all

(preceding-sibling::node()[1])[ends-with(., ' ')]
So I select the closest left sibling (no matter if it's text or element) and I check its text content. The text content of the empty abbreviated-form is empty so the error should be given for two or more consecutive abbreviated-forms.
Regards,
Radu

Re: Schematron: spacing before <ph> element

Posted: Tue Feb 04, 2025 11:39 am
by LASSE_MLE
Thank you so much, it works!
We've definitely made the good choice migrating to OxygenXML two years ago :D