【发布时间】:2017-01-31 15:03:52
【问题描述】:
我有一个 XSLT 级联将 XML 传输到 TeX。在最后一步中,我有一个简单的 xml 文件,其中包含两个标签之间的所有文本,我想应用几个搜索和替换例程。
所以输入文件是这样的:
<start>
.–
,–
{–
</start>
与此 XSLT 一起应用时(或多或少逐字逐句取自 Replacing strings in various XML files)
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="list">
<words>
<word>
<search> / </search>
<replace>\allowbreak\,\slash\,\allowbreak{}</replace>
</word>
<word>
<search>.–</search>
<replace>{\dotdash}</replace>
</word>
<word>
<search>,–</search>
<replace>{\commadash}</replace>
</word>
<word>
<search>;–</search>
<replace>{\semicolondash}</replace>
</word>
<word>
<search>!–</search>
<replace>{\excdash}</replace>
</word>
</words>
</xsl:param>
<xsl:template match="@*|*|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()">
<xsl:variable name="search" select="concat('(',string-join($list/words/word/search,'|'),')')"/>
<xsl:analyze-string select="." regex="{$search}">
<xsl:matching-substring>
<xsl:value-of select="$list/words/word[search=current()]/replace"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
应该有以下输出:
\dotdash{}
\逗号{}
{–
不幸的是,“{–”似乎触发了什么并消失了。谁能解释一下为什么?
【问题讨论】:
标签: xslt replace punctuation