使用quickfix将文本'abc‘替换为'-abc’后,我仍然可以选择将文本'abc‘替换为'-abc’。
XML输入:
<data>
<text>10abc and 20-abc</text>
<text>30abc test 40abc and 15-abc </text>
</data>schematron代码:
<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> </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>为什么即使在替换完成之后,我仍然可以选择将'abc‘替换为'-abc’?有人能告诉我代码出了什么问题吗?提前感谢
发布于 2019-10-07 15:12:23
你可以试试这个
<?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>https://stackoverflow.com/questions/58261223
复制相似问题