XSLT select 所有文本和特定节点

XSLT select all text and specific node

我想 select 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>

如有任何帮助,我们将不胜感激。

这样试试:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="a">
    <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>

注意输出方式。另见:http://www.w3.org/TR/xslt/#built-in-rule