Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html XSLT-删除一些标记,但按顺序保留内容_Html_Xslt - Fatal编程技术网

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>