我正在使用 XSLT 3.0 将 XML 文件输出到 HTML,但在消除逗号和句点之前的空格时遇到了麻烦。下面是我遇到的确切问题的一个示例:XML 中有行/回车,这些回车正在 HTML 中重现。通常这不是问题,因为浏览器会将空白折叠为一个空白;但是,正如您在下面的示例中看到的那样,它在逗号和句点之前保留了一个空格。
(关于 XML 的注意事项:这是中世纪手稿的文本编码,因此其中可以包含各种元素,并且它可以嵌套在不同级别的其他元素中)。
XML:
<persName>
<choice>
<orig>ar. p<hi rend="sup">a</hi>der</orig>
<reg>Arnaldum Prader</reg>
</choice>
</persName> et socium eius hereticos et vidit ibi cum eis <persName>
<choice>
<orig>P. barrau</orig>
<reg>Poncium Barrau</reg>
</choice>
</persName>, <persName>
<choice>
<orig>Iordanetū del maſ</orig>
<reg>Iordanetum del Mas</reg>
</choice>
</persName>, <persName>
<choice>
<orig>Iordanū de quiders</orig>
<reg>Iordanum de Quiders</reg>
</choice>
</persName> et <persName>
<choice>
<orig>W. Vitał</orig>
<reg>Willelmum Vitalis</reg>
</choice>
</persName> predictum et <persName>
<choice>
<orig>ux̄ dc̄ī W. Vitał</orig>
<reg>uxor dicti Willelmi Vitalis</reg>
</choice>
</persName>.
XML 模板:
<!-- format super/sub scripts -->
<xsl:template match="tei:hi" name="template_supersub">
<xsl:choose>
<xsl:when test="@rend ='sup'"><sup class="subsup"><xsl:apply-templates/></sup></xsl:when>
<xsl:when test="@rend ='sub'"><sub class="subsup"><xsl:apply-templates/></sub></xsl:when>
</xsl:choose>
</xsl:template>
<!-- parse persName into <spans> -->
<xsl:template match="tei:persName/tei:choice/tei:reg">
<span class="interpretive"><xsl:apply-templates/></span>
</xsl:template>
<xsl:template match="tei:persName/tei:choice/tei:orig">
<span class="diplomatic"><xsl:apply-templates/></span>
</xsl:template>
当前的 HTML 输出:
<span class="diplomatic">ar. p<sup class="subsup">a</sup>der</span>
<span class="interpretive">Arnaldum Prader</span>
et socium eius hereticos et vidit ibi cum eis
<span class="diplomatic">P. barrau</span>
<span class="interpretive">Poncium Barrau</span>
,
<span class="diplomatic">Iordanetū del maſ</span>
<span class="interpretive">Iordanetum del Mas</span>
,
<span class="diplomatic">Iordanū de quiders</span>
<span class="interpretive">Iordanum de Quiders</span>
et
<span class="diplomatic">W. Vitał</span>
<span class="interpretive">Willelmum Vitalis</span>
predictum et
<span class="diplomatic">ux̄ dc̄ī W. Vitał</span>
<span class="interpretive">uxor dicti Willelmi Vitalis</span>
.
最终,有问题的输出:
Arnaldum Prader et socium eius heticos et vidit ibi cum eis Poncium Barrau, Iordanetum del Mas, Iordanum de Quiders et Willelmum Vitalis predictum et uxor dicti Willelmi Vitalis。
strip-space、replace()、translate() 的各种组合都没有针对这个问题。它们通常会导致元素之间的每个空白空间都崩溃。
理想情况下,我希望逗号和句点前没有空格,逗号或句点后有一个空格。但我找不到解决这个问题的机制,更不用说破解了。谢谢。
所需的 HTML 输出:
<span class="diplomatic">ar. p<sup class="subsup">a</sup>der</span>
<span class="interpretive">Arnaldum Prader</span> et socium eius
hereticos et vidit ibi cum eis <span class="diplomatic">P.
barrau</span><span class="interpretive">Poncium Barrau</span>, <span
class="diplomatic">Iordanetū del maſ</span><span
class="interpretive">Iordanetum del Mas</span>, <span
class="diplomatic">Iordanū de quiders</span><span
class="interpretive">Iordanum de Quiders</span> et <span
class="diplomatic">W. Vitał</span><span class="interpretive">Willelmum
Vitalis</span> predictum et <span class="diplomatic">ux̄ dc̄ī W.
Vitał</span><span class="interpretive">uxor dicti Willelmi
Vitalis</span>.