One pure XSLT solution of this problem
Input XML
-----------------------------------------------------------------------------
<root>
<para role="h1">one</para>
<para>one_1</para>
<para>one_2</para>
.............................
<para role="h1">two</para>
<para>two_1</para>
<para>two_2</para>
........................
</root>
XSLT
-----------------------------------------------------------------------------
<?xml version="1.0"?>
<t:transform version="1.0" xmlns:t="http://www.w3.org/1999/XSL/Transform">
<t:template match="/root">
<root><t:apply-templates select="(para[(_at_)role])[1]" mode="r"/></root>
</t:template>
<t:template match="para[(_at_)role]" mode="r">
<para><t:copy-of select="@role"/>
<text><t:value-of select="."/></text>
<t:apply-templates select="(following-sibling::node())[1]" mode="c"/>
</para>
<t:apply-templates select="(following-sibling::para[(_at_)role])[1]"
mode="r"/>
</t:template>
<t:template match="node()" mode="c">
<t:copy-of select="."/>
<t:apply-templates select="(following-sibling::node())[1]" mode="c"/>
</t:template>
<t:template match="para[(_at_)role]" mode="c" priority="1"/>
</t:transform>
Output
------------------------------------------------------------------------------
<root>
- <para role="h1">
<text>one</text>
<para>one_1</para>
<para>one_2</para>
....................
</para>
- <para role="h1">
<text>two</text>
<para>two_1</para>
<para>two_2</para>
.................
</para>
</root>
------------------------------------------------------------------------------
SL> Does anyone have thoughts on the suitability of xslt/techniques for
SL> transforming non-nested structures to nested ones? e.g.
SL> Given input such as:
SL> <para role="h1">Text</para>
SL> <para/>
SL> <para/>
SL> {deleted stuff...}
SL> <para role="h1">
SL> ....
SL> produce output such as:
SL> <para role="h1"><para>Text</para>
SL> <para/>
SL> <para/>
SL> {deleted stuff...}
SL> </para>
SL> ...where the appearance of the second <para role="h1"> effectively marks
SL> the closure of the preceeding one.
--
Best regards,
Ivan Churkin mailto:_qq_(_at_)nsk(_dot_)ru
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list