Using Two "group-adjacent"
Input XML:
---------
<artbody>
<section id="s1">
<heading1 level="1">INTRODUCTION</heading1>
<para>xxx <b>xxx</b> xxxxxxxxxxxxxxxxxxx</para>
<subsect id="s1-1">
<heading2 level="2">Linkends</heading2>
<para>This paragraph contains fixed figure <fx1>, <fx2>, <fx3>.</para>
<para>This paragraph contains linkend type for Bibliography (numbered) (type=bib): [<link type="bib" linkend="">3</link>], [<link type="bib" linkend="">4, 7</link>], [<link type="bib" linkend="">7â12</link>], [<link type="bib" linkend="">14-18</link>], [<link type="bib" linkend="">3, 5, 7â12</link>] and [<link type="bib" linkend="">6, 8, 15-17</link>].</para></subsect1>
<subsect1 id="s1-5-1">
<heading3 level="3">Question and Answer</heading3>
<quest>What's you name?</quest>
<answer>Pradeep</answer>
<quest>How old are you?</quest>
<answer>62</answer>
<quest>So, what are you doing now?</quest>
<answer>Just chatting with an idiot</answer> </subsect>
</subsect>
<subsect1 id="s1-5-1">
<heading3 level="3">poem</heading3>
<stanza>What's you name?</stanza>
<stanza>Pradeep</stanza>
</subsect>
<para>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</para>
<para>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</para>
</section>
</artbody>
expected output xml:
--------------------
<artbody>
<section id="s1">
<heading1 level="1">INTRODUCTION</heading1>
<para>xxx <b>xxx</b> xxxxxxxxxxxxxxxxxxx</para>
<subsect id="s1-1">
<heading2 level="2">Linkends</heading2>
<para>This paragraph contains fixed figure <fx1>, <fx2>,
<fx3>.</para>
<para>This paragraph contains linkend type for Bibliography (numbered)
(type=bib): [<link type="bib" linkend="">3</link>], [<link type="bib"
linkend="">4, 7</link>], [<link type="bib" linkend="">7â12</link>],
[<link type="bib" linkend="">14-18</link>], [<link type="bib"
linkend="">3, 5, 7â12</link>] and [<link type="bib" linkend="">6, 8, 15-
17</link>].</para></subsect1>
<subsect1 id="s1-5-1">
<heading3 level="3">Question and Answer</heading3>
<qanda>
<quest>What's you name?</quest>
<answer>Pradeep</answer>
<quest>How old are you?</quest>
<answer>62</answer>
<quest>So, what are you doing now?</quest>
<answer>Just chatting with an idiot</answer>
</qanda>
</subsect>
</subsect>
<subsect1 id="s1-5-1">
<heading3 level="3">poem</heading3>
<poem>
<stanza>What's you name?</stanza>
<stanza>Pradeep</stanza>
</poem>
</subsect>
<para>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</para>
<para>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</para>
</section>
</artbody>
Style Sheet:
-----------
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns:o="urn:schemas-microsoft-com:office:office"
exclude-result-prefixes="aml w wx o v">
<xsl:output method="xml"
indent="yes"
omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:choose>
<xsl:when test="artbody">
<xsl:copy>
<xsl:for-each-group select="child::node()" group-adjacent="self::quest or self::answer">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<quanta>
<xsl:apply-templates select="current-group()"/>
</quanta>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Questions:
---------
1. I would like to group 'quest' & 'answer' under 'qanda'
2. I would like to group 'stanza' under 'poem'
I want to read each element dynamically and should group the orphan nodes such as quest & stanza under another parent element. But, with your suggestion, I could group one at a time. I couldn't do it in a loop. When I tried, I am getting duplicate of orphan nodes and all the attribute values are discarded.
If you could help us to design a xslt that groups "quest & answer" and "stanza" dynamically and retains all other elements untouched.
I sincerely appreciate your help in this regard.
Thanks & Regards,
- ROCXY
__________________
Thanks,
Rocxy.
|