Html XSLT-删除一些标记,但按顺序保留内容
我有一个标记,我想从中删除/转换某些标记,但保留数据 例如:Html XSLT-删除一些标记,但按顺序保留内容,html,xslt,Html,Xslt,我有一个标记,我想从中删除/转换某些标记,但保留数据 例如: <div>This is some <b>bold</b> text inside of a div</div> <p>This is <u>another <b>formatted</b></u> string...<br /></p> 这是div中的一些粗体文本 这是另一个格式化字符串… 应该是这
<div>This is some <b>bold</b> text inside of a div</div>
<p>This is <u>another <b>formatted</b></u> string...<br /></p>
这是div中的一些粗体文本
这是另一个格式化字符串…
应该是这样的:
<p>This is some <b>bold</b> text inside of a div</p>
<p>This is another <b>formatted</b> string...</p>
这是div中的一些粗体文本
这是另一个格式化字符串
使用apply templates
匹配每个条件由于嵌套而无效
你会怎么做呢?听起来像是一个修改过的工作,如下所示:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<!--This is the identity template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!--This template turns all <div> into <p>-->
<xsl:template match="div">
<p>
<xsl:apply-templates select="@*|node()"/>
</p>
</xsl:template>
<!--This template removes all <u> and continues processing -->
<xsl:template match="u">
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
</xsl:stylesheet>
听起来像是修改后的作业,如下所示:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<!--This is the identity template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!--This template turns all <div> into <p>-->
<xsl:template match="div">
<p>
<xsl:apply-templates select="@*|node()"/>
</p>
</xsl:template>
<!--This template removes all <u> and continues processing -->
<xsl:template match="u">
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
</xsl:stylesheet>