3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
19 Some callable templates useful when dealing with tab paths. Mostly used in
22 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
23 <xsl:param name="site-file" select="'cocoon://abs-menulinks'"/>
24 <xsl:variable name="site" select="document($site-file)"/>
25 <!-- Given the current path and a tabs.xml entry, returns a relative path to
26 the specified tab's URL. When rendering a set of tabs, this template will be
29 <xsl:template name="calculate-tab-href">
30 <xsl:param name="dir_index" select="'index.html'"/>
31 <xsl:param name="tab"/>
32 <!-- current 'tab' node -->
33 <xsl:param name="path" select="$path"/>
34 <xsl:if test="starts-with($tab/@href, 'http')">
36 <xsl:value-of select="$tab/@href"/>
38 <xsl:if test="not(starts-with($tab/@href, 'http'))">
39 <!-- Root-relative path -->
40 <xsl:variable name="backpath">
41 <xsl:call-template name="dotdots">
42 <xsl:with-param name="path" select="$path"/>
44 <xsl:text>/</xsl:text>
45 <xsl:value-of select="$tab/@dir | $tab/@href"/>
46 <!-- If we obviously have a directory, add /index.html -->
47 <xsl:if test="$tab/@dir or substring($tab/@href, string-length($tab/@href),
48 string-length($tab/@href)) = '/'">
49 <xsl:text>/</xsl:text>
50 <xsl:if test="$tab/@indexfile">
51 <xsl:value-of select="$tab/@indexfile"/>
53 <xsl:if test="not(@indexfile)">
54 <xsl:value-of select="$dir_index"/>
59 select="translate(normalize-space(translate($backpath, ' /', '/ ')), ' /', '/ ')"/>
60 <!-- Link to backpath, normalizing slashes -->
64 The id of any tab, whose path is a subset of the current URL. Ie,
65 the path of the 'current' tab.
67 <xsl:template name="matching-id" xmlns:l="http://apache.org/forrest/linkmap/1.0">
68 <xsl:value-of select="$site//*[starts-with(@href, $path)]/@tab"/>
71 The longest path of any level 1 tab, whose path is a subset of the current URL. Ie,
72 the path of the 'current' tab.
74 <xsl:template name="longest-dir">
75 <xsl:param name="tabfile"/>
76 <xsl:for-each select="$tabfile/tabs/tab[starts-with($path, @dir|@href)]">
77 <xsl:sort select="string-length(@dir|@href)"
78 data-type="number" order="descending"/>
79 <xsl:if test="position()=1">
80 <xsl:value-of select="@dir|@href"/>
85 The longest path of any level 2 tab, whose path is a subset of the current URL. Ie,
86 the path of the 'current' tab.
88 <xsl:template name="level2-longest-dir">
89 <xsl:param name="tabfile"/>
90 <xsl:for-each select="$tabfile/tabs/tab/tab[starts-with($path, @dir|@href)]">
91 <xsl:sort select="string-length(@dir|@href)"
92 data-type="number" order="descending"/>
93 <xsl:if test="position()=1">
94 <xsl:value-of select="@dir|@href"/>