forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Koberg" <...@koberg.com>
Subject expanded tree & site.xml -> was -> RE: Usability news website (fwd)
Date Wed, 26 Mar 2003 20:14:43 GMT
Hi,

You could make this configurable by adding an attribute (I use
@expand). Perhaps this is a place to start adding attributes to the
site.xml?

So you might have this attribute on a folder node:

<folder
id="cocoon_about" label="About" expand="0" onnav="1" index_page="about_index">
... page nodes ...
</folder>
<folder
id="cocoon_community" label="Community" expand="1" onnav="1"
index_page="community_index">
... page nodes ...
</folder>

I would also suggest to make the label attribute an element so users can
add some simple semantics to labels (I currently allow em and
strong). Also perhaps add a title element as well???

The onnav attribute allows for pages that should not show on the nav, but
should be accessible to the href building templates.

The index_page attribute sets the default page for the folder. I use the
XML Schema to constrain this to a page id.

Then an XSL (the XML source is the site.xml) can do something like:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="nav">
  <div id="nav">
    <div class="title">In this section:</div>
<!--
pass in or somehow set:
- the current folder ancestor id, $folder_id
- the relative path to the docroot, $relative_path
-->
    <xsl:apply-templates
      select="key('site', $folder_id)/*[not(local-name()='label')]"
      mode="nav"/>
  </div>
  <xsl:call-template name="util_nav"/>
</xsl:template>

<xsl:template match="folder" mode="nav">
  <xsl:if test="@onnav='1'">
    <xsl:variable name="_href">
      <xsl:call-template name="folder_path_builder"/>
    </xsl:variable>
    <xsl:variable name="title">
      <xsl:value-of select="key('site', @index_page)/title"/>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="@expand='1'">
        <div class="normal" title="{$title}">
          <div class="expandedFolder">
            <xsl:apply-templates select="label" mode="nav"/>
          </div>
          <div class="expanded">
            <xsl:apply-templates
select="*[not(local-name()='label')]" mode="nav"/>
          </div>
        </div>
      </xsl:when>
      <xsl:when test="not(@id=$folder_idref or
descendant::*[@id=$folder_idref])">
        <div>
          <a href="{$_href}"
            class="normal"
            title="{$title}"
            onmouseover="this.className='hover'"
            onmouseout="this.className='normal'">
            <img src="{$relative_path}images/f.gif" alt="Links to a
section"/>
            <xsl:apply-templates select="label" mode="nav"/>
          </a>
        </div>
      </xsl:when>
      <xsl:otherwise>
        <div>
          <a href="{$_href}" class="selected" title="{$title}">
            <xsl:text> &#187; </xsl:text>
            <xsl:apply-templates select="label" mode="nav"/>
          </a>
        </div>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>
</xsl:template>

<xsl:template match="page" mode="nav">
  <xsl:if test="@onnav='1' and @generate='1'">
    <xsl:variable name="id" select="@id"/>
    <xsl:variable name="_href">
      <xsl:call-template name="page_path_builder"/>
    </xsl:variable>
    <xsl:variable name="title">
      <xsl:value-of select="title"/>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="not($id=$page_idref)">
        <div>
          <a href="{$_href}"
            class="normal"
            title="{$title}"
            onmouseover="this.className='hover'"
            onmouseout="this.className='normal'">
            <img src="{$relative_path}images/p.gif" alt="Links to a
page"/>
            <xsl:apply-templates select="label" mode="nav"/>
          </a>
        </div>
      </xsl:when>
      <xsl:otherwise>
        <div>
          <a href="{$_href}" class="selected" title="{$title}">
            <xsl:text> &#187; </xsl:text>
            <xsl:apply-templates select="label" mode="nav"/>
          </a>
        </div>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>
</xsl:template>

<xsl:template match="label" mode="nav">
  <xsl:apply-templates mode="nav"/>
</xsl:template>

<xsl:template match="strong | em" mode="nav">
  <xsl:element name="{local-name()}">
    <xsl:apply-templates mode="nav"/>
  </xsl:element>
</xsl:template>

</xsl:stylesheet>

//************
href variable templates
//************

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="ancestor_path">
  <xsl:for-each select="ancestor::folder">
    <xsl:value-of select="@name"/>
    <xsl:text>/</xsl:text>
  </xsl:for-each>
</xsl:template>

<xsl:template name="folder_path_builder">
  <xsl:variable name="id" select="@id"/>
  <xsl:variable name="index_id" select="@index_page"/>
  <xsl:variable name="index_page" select="page[@id=$index_id]"/>
  <xsl:value-of select="$relative_path"/>
  <xsl:call-template name="ancestor_path"/>
  <xsl:value-of select="@name"/>
  <xsl:if test="local-name()='folder_conf'">
    <xsl:text>/</xsl:text>
  </xsl:if>
  <xsl:text>index.html</xsl:text>
</xsl:template>

<xsl:template name="page_path_builder">
  <xsl:value-of select="$relative_path"/>
  <xsl:variable name="id" select="@id"/>
  <xsl:call-template name="ancestor_path"/>
  <xsl:value-of select="@name"/>
</xsl:template>

</xsl:stylesheet>

best,
-Rob


> -----Original Message-----
> From: Nicola Ken Barozzi [mailto:nicolaken@apache.org]
> Sent: Wednesday, March 26, 2003 7:39 AM
> To: forrest-dev@xml.apache.org
> Subject: Re: Usability news website
>
>
>
>
> Stefano Mazzocchi wrote, On 26/03/2003 12.23:
> > Nicola Ken Barozzi wrote:
> ...
> > when entering the tree, it is shown as
> >
> >  v 1
> >    > 1.1
> >      1.2
> >      1.3
> >  v 2
> >      2.1
> >      2.2
> >    > 2.3
> >
> > this is better than simply
> >
> >  > 1
> >  > 2
> > because it gives enough contextual information for the user to
navigate.
> >
>
> Ok, I reckoned too.
<snip/>


Mime
View raw message