我有一个
xml
重复具有相同元素的文档。我需要将相邻的div元素放入另一个元素中。下面我的xml文档包含p和div元素。所有div元素都应该是
在部门内部分组
. 如果是单个或相邻的。
<doc>
<section>
<p class="h1">the fisr A</p>
<p class="txt">one</p>
<p>tow</p>
<div>the sec B</div>
<div>theree</div>
<div>theree</div>
<p class="h2">the sec sec B</p>
<p class="txt">the next text</p>
<p class="h3">the fisr C</p>
<p class="txt">four</p>
<div>five</div>
<div>the seccond A</div>
<p class="txt">the seccond txt</p>
<p class="h2">the second B</p>
</section>
<section>
<p class="txt">six</p>
<div>seven</div>
<p class="txt">eight</p>
<p class="txt">nine</p>
</section>
</doc>
<doc>
<section>
<p class="h1">the fisr A</p>
<p class="txt">one</p>
<p>tow</p>
<division>
<div>the sec B</div>
<div>theree</div>
<div>theree</div>
</division>
<p class="h2">the sec sec B</p>
<p class="txt">the next text</p>
<p class="h3">the fisr C</p>
<p class="txt">four</p>
<division>
<div>five</div>
<div>the seccond A</div>
</division>
<p class="txt">the seccond txt</p>
<p class="h2">the second B</p>
</section>
<section>
<p class="txt">six</p>
<division>
<div>seven</div>
</division>
<p class="txt">eight</p>
<p class="txt">nine</p>
</section>
</doc>
我已经尝试了下面的xslt。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="body">
<xsl:copy>
<xsl:for-each-group select="div" group-adjacent="div">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<division>
<xsl:apply-templates select="current-group()"/>
</division>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
请有人来帮我。