You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by je...@apache.org on 2003/01/04 13:09:54 UTC

cvs commit: xml-forrest/src/resources/skins/common/xslt/html book2menu.xsl pathutils.xsl

jefft       2003/01/04 04:09:54

  Modified:    src/resources/skins/common/xslt/html Tag: LINKMAP_BRANCH
                        book2menu.xsl pathutils.xsl
  Log:
  Normalize ..'s in paths, so the current menu entry is highlighted
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.1   +10 -2     xml-forrest/src/resources/skins/common/xslt/html/book2menu.xsl
  
  Index: book2menu.xsl
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/skins/common/xslt/html/book2menu.xsl,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- book2menu.xsl	28 Nov 2002 14:22:34 -0000	1.7
  +++ book2menu.xsl	4 Jan 2003 12:09:53 -0000	1.7.2.1
  @@ -66,9 +66,17 @@
         </xsl:call-template>
       </xsl:variable>
   
  +    <xsl:variable name="actual-path">
  +      <xsl:call-template name="normalize">
  +        <xsl:with-param name="path" select="concat($dirname, $href-noext)"/>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:message>## Checking <xsl:value-of select="$actual-path"/> against <xsl:value-of select="$path-noext"/></xsl:message>
  +
       <xsl:choose>
         <!-- Compare with extensions stripped -->
  -      <xsl:when test="concat($dirname, $href-noext) = $path-noext">
  +      <xsl:when test="$actual-path = $path-noext">
           <xsl:choose>
             <xsl:when test="contains(@href, '#')">
               <xsl:call-template name="selected-anchor"/>
  
  
  
  1.2.2.1   +72 -8     xml-forrest/src/resources/skins/common/xslt/html/pathutils.xsl
  
  Index: pathutils.xsl
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/skins/common/xslt/html/pathutils.xsl,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- pathutils.xsl	22 Nov 2002 11:36:38 -0000	1.2
  +++ pathutils.xsl	4 Jan 2003 12:09:53 -0000	1.2.2.1
  @@ -29,6 +29,18 @@
     </xsl:if>
   </xsl:template>
   
  +<!-- Normalized (..'s eliminated) version of 'dirname' -->
  +<xsl:template name="dirname-nz">
  +  <xsl:param name="path" />
  +  <xsl:call-template name="normalize">
  +    <xsl:with-param name="path">
  +      <xsl:call-template name="dirname">
  +        <xsl:with-param name="path" select="$path" />
  +      </xsl:call-template>
  +    </xsl:with-param>
  +  </xsl:call-template>
  +</xsl:template>
  +
   
   <!-- Returns the filename part of a path.  Equivalent to Unix 'basename'
   Examples:
  @@ -111,27 +123,79 @@
     <xsl:value-of select="substring($path, 1, string-length($path) - string-length($ext))"/>
   </xsl:template>
   
  +<!-- Normalized (..'s eliminated) version of 'path-noext' -->
  +<xsl:template name="path-noext-nz">
  +  <xsl:param name="path" />
  +  <xsl:call-template name="normalize">
  +    <xsl:with-param name="path">
  +      <xsl:call-template name="path-noext">
  +        <xsl:with-param name="path" select="$path" />
  +      </xsl:call-template>
  +    </xsl:with-param>
  +  </xsl:call-template>
  +</xsl:template>
  +
  +
  +<!-- Normalizes a path, converting '/' to '\' and eliminating ..'s
  +Examples:
  +'foo/bar/../baz/index.html' -> foo/baz/index.html'
  +-->
  +<xsl:template name="normalize">
  +  <xsl:param name="path"/>
  +  <xsl:variable name="path-" select="translate($path, '\', '/')"/>
  +  <xsl:choose>
  +    <xsl:when test="contains($path-, '/../')">
  +
  +      <xsl:variable name="pa" select="substring-before($path-, '/../')"/>
  +      <xsl:variable name="th" select="substring-after($path-, '/../')"/>
  +      <xsl:variable name="pa-">
  +        <xsl:call-template name="dirname">
  +          <xsl:with-param name="path" select="$pa"/>
  +        </xsl:call-template>
  +      </xsl:variable>
  +      <xsl:variable name="pa-th" select="concat($pa-, $th)"/>
  +      <xsl:call-template name="normalize">
  +        <xsl:with-param name="path" select="$pa-th"/>
  +      </xsl:call-template>
  +    </xsl:when>
  +
  +    <xsl:otherwise>
  +      <xsl:value-of select="$path-"/>
  +    </xsl:otherwise>
  +  </xsl:choose>
  +
  +</xsl:template>
  +
   <!--
   Uncomment this to test.
   Usage: saxon pathutils.xsl pathutils.xsl path=foo/bar
   
  -<xsl:param name="path" select="'/foo/bar/index.html'"/>
  +<xsl:param name="path" select="'/foo/bar/../baz/index.html'"/>
   <xsl:template match="/">
     <xsl:message>
  -    path= <xsl:value-of select="$path"/>
  -    dirname= <xsl:call-template name="dirname">
  +    path           = <xsl:value-of select="$path"/>
  +    normalize      = <xsl:call-template name="normalize">
  +      <xsl:with-param name="path" select="$path"/>
  +    </xsl:call-template>
  +    dirname        = <xsl:call-template name="dirname">
  +      <xsl:with-param name="path" select="$path"/>
  +    </xsl:call-template>
  +    dirname-nz     = <xsl:call-template name="dirname-nz">
  +      <xsl:with-param name="path" select="$path"/>
  +    </xsl:call-template>
  +    filename       = <xsl:call-template name="filename">
         <xsl:with-param name="path" select="$path"/>
       </xsl:call-template>
  -    filename= <xsl:call-template name="filename">
  +    ext            = <xsl:call-template name="ext">
         <xsl:with-param name="path" select="$path"/>
       </xsl:call-template>
  -    ext= <xsl:call-template name="ext">
  +    filename-noext = <xsl:call-template name="filename-noext">
         <xsl:with-param name="path" select="$path"/>
       </xsl:call-template>
  -    filename-noext= <xsl:call-template name="filename-noext">
  +    path-noext     = <xsl:call-template name="path-noext">
         <xsl:with-param name="path" select="$path"/>
       </xsl:call-template>
  -    path-noext= <xsl:call-template name="path-noext">
  +    path-noext-nz  = <xsl:call-template name="path-noext-nz">
         <xsl:with-param name="path" select="$path"/>
       </xsl:call-template>
     </xsl:message>