如何删除“pub-id”中的“斜体”元素,“pub-id”中不允许出现“斜体”元素

问题描述 投票:0回答:1

如果标签是

section
的前同级元素和
section
元素的后同级元素,我们将尝试移动
section
元素下的任何标签。

请看下面的例子并提出建议! 感谢您的提前!

输入:

<section><para>text here</para></section>
    <!-- Move below para in the preceding section -->
    <para><g>other txt</g></para>
    <parablock><g>txt</g></parablock>
    <list>list here</list>
    <section><para>another section para</para></section>

预期输出:

<section>
    <para>text here</para>
    <para><g>other txt</g></para>
    <parablock><g>text</g></parablock>
    <list>list here</list>
</section>
<section>
    <para>another section para</para>
</section>
xslt-2.0
1个回答
0
投票

您可以使用 xsl:for-each-group 和 group-starting-with...

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="/*">
        <xsl:copy>
            <xsl:for-each-group select="*" group-starting-with="section">
                <section>
                    <xsl:apply-templates select="current-group()"/>
                </section>
            </xsl:for-each-group>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="section">
        <xsl:apply-templates/>
    </xsl:template>
    
</xsl:stylesheet>

小提琴:http://xsltfiddle.liberty-development.net/6qVQdov

© www.soinside.com 2019 - 2024. All rights reserved.