forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric BURGHARD <>
Subject Re: [CONTRIB] auto generation of menus
Date Tue, 07 Oct 2003 00:59:54 GMT
Le Lundi 06 Octobre 2003 08:47, Jeff Turner a écrit :
> On Fri, Oct 03, 2003 at 11:12:04PM +0200, Eric BURGHARD wrote:
> > Hi,
> >
> > I've made some modifications to directory2book.xsl (which generate side
> > menu based on directory content):
> > -little cleanup (expected-extension argument no more needed)
> > -kind of control on which items are present or not
> > -allow parametrable sorting of menu-items
> > -easily extensible.
> Nice.  I've committed it with some modifications:
>  - Used the existing pathutils.xsl instead of substring-last.xsl
>  - I didn't understand the purpose of documentdirectory.xsl, so I put its
>    enhanced get-label template in directory2book.xml.  Any reason to
>    separate it out, other than to demonstrate its 'overridability'?

Yeah, in fact, directory2book.xsl is not specificly designed to be used with 
XPathDirectoryGenerator. Right ? After a simple DirectoryGenerator you've got 
no dir:xpath nodeset in the result. So is there any good reason to compute 
the menu-items labels from inexistants tags and rely on the default behavior 
which take them from the filenames ?

On the other side, when you apply documentdirectory2book.xsl you say 
indirectly your intention to scan directory full of document-v20 compliant 
xml. This stylesheet rely on XPathDirectoryGenerator because the get-label 
template make use of dir:xpath contents.

If you've got docbook directories, perhaps you want to get the labels from 
something else than <meta name="short-title"/> (the meta tag could possibly 
not exists in docbook or exists in another branch than document/header, i 
don't know). So just edit a new docbookdirectory2book.xsl which only need to 
override the get-label with something like:

<xsl:template name="get-label">
 <xsl:value-of select="dir:xpath/whatever-tab"/>

and modify your sitemap.xmap accordingly

<map:generate label="debug" src="content/xdocs/{1}{2}" type="xpathdirectory">
  <map:parameter name="xpath" value="//whatever-tab">
  <map:transform src="resources/stylesheets/docbookdirectory2book.xsl"/>
  <map:serialize type="xml">

In the last version of my directory2book.xsl (attached) I also define a 
get-href named template. That way you can easily compute the urls served by 
menu-items. Example: for my simple gallery i use a jpegdirectory2book.xsl 
which is quite simple and clear:

    <xsl:import href="directory2book.xsl"/>
    <xsl:output doctype-public="-//APACHE//DTD Cocoon Documentation Book 
V1.0//EN" doctype-system="book-cocoon-v10.dtd"/>

    <!-- link to screen oriented jpegs -->
    <xsl:template name="get-href">
        <xsl:param name="corename"/>
        <xsl:value-of select="concat($corename, '-1024.jpg')"/>


for each of my jpegs i've got a menu-item item which link to something like 
img-1024.jpg which refer to img.jpg with a 1024 pixels height.

Somewhere in my sitemap.xmap i've got this to generate jpeg at a given height.

<map:match pattern="(.*)-([0-9]*).jpg" type="regexp">
  <map:read src="content/xdocs/{1}.jpg" type="image">
     <map:parameter name="height" value="{2}"/>

and by default (in directory2book.xsl) get-href is

<xsl:template name="get-href">
   <xsl:param name="corename"/>
   <xsl:value-of select="concat($corename, '.', $served-extension)"/>

which link items with something like filename.html

> Sorting by XPath is a good idea, but ordering still doesn't seem flexible
> enough for ordinary sites.  Perhaps we need another transformer that sets
> a <meta name="order"> field based on some clever algorithm:
> <map:generate src="content/xdocs/{1}" type="xpathdirectory"/>
> <map:transform type="sorter"/>
> <map:transform src="resources/stylesheets/directory2book.xsl"/>

That would be nice. I didn't like the fact to use a non standard xslt 
extension to achieve this sorting flexibility in my stylesheet, but it was a 
good preliminary that fullfill my needs.

> Then pages could have some metadata used by the sorting algorithm:
> <meta name="group">GettingStarted</meta>
> <meta name="comes-after">index.html</meta>
> <meta name="comes-before">primer.html</meta>

Yeah ! much more flexibility like this ! Thus you can already achieve quite 
the same behavior with the actual sorting mechanism and without the hassle of 
programming a constraints resolution engine. Use directory hierachie a 
relaxed numbering scheme (like sysV init filenames):

directory: GettingStarted
<meta name="menu-order">S5</meta>

<meta name="menu-order">S0</meta>

<meta name="menu-order">S20</meta>

and do your sorting with

<map:transform src="resources/stylesheets/documentdirectory2book.xsl">
   <map:parameter name="sort-select" 

PS: What did the pathutils.xsl do in resources/skins/common/xslt/html 
directory ? Shouldn't it be placed in resources/stylesheets ?

> --Jeff

View raw message