[Home] [By Thread] [By Date] [Recent Entries]
Here's a quick and dirty method to convert your flat sample to nested hierarchy. I didn't copy all the supposed markup here, just created the hierarchy. My source file was: <?xml version='1.0' encoding='utf-8'?>
<text>
<flat lvl="1"> {markupA} </flat>
<flat lvl="2"> {markupB} </flat>
<flat lvl="2"> {markupC} </flat>
<flat lvl="1"> {markupD} </flat>
<flat lvl="2"> {markupE} </flat>
<flat lvl="2"> {markupF} </flat>
<flat lvl="3"> {markupG} </flat>
<flat lvl="4"> {markupH} </flat>
<flat lvl="4"> {markupI} </flat>
<flat lvl="3"> {markupJ} </flat>
<flat lvl="3"> {markupK} </flat>
<flat lvl="2"> {markupL} </flat>
<flat lvl="1"> {markupM} </flat>
</text>The XSLT is: <?xml version='1.0' encoding='utf-8'?> <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/ Transform'> <xsl:output method='xml' version='1.0' encoding='utf-8' indent='yes'/> <xsl:template match="/">
<xsl:call-template name="nest">
<xsl:with-param name="flat" select="text/flat[1]" />
</xsl:call-template>
</xsl:template><xsl:template name="nest">
<xsl:param name="flat" />
<xsl:element name="nest">
<xsl:value-of select="$flat" />
<xsl:if test="$flat/following::flat[1]/@lvl > $flat/@lvl">
<xsl:call-template name="nest">
<xsl:with-param name="flat" select="$flat/following::flat
[1]" />
</xsl:call-template>
</xsl:if>
</xsl:element>
<xsl:variable name="next" select="$flat/following::flat[@lvl <=
$flat/@lvl]" />
<xsl:if test="$next[1]/@lvl = $flat/@lvl">
<xsl:call-template name="nest">
<xsl:with-param name="flat" select="$next[1]" />
</xsl:call-template>
</xsl:if>
</xsl:template></xsl:stylesheet> Kind regards, -- Mikhail Edoshin m.edoshin@xxxxxxx On Oct 14, 2006, at 8:28 PM, Watch-O-Matic wrote: Michael Kay wrote:
|

Cart



