Reputation: 72
I would like to select all text from an XHTML file except all hyperlink elements which are needed to be printed fully:
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>
Desired output:
This is a paragraph. This is another paragraph. <a href="www.link.com">This is a link.</a>
I am using the following XSLT, but getting no results:
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>
Any help on this will be very appreciated.
Upvotes: 0
Views: 2057
Reputation: 116982
Try it this way:
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>
Note the output method. See also: http://www.w3.org/TR/xslt/#built-in-rule
Upvotes: 1