Shil
Shil

Reputation: 221

Schematron quick fix issue

after replacing text 'abc' with '-abc' using quickfix I still do get an option to replace text 'abc' with '-abc'.
XML Input:

  <data>
     <text>10abc and 20-abc</text>
     <text>30abc test 40abc and 15-abc </text>
  </data>

schematron code:

<sch:pattern>
        <sch:rule context="//text()">
<sch:report
                test="contains(.,'abc ')"sqf:fix="group-fix">abc not allowed without hypen</sch:report>
<sqf:group id="group-fix">
 <sqf:fix id="abc-fix" use-when="contains(current(),'abc')">
                    <sqf:description>
                        <sqf:title>replace</sqf:title>
                    </sqf:description>
                    <sqf:replace>
                        <xsl:analyze-string select="." regex="(\d+)abc\s">
                            <xsl:matching-substring><xsl:value-of select="regex-group(1)"/><xsl:value-of select="'-abc'"/><xsl:text>&#xA0;</xsl:text></xsl:matching-substring>
                            <xsl:non-matching-substring><xsl:value-of select="."/></xsl:non-matching-substring>
                        </xsl:analyze-string>
                    </sqf:replace>
                </sqf:fix>
    </sqf:group>
        </sch:rule>
    </sch:pattern>

why do I get the option to replace 'abc' with '-abc' again even after the replace is done? Can anyone tell me what is wrong with the code? Thanks in advance

Upvotes: 1

Views: 130

Answers (1)

Sam
Sam

Reputation: 841

You can try this

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:output method="xml" omit-xml-declaration="no"/>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="//text()">
        <xsl:value-of select="replace(., '((\d+)(abc))', '$2-$3')"/>
    </xsl:template>
</xsl:stylesheet>

DEMO https://xsltfiddle.liberty-development.net/94AbWAS/1

Upvotes: 0

Related Questions