XSL: select all text in a node except for certain node types
4 answers
Use the built-in template rule for text nodes to copy them into the result. Even for the new processing mode that you specify ("all-but-a" in the code below), the built-in rules will work: for elements (recursively) handle children; for text nodes, copy. You only need to override one of them, the element rule <a>
, hence this is an empty template rule that effectively removes the text.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="myNode">
<!-- Process children -->
<xsl:apply-templates mode="all-but-a"/>
</xsl:template>
<!-- Don't process <a> elements -->
<xsl:template mode="all-but-a" match="a"/>
</xsl:stylesheet>
For a complete description of how built-in template rules work, see the Built-in Rule Templates section of How XSLT Works on my website.
+8
a source to share