cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Koberg" <...@koberg.com>
Subject RE: About sitetrees and navigation bars (long post) (Was: Re: Link Livesites: Inventive Designers)
Date Sun, 15 Sep 2002 14:02:10 GMT
Hi,

> -----Original Message-----
> From: Litrik De Roy [mailto:cocoon-users@litrik.com]
> Sent: Sunday, September 15, 2002 6:07 AM
>
> All XSP pages have an attribute "uri" on my top element "Page". It
> identifies the page within the whole site and its the value is also what
> will guide the sitemap.xmap to this XSP. (I know... "uri" might not be the
> best name for the attribute but that's what it is called...)

You could organize your Page elements inside Folder elements and eliminate the
need for your uri attribute. You can crawl up and down the pages and folders to
build paths.

I will use an example from what I do. The snipped XML (there are more elements)
below allows for several things:

- you can build links very easy and maintain integrity.
-- The nav can be built in a numbver of ways by crawling the site tree.
-- Internal links can reference a page or folder ID and be assured it will have
the correct path, even if the page or folder was moved.
- you can assign a 'site index' and 'folder index' pages to identify at
generation time and to copy to index.html in the proper location, a dynamic site
can use this page when a folder link is clicked on.
- you can set different attributes to trigger XSLT components (TOC, snailtrail,
pagination, etc) to be accessed.
- you can assign an XSL at the folder level and it can cascade down to pages
unless overriden at the page level
- you can assign content pieces at the folder and page level in different
columns. If assigned at the folder level it is displayed on all pages in the
folder. (content pieces are a reference to an entry in a content.xml config file
that describes them more)
- you can set status at the folder and page level (you set status for a content
piece in content.xml)

I have to create two sets of navs for the livestoryboard tool. One for the tool
and one for a generated site. The XSLT below shows how I use the site tree xml
to create relative HTML links and javascript: links. I use two URIResolvers
depending on whether the user is in authoring time or generating the site to
static. During tool time the URIResolver resolves util XSLT files to the tool's
set and during generation in resolves to the client's set.

I have an entire site/example up at
http://docs.livestoryboard.com/en_us/manual/Overview.html (though the URL says
docs, there is not too much there yet :( ). And it is a little out of date. I
will have a newer version up in a few days, but it shows many examples of how
the site tree xml can be used.


First an XML snippet (followed by some XSLT):


<config id="clean" nav_col="tabs_narrow_left" p_nam="label"
site_index="siteindex" subtitle="Starter1" title="Clean Site1"
use_tool_style="0">
  <folder display_label_link="true" expand="true" id="f1" index_page="siteindex"
label="Home" name="en_us" pager="true" snailtrail="true" status="editorial"
xsl_fileref="basic_3col.xsl">
    <col type="narrow_right">
      <article id="c413186147"/>
     </col>

  <page display_label_link="true" file_ext=".html" gen="true" id="siteindex"
label="index" metadata="true" print_friendly="true" status="editorial"
title="Clean Index Page" toc="true" xsl_fileref="homepage.xsl">
    <col type="narrow_left"/>
    <col type="wide_center">
      <article id="cindex"/>
      <article id="c1021039099"/>
    </col>
    <col type="narrow_right"/>
  </page>

  <page display_label_link="true" file_ext=".html" gen="true" id="p353715906"
label="page 2" metadata="false" print_friendly="true" status="editorial"
title="page 2" toc="false" xsl_fileref="basic_3col.xsl">
    <col type="narrow_left"/>
    <col type="wide_center">
      <article id="c1919458443"/>
      <article id="cindex"/>
    </col>
    <col type="narrow_right"/>
  </page>

  <folder display_label_link="true" expand="false" id="f953036460"
index_page="p948884099" label="Folder 1" name="Folder1" pager="true"
snailtrail="true" status="editorial" xsl_fileref="basic_3col.xsl">
     <col type="narrow_left"/>
     <col type="wide_center"/>
     <col type="narrow_right"/>

     <page display_label_link="true" file_ext=".html" gen="true" id="p948884099"
label="page 1" metadata="true" print_friendly="true" status="editorial"
title="page 1" toc="true" xsl_fileref="basic_2col.xsl">
    <col type="narrow_left"/>
    <col type="wide_center">
       <article id="c413186147"/>
       <article id="cindex"/>
    </col>
    <col type="narrow_right"/>
     </page>

     <folder display_label_link="true" expand="false" id="f1051775540"
index_page="p1113453353" label="Folder1a" name="f1a" pager="false"
snailtrail="true" status="editorial" xsl_fileref="basic_3col.xsl">
    <col type="narrow_left"/>
    <col type="wide_center"/>
    <col type="narrow_right"/>

    <page display_label_link="true" file_ext=".html" gen="true" id="p1113453353"
label="fdsfasfd" metadata="false" print_friendly="false" status="editorial"
title="sdfadfaf" toc="false" xsl_fileref="basic_3col.xsl">
       <col type="narrow_left"/>
       <col type="wide_center">
      <article id="c1021039099"/>
       </col>
       <col type="narrow_right"/>
    </page>

     </folder>
  </folder>
....
<snip/>

----------------------------------

An XSLT snippet for a nav:

<!-- I use more than one folder type so I set up a key to define them only
once -->
<xsl:key
   name="folder-match-set"
   match="folder | faqs | category | jobs | press_releases"
   use="'folder-types'" />

<xsl:template match="key('folder-match-set', 'folder-types')" mode="nav">

  <xsl:variable name="folder_label" select="@label"/>
  <xsl:variable name="folder_name" select="@name"/>
  <xsl:variable name="folder_id" select="@id"/>

  <xsl:variable name="_href">
    <xsl:call-template name="folder_path_builder"/>
  </xsl:variable>

  <ul id="{generate-id()}" class="open">

    <xsl:choose>
       <xsl:when test="$folder_id=$folder_idref">

        <a href="{$_href}" class="focus" title="{@title}">

          <xsl:value-of select="$folder_label"/>

        </a>

        <xsl:apply-templates select="col" mode="nav"/>
        <xsl:apply-templates select="*[not(name()='col')]" mode="nav"/>
      </xsl:when>
      <xsl:when test="descendant::*[@id=$folder_idref]">

        <a href="{$_href}" class="focus" title="{@title}">

          <xsl:value-of select="$folder_label"/>

        </a>

        <xsl:apply-templates select="*[not(name()='col')]" mode="nav"/>

      </xsl:when>

      <xsl:otherwise>

        <a href="{$_href}" class="blur" title="{@title}">

          <xsl:value-of select="$folder_label"/>

        </a>

      </xsl:otherwise>
    </xsl:choose>

  </ul>

</xsl:template>


<xsl:template match="page" mode="nav">

    <xsl:variable name="_href">
      <xsl:call-template name="page_path_builder"/>
    </xsl:variable>

    <ul class="open">

      <xsl:choose>
        <xsl:when test="not(@id=$page_idref)">

          <a href="{$_href}" class="blur" title="{@title}">

            <xsl:value-of select="@label"/>

          </a>

        </xsl:when>
        <xsl:otherwise>

          <a href="{$_href}" class="focus" title="{@title}">

            <xsl:value-of select="@label"/>

          </a>

          <xsl:apply-templates select="col" mode="nav"/>
        </xsl:otherwise>
      </xsl:choose>

    </ul>


</xsl:template>

------------------

Following are two ways to make links. The first creates regular, relative html
links. The second creates javascript: links for a dynamic app
(livestoryboard.com)

========= html links  /tool/client-site/WEB-INF/styling/common/path_builders.xsl
=================

<xsl:template name="folder_path_builder">
  <xsl:variable name="index_id" select="@index_page"/>
  <xsl:variable name="index_page" select="page[@id=$index_id]"/>

  <xsl:value-of select="$relative_path_to_root"/>
  <xsl:choose>
    <xsl:when test="not($root_nodeset/@site_index=$index_page/@id)">
      <xsl:for-each select="ancestor::*[name()!='config']">
      	<xsl:if test="not(position()=1)">
      		<xsl:text>/</xsl:text>
      	</xsl:if>
      	<xsl:value-of select="@name"/>
      </xsl:for-each>
      <xsl:text>/</xsl:text>
      <xsl:value-of select="@name"/>
      <xsl:text>/</xsl:text>

      <xsl:choose>
        <xsl:when test="boolean($index_page)">

          <xsl:choose>
            <xsl:when test="$page_name_type='id'">
              <xsl:value-of select="$index_page/@id"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="translate($index_page/@label, ' ', '_')"/>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:value-of select="$index_page/@file_ext"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$page_name_type='id'">
              <xsl:value-of select="@id"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="remove_quotes">
                <xsl:with-param name="string" select="translate(@label, ' ',
'_')"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:value-of select="'.html'"/>
        </xsl:otherwise>
      </xsl:choose>


    </xsl:when>
    <xsl:otherwise>
      <xsl:text>index</xsl:text>
      <xsl:value-of select="$index_page/@file_ext"/>
    </xsl:otherwise>
  </xsl:choose>


</xsl:template>

<xsl:template name="page_path_builder">

  <xsl:value-of select="$relative_path_to_root"/>
  <xsl:choose>
    <xsl:when test="not($root_nodeset/@site_index=@id)">
      <xsl:for-each select="ancestor::folder">
        <xsl:if test="not(position()=1)">
          <xsl:text>/</xsl:text>
        </xsl:if>
        <xsl:value-of select="@name"/>
      </xsl:for-each>
      <xsl:text>/</xsl:text>
      <xsl:choose>
        <xsl:when test="$page_name_type='id'">
          <xsl:value-of select="@id"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="remove_quotes">
            <xsl:with-param name="string" select="translate(@label, ' ', '_')"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>index</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:value-of select="@file_ext"/>

</xsl:template>

========== javascript: links /tool/WEB-INF/styling/common/path_builders.xsl
====================


<xsl:template name="folder_path_builder">
   <xsl:variable name="folder_label" select="@label"/>
   <xsl:variable name="folder_name" select="@name"/>
   <xsl:variable name="folder_id" select="@id"/>
   <xsl:variable name="index_id" select="@index_page"/>
   <xsl:variable name="index_node_name" select="name(key('site_config_key',
@index_page))"/>
   <xsl:variable name="index_xsl_fileref" select="key('site_config_key',
@index_page)/@xsl_fileref"/>
   <xsl:variable name="style_fileref">
     <xsl:choose>
         <xsl:when test="$index_xsl_fileref='default'">
             <xsl:value-of select="@xsl_fileref"/>
         </xsl:when>
         <xsl:when test="not($index_node_name='folder')">
             <xsl:apply-templates select="." mode="get_default_styling"/>
         </xsl:when>
         <xsl:when test="$index_id='empty'">
             <xsl:value-of select="@xsl_fileref"/>
         </xsl:when>
         <xsl:when test="@xsl_fileref='default'">
             <xsl:apply-templates select="$folder_nodeset"
mode="get_default_styling"/>
         </xsl:when>
         <xsl:otherwise>
             <xsl:value-of select="$index_xsl_fileref"/>
         </xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:if test="not($type='ToolNav')">
      <xsl:text>javascript:</xsl:text>
   </xsl:if>
   <xsl:value-of select="$cleanup_current_page_call"/>
   <xsl:if test="$type='ToolNav'">
      <xsl:text>_main.</xsl:text>
   </xsl:if>
   <xsl:text>displayPage('</xsl:text>
   <xsl:value-of select="$folder_id"/>
   <xsl:text>','</xsl:text>
   <xsl:value-of select="$index_id"/>
   <xsl:text>','','</xsl:text>
   <xsl:value-of select="$style_fileref"/>
   <xsl:text>')</xsl:text>
</xsl:template>

<xsl:template name="page_path_builder">
  <xsl:variable name="current_page_idref" select="@id"/>
  <xsl:variable name="style_fileref">
      <xsl:choose>
          <xsl:when test="@xsl_fileref='default'">
              <xsl:apply-templates select="key('site_config_key', ../@id)"
mode="get_default_styling"/>
          </xsl:when>
          <xsl:otherwise>
              <xsl:value-of select="@xsl_fileref"/>
          </xsl:otherwise>
      </xsl:choose>
  </xsl:variable>
  <xsl:if test="not($type='ToolNav')">
      <xsl:text>javascript:</xsl:text>
   </xsl:if>
  <xsl:value-of select="$cleanup_current_page_call"/>
  <xsl:if test="$type='ToolNav'">
      <xsl:text>_main.</xsl:text>
   </xsl:if>
  <xsl:text>displayPage('</xsl:text>
  <xsl:value-of select="../@id"/>
  <xsl:text>','</xsl:text>
  <xsl:value-of select="$current_page_idref"/>
  <xsl:text>','','</xsl:text>
  <xsl:value-of select="$style_fileref"/>
  <xsl:text>')</xsl:text>
</xsl:template>

best,
-Rob







---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message