Schematron assertions for specific words/phrases and quickfix help
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 18
- Joined: Thu Mar 16, 2017 8:44 pm
Schematron assertions for specific words/phrases and quickfix help
We have several common words or phrases we general wrap with <i> when they appear in text. I am trying to write a schematron rule to enforce this rule and suggest a quick fix to wrap the word or phrase in <i>. The following code works, but the warning underline underlines the beginning of the entire element surrounding the appearance of "Assay", and it necessitates writing an assertion for literally every word separately. Is there a way to generate the warning under "Assay" itself in a text() node?
More importantly, I would love any suggestions for a schematron quickfix that would wrap the offending word in an <i> and preserve the rest of the content in the tag.
More importantly, I would love any suggestions for a schematron quickfix that would wrap the offending word in an <i> and preserve the rest of the content in the tag.
Code: Select all
<pattern>
<title>Italic suggestion</title>
<rule context="*[not(ancestor-or-self::title) and not(ancestor-or-self::i)]/text()" role="warn">
<assert test="not(matches(., 'Assay'))">Assay is generally italicized when referenced in text</assert>
</rule>
</pattern>
-
- Posts: 388
- Joined: Thu Jul 01, 2004 12:29 pm
Re: Schematron assertions for specific words/phrases and quickfix help
Hello,
If you want to wrap an word in an element I recommend you to use the sqf:stringReplace operation. You can match the word that you want to wrap and replace it with a fragment. The quick fix should look something like this:
Best Regards,
Octavian
If you want to wrap an word in an element I recommend you to use the sqf:stringReplace operation. You can match the word that you want to wrap and replace it with a fragment. The quick fix should look something like this:
Code: Select all
<sch:rule context="*[not(ancestor-or-self::title) and not(ancestor-or-self::i)]/text()" role="warn">
<sch:assert test="not(matches(., 'Assay'))" sqf:fix="wrapWord">Assay is generally italicized when referenced in text</sch:assert>
<sqf:fix id="wrapWord">
<sqf:description>
<sqf:title>Wrap 'Assay' word in italic</sqf:title>
</sqf:description>
<sqf:stringReplace regex="Assay">
<i>Assay</i>
</sqf:stringReplace>
</sqf:fix>
</sch:rule>
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 18
- Joined: Thu Mar 16, 2017 8:44 pm
Re: Schematron assertions for specific words/phrases and quickfix help
Thanks, I figured out that stringReplace could insert elements yesterday, so we reached the same conclusion!
To my other question, is there any way to make a template for this, and supply a list of words rather than creating separate assertions for numerous words individually?
To my other question, is there any way to make a template for this, and supply a list of words rather than creating separate assertions for numerous words individually?
-
- Posts: 388
- Joined: Thu Jul 01, 2004 12:29 pm
Re: Schematron assertions for specific words/phrases and quickfix help
Hello,
You can create an abstract pattern and then for each word you need to instantiate the pattern and pass the word as parameter. Something like this:
Best Regards,
Octavian
You can create an abstract pattern and then for each word you need to instantiate the pattern and pass the word as parameter. Something like this:
Code: Select all
<sch:pattern id="warap" abstract="true">
<sch:title>Italic suggestion</sch:title>
<sch:rule context="*[not(ancestor-or-self::title) and not(ancestor-or-self::i)]/text()" role="warn">
<sch:assert test="not(matches(., '$word'))" sqf:fix="wrapWord">$word is generally italicized when referenced in text</sch:assert>
<sqf:fix id="wrapWord">
<sqf:description>
<sqf:title>Wrap '$word' word in italic</sqf:title>
</sqf:description>
<sqf:stringReplace regex="$word">
<i>$word</i>
</sqf:stringReplace>
</sqf:fix>
</sch:rule>
</sch:pattern>
<sch:pattern is-a="warap">
<sch:param name="word" value="Assay"/>
</sch:pattern>
<sch:pattern is-a="warap">
<sch:param name="word" value="OtherWord"/>
</sch:pattern>
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “General XML Questions”
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