3

I have created a schematron rule that searches for a particular text given by a variable in a case-insensitive manner (provided by "i" flag):

<sch:report test="matches(.,concat('(^|\W)',$phrase,'(\W|$)'),'i')" role="error" 
sqf:fix="replaceWithKey">...</sch:report>

where $phrase = '(phrase)'

I want a user to be able to use a quick fix and replace the text, but I don't know how to provide a case-insensitive solution in the quick fix. My initial version looks like this:

<sqf:fix id="replaceWithKey">
<sqf:stringReplace regex="{$phrase}">
...
</sqf:stringReplace>

the quick fix works only if the part of the text has exactly the same capitalization as $phrase, though the rule violation is recognized in every case. Is there a way to utilize the "i" flag functionality in the regex attribute?

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
proxx
  • 61
  • 3
  • Can you clarify "works"? What's the difference in the result when the quick fix works, vs. when it doesn't? – LarsH Jul 08 '16 at 15:05
  • 1
    If, for example, $phrase = '(phrase)', schematron will highlight several text cases like "phrase", "Phrase" or "PhRAse". The quick fix option will be offered for each of these cases, but the stringReplace function will replace only "phrase". For "Phrase" and "PhRAse" no action will be taken. Quick fix will work properly if the $phrase contained regular expression like [Pp][Hh][Rr][Aa][Ss][Ee], but this is not a flexible solution for all cases I have. If the 'i' modifier cannot be included in the regex attribute, then probably there is no good solution for that. – proxx Jul 08 '16 at 19:31

2 Answers2

0

I've not used SQF, but I think the answer to your final question is "no." According to the reference docs, <sqf:stringReplace> does not allow a flags attribute, as <xsl:analyze-string> does in XSLT.

And the regex syntax does not provide a way to pass those flags within the regex itself.

Probably the easiest way forward would be to modify SQF to add a flags attribute to <sqf:stringReplace>, or ask the SQF author to make that change.

LarsH
  • 27,481
  • 8
  • 94
  • 152
0

Two updates on this topic:

  1. The support for flags in the sqf:stringReplace shall be added to SQF in the future
  2. The workaround is to use sqf:replace function combined with xsl:analyze-string, like below:

    <sqf:replace>
      <xsl:analyze-string select="." regex="{$phrase}" flags="i">
        <xsl:matching-substring>...</xsl:matching-substring>
        <xsl:non-matching-substring>
          <xsl:value-of select="."/>
        </xsl:non-matching substring>
      </xsl:analyze-string>
    </sqf:replace>
    
proxx
  • 61
  • 3