You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lenya.apache.org by Gerd-Christian Michalke <gm...@tiscali.be> on 2005/11/23 12:07:00 UTC

Multi-level table of content

Hi !

I tried to make a toc as described in 
http://wiki.apache.org/lenya/HowToTableOfContents, which works fine.

I wanted to extend from h2 do h3 and h4 level. 

for example, h3 is tagged with

<xsl:template match="xhtml:h3">
   <xsl:copy>
     <xsl:apply-templates select="@*"/>
     <xsl:if test="$rendertype != 'edit'">
     <a name="{.}">
     <xsl:apply-templates select="node()"/></a>
     </xsl:if>
   </xsl:copy>
</xsl:template>

It works ok. I tried to create the toc with this:

<xsl:template name="toc">
  <xsl:if test="count(//xhtml:div[@id='body']/xhtml:h2) &gt; 1">
        <div id="toc">
     Table of Contents
         <ul id="toclist">
           <xsl:for-each select="//xhtml:div[@id='body']/xhtml:h2">
                 <li><a href="#{.}"><xsl:value-of select="." /></a></li>

	  <xsl:if test="count(//xhtml:div[@id='body']/xhtml:h3) &gt; 1">
        	 <ul id="toclist">
	           <xsl:for-each select="//xhtml:div[@id='body']/xhtml:h3">
                	 <li><a href="#{.}"><xsl:value-of select="." /></a></li>
        	   </xsl:for-each>
	         </ul>
        	</div>
	  </xsl:if>


           </xsl:for-each>
         </ul>
        </div>
  </xsl:if>
</xsl:template>


Which gives something such as (as it should)

* H2_1
 - H3_1
 - H3_2
 - H3_3
 - H3_4
* H2_2
 - H3_1
 - H3_2
 - H3_3
 - H3_4

instead of
* H2_1
 - H3_1
 - H3_2
* H2_2
 - H3_3
 - H3_4

How can I do ? The problem is that from a xpath point of you, all H2 and H3 
tittles aren't children but are at the same level.

Thanks a lot in advance,
Gerd

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org


Re: Multi-level table of content

Posted by so...@gmail.com.
On 11/24/05, Gerd-Christian Michalke <gm...@tiscali.be> wrote:
> first, I want to thank you very much: you made my day ;-)
> May I suggest one little change ?
> The anchor needed the # removed
>
> This works really great on IE, Firefox and Konqueror. Would you mind put it on
> the Wiki ? If you wish I may write some article, with credits, obviously.

Oops, I copied it poorly.  I tested with MSIE and Mozilla.  I posted it at:
http://solprovider.com/lenya/menuheaders

I assume anything on the MLs is public domain (but I could be wrong. 
I have not checked the rules.)  The Lenya organization has permission
to use any Lenya-related content from solprovider.com.  A few articles
were imported, but we had maintenance issues; I fixed my version based
on bug reports to the ML, but the Lenya website was not updated.  The
Wiki would be easier to update, but I am afraid I might dominate it (I
tend to write prolifically), and it is useful to have multiple
versions of similar tasks.  The HowToTableOfContents Wiki entry
includes JS for hiding the menu; mine does not.

solprovider

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org


Re: Multi-level table of content

Posted by Gerd-Christian Michalke <gm...@tiscali.be>.
Hi !

first, I want to thank you very much: you made my day ;-)

May I suggest one little change ?

<xsl:template match="xhtml:h1|xhtml:h2|xhtml:h3|xhtml:h4|xhtml:h5|xhtml:h6">
<xsl:variable name="count"><xsl:number
count="xhtml:h1|xhtml:h2|xhtml:h3|xhtml:h4|xhtml:h5|xhtml:h6"/></xsl:variable> 
<a name="{name()}-{$count}"/>
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>

The anchor needed the # removed


This works really great on IE, Firefox and Konqueror. Would you mind put it on 
the Wiki ? If you wish I may write some article, with credits, obviously.

Bye,
Gerd

Le Mercredi 23 Novembre 2005 23:42, solprovider@gmail.com a écrit :
> On 11/23/05, Gerd-Christian Michalke <gm...@tiscali.be> wrote:
> > I tried to make a toc as described in
> > http://wiki.apache.org/lenya/HowToTableOfContents, which works fine.
> >
> > I wanted to extend from h2 do h3 and h4 level.
>
> I tried to move the tags into a hierarchy using just XSL.  It almost
> worked, but there were too many hacks.  I would be very interested if
> someone else has a solution.
>
> Below is a solution that handles all 6 levels of headers. It depends
> on CSS for formatting the data; the XML is not hierarchical.  The
> anchors are named like "h3-7" (tag name + "-" + absolute position);
> this solves the issues of duplicates and url-encoding the text, but
> makes the names much less memorable.  The tag name and the dash are
> not necessary; they are remnants of earlier attempts.
>
> solprovider
>
> ==
> Put this line where you want the headers menu:
> <xsl:apply-templates
> select="//xhtml:h1|//xhtml:h2|//xhtml:h3|//xhtml:h4|//xhtml:h5|//xhtml:h6"
> mode="headers"/>
>
> Add these matches:
> <!-- Headers Menu -->
> <xsl:template match="xhtml:h1|xhtml:h2|xhtml:h3|xhtml:h4|xhtml:h5|xhtml:h6"
> mode="headers">
> <xsl:element name="div">
> <xsl:attribute name="class">header<xsl:value-of
> select="substring-after(name(), 'h')"/></xsl:attribute>
> <a href="#{name()}-{position()}"><xsl:value-of select="."/></a>
> </xsl:element>
> </xsl:template>
> <!-- Add Named Anchors to Headers -->
> <xsl:template
> match="xhtml:h1|xhtml:h2|xhtml:h3|xhtml:h4|xhtml:h5|xhtml:h6">
> <xsl:variable name="count"><xsl:number
> count="xhtml:h1|xhtml:h2|xhtml:h3|xhtml:h4|xhtml:h5|xhtml:h6"/></xsl:variab
>le> <a name="#{name()}-{$count}"/>
> <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
> </xsl:template>
>
> Add this to your CSS (to indent each level):
> /* Header Menu */
> .header1 {  padding: 0px 0px 0px 0px; }
> .header2 {  padding: 0px 0px 0px 10px; }
> .header3 {  padding: 0px 0px 0px 20px; }
> .header4 {  padding: 0px 0px 0px 30px; }
> .header5 {  padding: 0px 0px 0px 40px; }
> .header6 {  padding: 0px 0px 0px 50px; }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
> For additional commands, e-mail: user-help@lenya.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org


Re: Multi-level table of content

Posted by so...@gmail.com.
On 11/23/05, Gerd-Christian Michalke <gm...@tiscali.be> wrote:
> I tried to make a toc as described in
> http://wiki.apache.org/lenya/HowToTableOfContents, which works fine.
>
> I wanted to extend from h2 do h3 and h4 level.

I tried to move the tags into a hierarchy using just XSL.  It almost
worked, but there were too many hacks.  I would be very interested if
someone else has a solution.

Below is a solution that handles all 6 levels of headers. It depends
on CSS for formatting the data; the XML is not hierarchical.  The
anchors are named like "h3-7" (tag name + "-" + absolute position);
this solves the issues of duplicates and url-encoding the text, but
makes the names much less memorable.  The tag name and the dash are
not necessary; they are remnants of earlier attempts.

solprovider

==
Put this line where you want the headers menu:
<xsl:apply-templates
select="//xhtml:h1|//xhtml:h2|//xhtml:h3|//xhtml:h4|//xhtml:h5|//xhtml:h6"
mode="headers"/>

Add these matches:
<!-- Headers Menu -->
<xsl:template match="xhtml:h1|xhtml:h2|xhtml:h3|xhtml:h4|xhtml:h5|xhtml:h6"
mode="headers">
<xsl:element name="div">
<xsl:attribute name="class">header<xsl:value-of
select="substring-after(name(), 'h')"/></xsl:attribute>
<a href="#{name()}-{position()}"><xsl:value-of select="."/></a>
</xsl:element>
</xsl:template>
<!-- Add Named Anchors to Headers -->
<xsl:template match="xhtml:h1|xhtml:h2|xhtml:h3|xhtml:h4|xhtml:h5|xhtml:h6">
<xsl:variable name="count"><xsl:number
count="xhtml:h1|xhtml:h2|xhtml:h3|xhtml:h4|xhtml:h5|xhtml:h6"/></xsl:variable>
<a name="#{name()}-{$count}"/>
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>

Add this to your CSS (to indent each level):
/* Header Menu */
.header1 {  padding: 0px 0px 0px 0px; }
.header2 {  padding: 0px 0px 0px 10px; }
.header3 {  padding: 0px 0px 0px 20px; }
.header4 {  padding: 0px 0px 0px 30px; }
.header5 {  padding: 0px 0px 0px 40px; }
.header6 {  padding: 0px 0px 0px 50px; }

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org