Re: [xsl] Generating an HTML with a navigation menu and a full listing.

Subject: Re: [xsl] Generating an HTML with a navigation menu and a full listing.
From: "cking" <cking@xxxxxxxxxx>
Date: Fri, 27 Aug 2004 22:26:51 +0200
Hi Shlomi,

First some remarks about your stylesheet:

<xsl:template match="comparison">
    <xsl:apply-templates select="//comparison/contents/section">

Don't do this: it will scan the complete input file into the deepest level,
searching for comparison elements. The template is already in the
comparison element context, so it's better to use:

    <xsl:apply-templates select="contents/section">

<xsl:with-param name="toc" value="1"/>

xsl:with-param takes a select, not a value attribute.
That's why, in the corresponding template, <xsl:when test="$toc = 1">
is never reached. Anyway, using params here is not necessary,
it's much easier to use a different mode (see below).

Here's a reworked version of compare-ml.xsl, it will generate a 
table of contents just like the one in comparison.html:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"

 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"

 <xsl:key name="impl" match="/comparison/meta/implementations/impl" use="@id"/>

 <xsl:template match="/comparison">
  <html xmlns="";>
    <title><xsl:value-of select="contents/section[@id='main']/title"/></title>
    <style type="text/css">
     h2 { background-color : #98FB98; /* PaleGreen */ }
     h3 { background-color : #FFA500; /* Orange */ } 
       margin-left : 1em; 
       margin-right : 1em; 
       width: 90%;
       max-width : 40em;
     .compare td 
       border-color : black; border-style : solid ; border-width : thin;
       vertical-align : top;
       padding : 0.2em;
       list-style-type : none ; padding-left : 0em;
     .toc ul
       list-style-type : none ; 
       padding-left : 0em; 
       margin-left : 2em;
       border-style : solid ; border-width : thin;
       background-color : #E6E6FA; /* Lavender */
       border-color : black;
       padding : 0.3em;
     :link:hover { background-color : yellow }
    <xsl:apply-templates select="contents"/>

 <xsl:template match="contents">
  <xsl:apply-templates select="section"/>

 <xsl:template match="section">
  <xsl:element name="h{count(ancestor-or-self::section)}">
   <a id="{@id}"></a>
   <xsl:value-of select="title"/>
  <xsl:apply-templates select="expl"/>
  <xsl:if test="@id = 'main'">
    <xsl:apply-templates select="section" mode="toc"/>
  <xsl:apply-templates select="section"/>
  <xsl:apply-templates select="compare"/>

 <xsl:template match="section" mode="toc">
   <a href="#{@id}"><xsl:value-of select="title"/></a>
   <xsl:if test="section">
     <xsl:apply-templates select="section" mode="toc"/>

 <xsl:template match="expl">
  <p class="expl">
   <xsl:value-of select="."/>

 <xsl:template match="compare">
  <table class="compare">
   <xsl:apply-templates select="s"/>

 <xsl:template match="s">
   <td class="sys"><xsl:value-of select="key('impl', @id)/name"/></td>
   <td class="desc"><xsl:value-of select="."/></td>


Best regards,
Anton Triest

Friday, August 27, 2004 7:39 PM, Shlomi Fish wrote:
> Hi!
> I have a grammar for comparisons with the following DTD:
> A sample input (known to be valid) is:
> Now, I'd like to generate a page with the items preceded by a navigation menu 
> of them not unlike this:
> The XSL transformation I have so far is:
> How can I modify it to do it?
> Regards,
> Shlomi Fish

Current Thread