如果 p 子元素出现在子元素之前关闭并在子元素之后使用 xslt 打开
If p sub element appears close before the sub element and open after the sub element using xslt
我有一个输入 xml 作为:
<root>
<p>text 1</p>
<p>text <i>2</i>
<disp-quote>
<p>text <b>3</b></p>
</disp-quote>
text <b>4</b>
<disp-quote>
<p>text 5</p>
</disp-quote>
text 6</p>
</root>
需要输出作为每个子元素关闭出现的关闭 p
输出为:
<root>
<p>text 1</p>
<p>text <i>2</i></p>
<blockquote>
<p>text <b>3</b></p>
</blockquote>
<p>text <i>4</i></p>
<blockquote>
<p>text 5</p>
</blockquote>
<p>text 6</p>
</root>
提前致谢
像这样:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="/root/p" >
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/root/p/i|root/p/b"/>
<xsl:template match="/root/p/text()[normalize-space()!='']">
<p>
<xsl:copy-of select="preceding-sibling::node()[1][self::i|self::b]"/>
<xsl:copy-of select="."/>
<xsl:copy-of select="following-sibling::node()[1][self::i|self::b]"/>
</p>
</xsl:template>
</xsl:stylesheet>
我有一个输入 xml 作为:
<root>
<p>text 1</p>
<p>text <i>2</i>
<disp-quote>
<p>text <b>3</b></p>
</disp-quote>
text <b>4</b>
<disp-quote>
<p>text 5</p>
</disp-quote>
text 6</p>
</root>
需要输出作为每个子元素关闭出现的关闭 p 输出为:
<root>
<p>text 1</p>
<p>text <i>2</i></p>
<blockquote>
<p>text <b>3</b></p>
</blockquote>
<p>text <i>4</i></p>
<blockquote>
<p>text 5</p>
</blockquote>
<p>text 6</p>
</root>
提前致谢
像这样:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="/root/p" >
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/root/p/i|root/p/b"/>
<xsl:template match="/root/p/text()[normalize-space()!='']">
<p>
<xsl:copy-of select="preceding-sibling::node()[1][self::i|self::b]"/>
<xsl:copy-of select="."/>
<xsl:copy-of select="following-sibling::node()[1][self::i|self::b]"/>
</p>
</xsl:template>
</xsl:stylesheet>