xsl-list
[Top] [All Lists]

RE: Creating lists and sublists from a level attribute

2004-09-01 06:34:28
Here's an adaptation of a stylesheet I presented at the Oxford summer
school: a recursive template using XSLT 2.0 xsl:for-each-group. 

<xsl:template name="process-level">
  <xsl:param name="population" required="yes" as="element(heading)*"/>
  <xsl:param name="level" required="yes" as="xs:integer"/>
  <xsl:if test="$population">
   <ul>
    <xsl:for-each-group select="$population" 
                group-starting-with="*[xs:integer(@level) eq $level]">
     <li>
      <p><xsl:value-of select="."/></p>   
      <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>
     </li>
    </xsl:for-each-group>
   </xsl:if>
  </ul>
</xsl:template>

Call it like this:

<xsl:call-template name="process-level">
  <xsl:with-param name="population" select="child::heading"/>
  <xsl:with-param name="level" select="1"/>
</xsl:call-template>

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Andrew Brothwell [mailto:ANBROTH(_at_)uk(_dot_)ibm(_dot_)com] 
Sent: 01 September 2004 14:16
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Creating lists and sublists from a level attribute

Hi,

I currently have a series of <heading> tags in the xml file. 
These are not 

embedded within each other, but have a level attribute to 
indicate which 
ones are sub headings of others. For instance:

<heading level="1">A main Heading</heading>
<heading level="2">Sub heading of main heading</heading>
<heading level="2">another sub heading of main heading</heading>
<heading level="1">Another main Heading</heading> 

There can be up to 4 levels.

What I am trying to achieve is a "document outline" at the 
top of the page 

that takes each heading and puts it in a list, with sub 
headings being 
sublists of their parent headings. I am struggling to find a way to 
arrange the <ul> and <li> tags to achieve this, and any help 
would be much 

appreciated.

thanks, 

Andy

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





<Prev in Thread] Current Thread [Next in Thread>