Html 删除节点副本中的某些节点
如何复制整个元素,但只删除部分子元素? 我想复制Html 删除节点副本中的某些节点,html,xml,xslt,Html,Xml,Xslt,如何复制整个元素,但只删除部分子元素? 我想复制div#about,但我想从中删除表元素 输入HTML: <html> <body> <div class="content-header"> <h1>Title</h1> </div> <div id="about"> <h1>About</h1> <table>.
div#about
,但我想从中删除表
元素
输入HTML:
<html>
<body>
<div class="content-header">
<h1>Title</h1>
</div>
<div id="about">
<h1>About</h1>
<table>...</table>
<p>Bla bla bla</p>
<table>...</table>
<p>The end</p>
</div>
</body>
</html>
标题
关于
...
呜呜呜呜
...
结局
XSLT:
首先将标识模板添加到XSLT中
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
最后,用xsl:apply templates
替换xsl:copy的
试试这个XSLT
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="div[@id='about']/table" />
<xsl:template match="/">
<div class="article">
<h1>
<xsl:value-of select="//div[@class='content-header']/h1/text()"/>
</h1>
<div>
<xsl:apply-templates select="//div[@id='about']"/>
</div>
</div>
</xsl:template>
</xsl:transform>
首先将标识模板添加到XSLT中
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
最后,用xsl:apply templates
替换xsl:copy的
试试这个XSLT
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="div[@id='about']/table" />
<xsl:template match="/">
<div class="article">
<h1>
<xsl:value-of select="//div[@class='content-header']/h1/text()"/>
</h1>
<div>
<xsl:apply-templates select="//div[@id='about']"/>
</div>
</div>
</xsl:template>
</xsl:transform>