【发布时间】:2016-04-25 22:24:08
【问题描述】:
我已经搜索了论坛,但仍然不清楚这一点。我对这个话题很陌生。
我有正在发送到浏览器电子邮件客户端 (Outlook) 的 HTML 输出。 Outlook 覆盖了<p> 标记的特性并引入了大间距。
我想设置一个模板匹配来用<div> 或<span> 替换所有<p> 标签。
由于本文未解决的复杂原因,我无法阻止 HTML 中带有 <p> 标签的渲染。
所以可以说我有:
<p xmlns="http://www.w3.org/1999/xhtml">
<span>Some text</span>
</p>
我希望输出是
<span>Some text</span>
删除了<p> 标签。
如果我有
<p xmlns="http://www.w3.org/1999/xhtml">
<b>Some other text</b>
</p>
那么我会很高兴:
<b>Some other text</b>
或
<span>
<b>Some other text</b>
</span>
只要它去掉<p>标签。
它还需要识别没有任何属性的<p>。
我想过类似的事情
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="p">
<span>
<xsl:apply-templates select="@*|node()" />
</span>
</xsl:template>
但这不起作用。 <p> 标签仍然出现。
可以编写一个适配器,在 HTML 发送到 smtp 服务器之前拦截它并对其进行操作,但我希望避免这种方法存在相当大的困难。
甚至可以做我正在尝试的事情吗?非常感谢任何帮助。
【问题讨论】:
-
您是否错误地用
xsl-fo标记了这个问题? XSL-FO 不同于 XSLT。 -
生成输入 XML 的系统是基于 xsl-fo 的......但你是对的,这与这个问题无关。移除标签。干杯
标签: xslt xhtml template-matching