【发布时间】:2015-11-23 10:38:49
【问题描述】:
我想从 XHTML 文件中选择所有文本,除了所有需要完全打印的超链接元素:
XHTML
<?xml version="1.0" encoding="UTF-8" ?>
<html>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<a href="www.link.com">This is a link.</a>
</body>
</html>
期望的输出:
This is a paragraph. This is another paragraph. <a href="www.link.com">This is a link.</a>
我正在使用以下 XSLT,但没有得到任何结果:
XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="@*|node()">
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
<xsl:template match="ancestor-or-self::text()">
<xsl:value-of select="text()"/>
</xsl:template>
<xsl:template match="a">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
对此的任何帮助将不胜感激。
【问题讨论】: