html:
<div class="ls-col" id="ls-row-2-col-2">
<div class="ls-col-body" id="ls-gen79493564-ls-col-body">
<div class="ls-row" id="ls-row-2-col-2-row-1">
<div class="ls-fxr" id="ls-gen79493565-ls-fxr">
<div class="ls-area" id="ls-row-2-col-2-row-1-area-1">
<div class="ls-area-body" id="ls-gen79493566-ls-area-body">
<div class="grid-container">
<div class="grid-100">
<div class="intro_content slide_content grid-40">
<div class="current"></div>
<div class="next"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
预期:
<div class="ls-col">
<div class="ls-row">
<div class="ls-area">
<div class="grid-container">
<div class="grid-100">
<div class="intro_content slide_content grid-40">
<div class="current"></div>
<div class="next"></div>
</div>
</div>
</div>
</div>
</div>
</div>
我想删除包含以下类的div
- ls col主体
- ls区域体
- ls行正文
- ls fxr
- 只需移除所有以ls开头的id属性,而不是div just id属性
我试着用这种方式匹配。但不了解如何删除
<xsl:template match="div[contains(@class,'ls-col-body')]">
<xsl:apply-templates select="container"/> <!-- some template -->
</xsl:template>
试试这个XSLT:
第一个模板用于复制节点和属性。第二个是删除具有特定值的div,第三个是省略以ls-开头的id属性
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="div[@class='ls-col-body' or @class='ls-area-body' or @class='ls-row-body']">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="@id[starts-with(.,'ls-')]"/>
</xsl:stylesheet>