forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From je...@apache.org
Subject cvs commit: xml-forrest/src/resources/stylesheets directory2book.xsl
Date Mon, 06 Oct 2003 06:32:48 GMT
jefft       2003/10/05 23:32:48

  Modified:    src/resources/stylesheets directory2book.xsl
  Log:
  Enhancements that allow an auto-generated menu to use metadata inside the page
  (requires XPathDirectoryGenerator output).  The label can be customized if
  <title> is too long, and the sort order can be determined by an XPath
  expression in the sitemap.
  
  Thanks to Eric BURGHARD <eburghar @ free.fr>
  
  Revision  Changes    Path
  1.10      +90 -40    xml-forrest/src/resources/stylesheets/directory2book.xsl
  
  Index: directory2book.xsl
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/stylesheets/directory2book.xsl,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- directory2book.xsl	2 Oct 2003 06:32:32 -0000	1.9
  +++ directory2book.xsl	6 Oct 2003 06:32:48 -0000	1.10
  @@ -20,51 +20,101 @@
     <map:transform src="resources/stylesheets/directory2book.xsl" />
     <map:serialize type="xml"/>
   </map:match>
  --->
  -
  -<xsl:stylesheet version="1.0"
  -  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  -  xmlns:dir="http://apache.org/cocoon/directory/2.0" exclude-result-prefixes="dir">
  -
  -  <xsl:output doctype-system="book-cocoon-v10.dtd" doctype-public="-//APACHE//DTD Cocoon
Documentation Book V1.0//EN"/>
   
  -  <xsl:param name="expected-extension" select="'xml'"/>
  -  <xsl:param name="served-extension" select="'html'"/>
  -
  -  <xsl:variable name="ext" select="concat('.', $expected-extension)"/>
  -  <xsl:variable name="sext" select="concat('.', $served-extension)"/>
  +Alternatively, the XPathDirectoryGenerator can be used to include some page
  +metadata (label, meta attributes) in the XML, and the directory listing can
  +then be sorted by an XPath expression specified in the sitemap:
  +
  +<map:match pattern="(.*)(dir1|dir2|dir3)/book-(.*)" type="regexp">
  +   <map:generate label="debug" src="content/xdocs/{1}{2}" 
  +type="xpathdirectory">
  +      <map:parameter name="depth" value="2"/>
  +      <map:parameter name="xpath" value="/document/header/meta | 
  +/document/header/title"/>
  +   </map:generate>
  +   <map:transform src="resources/stylesheets/directory2book.xsl">
  +      <map:parameter name="sort-order" value="descending"/>
  +      <map:parameter name="sort-select" value="dir:xpath/meta[@name='date']"/>
  +   </map:transform>
  +   <map:serialize type="xml"/>
  +</map:match>
  +-->
   
  -  <xsl:template match="/">
  -    <book software="" title="" copyright="">
  -      <!--
  +<xsl:stylesheet exclude-result-prefixes="dir" version="1.0"
  +    xmlns:dir="http://apache.org/cocoon/directory/2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  +    xmlns:dyn="http://exslt.org/dynamic">
  +    <xsl:import href="../../skins/common/xslt/html/pathutils.xsl"/>
  +    <xsl:output doctype-public="-//APACHE//DTD Cocoon Documentation Book V1.0//EN" doctype-system="book-cocoon-v10.dtd"/>
  +
  +    <xsl:param name="served-extension" select="'html'"/>
  +    <xsl:param name="sort-order" select="'ascending'"/>
  +    <xsl:param name="sort-case-order" select="'upper-first'"/>
  +    <xsl:param name="sort-select" select="'.'"/>
  +            
  +    <xsl:template match="/">
  +        <book copyright="" software="" title="">
  +            <!--
         <menu label="Aggregates">
           <menu-item label="Combined content" href="combined.html"/>
         </menu>
         -->
  -      <xsl:apply-templates/>
  -    </book>
  -  </xsl:template>
  -
  -  <xsl:template match="dir:directory">
  -    <menu label="{translate(@name,'-_',' ')}">
  -      <xsl:apply-templates select="dir:file" />
  -    </menu>
  -      <!-- [descendant::dir:file] is to remove empty menu nodes -->
  -      <xsl:apply-templates select="dir:directory [descendant::dir:file]" />
  -  </xsl:template>
  -
  -  <xsl:template match="dir:file">
  -    <menu-item label="{translate(substring-before(@name, $ext),'-_',' ')}">
  -      <xsl:attribute name="href">
  -      <xsl:variable name="path" />
  -        <!-- [not (position()=last())] is to ignore the root node -->
  -        <xsl:for-each select="ancestor::dir:directory [not (position()=last())]">
  -          <xsl:variable name="path" select="concat($path, @name, '/')" />
  -          <xsl:value-of select="$path"/>
  -        </xsl:for-each>
  -        <xsl:value-of select="concat(substring-before(@name, $ext), $sext)"/>
  -      </xsl:attribute>
  -    </menu-item>
  -  </xsl:template>
  +            <xsl:apply-templates/>
  +        </book>
  +    </xsl:template>
  +
  +    <xsl:template match="dir:directory">
  +        <menu label="{translate(@name,'-_',' ')}">
  +           <xsl:apply-templates select="dir:file">
  +                <xsl:sort order="{$sort-order}"  case-order="{$sort-case-order}" select="dyn:evaluate($sort-select)"/>
  +            </xsl:apply-templates>
  +        </menu>
  +        <xsl:apply-templates select="dir:directory [descendant::dir:file]"/>
  +    </xsl:template>
  +
  +    <xsl:template match="dir:file">
  +        <!-- name without extension -->
  +        <xsl:variable name="corename">
  +            <xsl:call-template name="path-noext">
  +                <xsl:with-param name="path" select="@name"/>
  +            </xsl:call-template>
  +        </xsl:variable>
  +        <!-- indirection to allow get-label overriding -->
  +        <xsl:variable name="label">
  +            <xsl:call-template name="get-label">
  +                <xsl:with-param name="corename" select="$corename"/>
  +            </xsl:call-template>
  +        </xsl:variable>
  +        <!-- empty label means side menu item inexistence -->
  +        <xsl:if test="$label != ''">
  +            <menu-item label="{$label}">
  +                <xsl:attribute name="href">
  +                    <xsl:variable name="path"/>
  +                    <xsl:for-each select="ancestor::dir:directory [not (position()=last())]">
  +                        <xsl:variable name="path" select="concat($path, @name, '/')"/>
  +                        <xsl:value-of select="$path"/>
  +                    </xsl:for-each>
  +                    <xsl:value-of select="concat($corename, '.', $served-extension)"/>
  +                </xsl:attribute>
  +            </menu-item>
  +        </xsl:if>
  +    </xsl:template>
  +
  +    <!-- label is  short-title, title and in last resort filename
  +         override this to your needs -->
  +    <xsl:template name="get-label">
  +        <xsl:param name="corename"/>
  +        <xsl:choose>
  +            <xsl:when test="dir:xpath/meta[@name='short-title']">
  +                <xsl:value-of select="dir:xpath/meta[@name='short-title']"/>
  +            </xsl:when>
  +            <xsl:when test="dir:xpath/title">
  +                <xsl:value-of select="dir:xpath/title"/>
  +            </xsl:when>
  +            <xsl:otherwise>
  +                <xsl:value-of select="$corename"/>
  +            </xsl:otherwise>
  +        </xsl:choose>
  +    </xsl:template>
   
  +    
   </xsl:stylesheet>
  
  
  

Mime
View raw message