[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Generating an HTML with a navigation menu and a fu

Subject: Re: Generating an HTML with a navigation menu and a full listing.
From: "cking" <cking@xxxxxxxxxx>
Date: Fri, 27 Aug 2004 22:26:51 +0200
xml navigation menu
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"
 xmlns="http://www.w3.org/1999/xhtml"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 >

 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  />

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

 <xsl:template match="/comparison">
  <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
    <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 */ }
     table.compare 
     { 
       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;
     }
     ul.toc
     {
       list-style-type : none ; padding-left : 0em;
     }
     .toc ul
     {
       list-style-type : none ; 
       padding-left : 0em; 
       margin-left : 2em;
     }
     .expl
     {
       border-style : solid ; border-width : thin;
       background-color : #E6E6FA; /* Lavender */
       border-color : black;
       padding : 0.3em;
     }
     :link:hover { background-color : yellow }
    </style>
   </head>
   <body>
    <xsl:apply-templates select="contents"/>
   </body>
   <!--http://rafb.net/paste/results/lTurEi25.html-->
  </html>
 </xsl:template>

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

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

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

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

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

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

</xsl:stylesheet>

HTH
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:
> 
> http://opensvn.csie.org/betterscm/better-scm-comparison/trunk/comparison.dtd
> 
> A sample input (known to be valid) is:
> 
> http://opensvn.csie.org/betterscm/better-scm-comparison/trunk/scm-comparison.xml
> 
> Now, I'd like to generate a page with the items preceded by a navigation menu 
> of them not unlike this:
> 
> http://better-scm.berlios.de/comparison/comparison.html
> 
> The XSL transformation I have so far is:
> 
> http://opensvn.csie.org/betterscm/better-scm-comparison/trunk/compare-ml.xsl
> 
> How can I modify it to do it?
> 
> Regards,
> 
> Shlomi Fish

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.