Schematron: spacing before <ph> element
Post here questions and problems related to editing and publishing DITA content.
-
- Posts: 42
- 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
It helps me to find spaces around <ph> tags.
However it doesn't work when the Indent inline elements is ticked in the preferences.
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 <ph></sch:assert>
<sqf:fix id="add-space-before-ph">
<sqf:description>
<sqf:title>Add space before <ph></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.You do not have the required permissions to view the files attached to this post.
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Schematron: spacing before <ph> element
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
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
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 42
- 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
Pieterjan
-
- Posts: 38
- Joined: Mon Dec 05, 2022 3:24 pm
Re: Schematron: spacing before <ph> element
<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
The following dita code:
will raise warnings for the <uicontrol> and <ph> but not for the <abbreviated-form>? Strange no ?
Thank you for your help!
BR
Mathieu
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 <></sch:assert>
<sqf:fix id="add-space-before">
<sqf:description>
<sqf:title>Add space before <></sqf:title>
</sqf:description>
<sqf:add position="before" match="." select="' '"/>
</sqf:fix>
</sch:rule>
</sch:pattern>
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>
Thank you for your help!
BR
Mathieu
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Schematron: spacing before <ph> element
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:.
Regards,
Radu
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:
So in the case of "abbreviated-form" it locates the indentation text before the <li> elementpreceding::
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.
Code: Select all
<li>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 38
- Joined: Mon Dec 05, 2022 3:24 pm
Re: Schematron: spacing before <ph> element
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
is not correct.
I'm not sure to see have clearly understood your advice...
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"/>
I'm not sure to see have clearly understood your advice...
-
- Posts: 38
- Joined: Mon Dec 05, 2022 3:24 pm
Re: Schematron: spacing before <ph> element
I've just test something and
is raising the warning I want...
Do I have to rewrite all my glossary entries ?
Code: Select all
<abbreviated-form keyref="A">A</abbreviated-form><abbreviated-form keyref="B"/>
Do I have to rewrite all my glossary entries ?

-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Schematron: spacing before <ph> element
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:
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
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(., ' ')]
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “DITA (Editing and Publishing DITA Content)”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service