Re: [xsl] following-sibling problem

Subject: Re: [xsl] following-sibling problem
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Thu, 28 Oct 2004 09:13:12 -0400
On Oct 27, 2004, at 9:38 AM, Michael Kay wrote:

For a very similar problem I used:

<xsl:template name="process-level">
<xsl:param name="population" required="yes" as="element()*"/>
<xsl:param name="level" required="yes" as="xs:integer"/>
<xsl:for-each-group select="$population"
group-starting-with="*[xs:integer(@level) eq $level]">
<xsl:element name="{@tag}">
<xsl:copy-of select="@ID[string(.)], @REF[string(.)]"/>
<xsl:value-of select="normalize-space(@text)"/>
<xsl:call-template name="process-level">
<xsl:with-param name="population" select="current-group() except
.."/>
<xsl:with-param name="level" select="$level + 1"/>
</xsl:call-template>
</xsl:element>
</xsl:for-each-group>
</xsl:template>


Prime this with the population parameter set to the entire sequence of key
elements, and level set to 0, and it will build the hierarchy for you; you
only need to change the instructions that construct new elements and
attributes in the new hierarchy.

I'm a little stuck on this; I end up sending Saxon into an infinite loop with my current code:


<xsl:template match="key:slide">
  <div class="slide">
    <xsl:apply-templates select="key:bullets"/>
  </div>
</xsl:template>

<xsl:template match="key:bullets">
<xsl:choose>
<xsl:when test="../@master-slide-id='master-slide-1'">
<xsl:apply-templates select="key:bullet[@level='0']" mode="title"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="process-level">
<xsl:with-param name="bullet" select="key:bullet"/>
<xsl:with-param name="level" select="0"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template match="key:bullet[@level='0']" mode="title">
  <h1><xsl:value-of select="$title"/></h1>
  <h3><xsl:value-of select="$author"/></h3>
</xsl:template>

<xsl:template name="process-level">
<xsl:param name="bullet" required="yes" as="element()*"/>
<xsl:param name="level" required="yes" as="xs:integer"/>
<xsl:for-each-group select="$bullet"
group-starting-with="*[xs:integer(@level) eq $level]">
<ul>
<li><xsl:value-of select="normalize-space(.)"/></li>
<xsl:call-template name="process-level">
<xsl:with-param name="bullet" select="current-group() except ..."/>
<xsl:with-param name="level" select="$level + 1"/>
</xsl:call-template>
</ul>
</xsl:for-each-group>
</xsl:template>


Current Thread