[xsl] parameter getting lost in tunnel?

Subject: [xsl] parameter getting lost in tunnel?
From: "Tom Schmitter" <toms@xxxxxxxxxxxxxxxxx>
Date: Sun, 20 Jul 2008 09:42:30 -0700 (PDT)
Hi List,
I've been struggling for more hours than I care to admit on a simple task
- passing a parameter through a series of templates using tunnel="yes".
For some reason my parameter seems to be lost along the way and inevitably
ends up with the default value (0).
In the abbreviated "sect_break" template below, the param "prev_depth"
should start out at 0 then be set to 1 as it's passed through
apply-templates the first time. But the next time sect_break is called,
prev_depth is 0 (or whatever default is specified in the param's select):
<xsl:stylesheet version="2.0"
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
    <xsl:template match="sect_break">
        <!-- prev_depth is the depth that we were at before encountering
this sect_break -->
        <xsl:param name="prev_depth" select="0" tunnel="yes"/>
        <!-- depth is the depth indicated in the current sect_break -->
        <xsl:variable name="depth" select="./@depth" as="xs:integer"/>
        <xsl:variable name="direction" select="$depth - $prev_depth"
            <xsl:when test="$direction &gt; 0">
                <!-- going deeper in depth -->
                sect_break depth=<xsl:value-of select="$depth"/>
                    <xsl:with-param name="prev_depth" select="$depth"
tunnel="yes" />
            <!-- some other cases have been omitted for brevity -->
Sample input:
    <sect_break depth="1"/>
    <sect_break depth="2"/>
    <sect_break depth="2"/>
    <sect_break depth="3"/>
    <sect_break depth="1"/>
(fwiw, the objective is to create a nested hierarchy from one that is
defined unnested. eg:
<level 1>
<level 2>
<level 2>
<level 3>
<level 1>
<level 1>
    <level 2>
    <level 2>
        <level 3>
<level 1>
Thanks very much for any help!
(using xmlspy)

Current Thread