使用 XSLT,如何从 HTML 中删除所有文本节点,但保留元素标签、属性名称和属性值?
<table id="preserve-this-value">
<caption>Lose this text node</caption>
转型:
<table id="preserve-this-value">
<caption></caption>
谢谢:)
最佳答案
使用此模板:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
它复制除文本节点之外的所有节点(元素、属性)。
关于html - 如何删除文本但保留 HTML 元素、属性和属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13371988/