我写了一个快捷键,在数字和字符串之间插入一个空格,例如:15 20Hz,20 to。
Schematron
<sch:pattern>
<sch:title>quick-fix</sch:title>
<sch:rule context="//text()">
<sch:report
test="matches(.,'(\d+)MHz') or matches(.,'(\d+)Hz')"
sqf:fix="groupfix" role="warning">Insert a space</sch:report>
<sqf:group id="groupfix">
<sqf:fix id="MHz-fix" use-when="contains(current(), 'MHz')">
<sqf:description>
<sqf:title>Insert space before MHz
</sqf:title>
</sqf:description>
<sqf:replace>
<xsl:analyze-string select="." regex="(\d+)MHz">
<xsl:matching-substring><xsl:value-of select="regex-group(1)"
/><xsl:value-of select="' MHz'"
/></xsl:matching-substring>
<xsl:non-matching-substring><xsl:value-of select="."
/></xsl:non-matching-substring>
</xsl:analyze-string>
</sqf:replace>
</sqf:fix>
<sqf:fix id="Hz-fix" use-when="contains(current(), 'Hz')">
<sqf:description>
<sqf:title>Insert space before Hz
</sqf:title>
</sqf:description>
<sqf:replace>
<xsl:analyze-string select="." regex="(\d+)Hz">
<xsl:matching-substring><xsl:value-of select="regex-group(1)"
/><xsl:value-of select="' Hz'"
/></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>xml
<topic>
<p>15MHz</p>
</topic>我能够在MHz之前插入空间,但是快速修复显示两个选项“MHz之前插入空间”和“Hz之前插入空间”。我只想要显示“在MHz之前插入空间”。
请帮帮忙。谢谢
发布于 2022-01-25 15:18:03
取而代之的是:
<sqf:fix id="Hz-fix" use-when="contains(current(), 'Hz')">这样做:
<sqf:fix id="Hz-fix" use-when="matches(current(), '(\d+)Hz')">在pattern.
<xsl:analyze-string>.
matches函数,您可以用.代替current()来保存代码。H 113在氧气中您可以使用<sqf:stringReplace regex="(\d+)Hz" select="'$1 Hz'"/>代替复杂的
https://stackoverflow.com/questions/70849587
复制相似问题