Page 1 of 1

Schematron to find plural keywords

Posted: Wed Dec 14, 2016 4:20 am
by shudson310
I've found a few instances where an author has used something like

Code: Select all

<keyword keyref="display"/>s
.

I know this will create issues with the content is translated, or potentially if the value of the key changes.

Any suggestions on how to detect this construction? I've tried variations on substring-after, but can't get it exactly right.

Thanks!

Re: Schematron to find plural keywords

Posted: Wed Dec 14, 2016 4:21 am
by shudson310
shudson310 wrote:I've found a few instances where an author is trying to create a plural version of an existing term, using something like:

Code: Select all

<keyword keyref="display"/>s
.

I know this will create issues with the content is translated, or potentially if the value of the key changes.

Any suggestions on how to detect this construction? I've tried variations on substring-after, but can't get it exactly right.

Thanks!

Re: Schematron to find plural keywords

Posted: Wed Dec 14, 2016 11:36 am
by xephon
I'd search for a single 's'. Is this only related to plural 's'?

Re: Schematron to find plural keywords

Posted: Wed Dec 14, 2016 1:49 pm
by tavy
Hello,

You can create a Schematron rule that matches the keyword element, and check that the text after the element does not start with the 's' character. The rule will be something like this:

Code: Select all


<sch:rule context="keyword[@keyref]">
<sch:report test="following-sibling::node()[1][self::text()][starts-with(self::text(), 's')]">
The 's' character is not allowed after a keyword
</sch:report>
</sch:rule>
Or, if you want to create a more generic rule that will check if after the keyword element is not a character that might appear in a word (so you can permit "punctuation" or "space"), you can create a rule like this:

Code: Select all


<sch:rule context="keyword[@keyref]">
<sch:report test="following-sibling::node()[1][self::text()][matches(self::text(), '^\w+')]">
Text not allowed after keyword
</sch:report>
</sch:rule>
Best Regards,
Octavian

Re: Schematron to find plural keywords

Posted: Wed Dec 14, 2016 5:04 pm
by shudson310
Thanks, Octavian! The first suggestion is exactly what I needed.