I want to grouping <block> element in inside the <p class="p"> element. If <p class="p"> following-sibling[1] is <block> element and <p class="p1"> value inside in <p class="p"> element.
Input XML File-:
<root>
<p class="p">aaaaaa</p>
<block>
<p>block</p>
</block>
<p class="p1"> bbb </p>
<block>
<p>block</p>
</block>
<p class="p1">bbb.</p>
<p class="p">cccc</p>
</root>
I want to expected output below.
Output XML file:
<root>
<p class="p">aaaaaa<block><p>block</p></block> bbb <block><p>block</p></block>bbb.</p>
<p class="p">cccc</p>
</root>
Can we right the logic another way to above the output, I am using XSLT below above the output:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="p[@class='p']">
<xsl:choose>
<xsl:when test="following-sibling::*[1][self::block]">
<xsl:text disable-output-escaping="yes"><p></xsl:text>
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<p><xsl:apply-templates select="@*|node()"/></p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="p[@class='p1']">
<xsl:choose>
<xsl:when test="following-sibling::*[1][self::p[@class='p']]">
<xsl:apply-templates/>
<xsl:text disable-output-escaping="yes"></p></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The following seems to wrap/group the right nodes for the input sample but I am not sure it implements your requirements, I haven't quite understood them.