pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / site / src / documentation / skins / common / xslt / html / dotdots.xsl
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
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
9
10       http://www.apache.org/licenses/LICENSE-2.0
11
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.
17 -->
18 <!--
19 Contains the 'dotdots' template, which, given a path, will output a set of
20 directory traversals to get back to the source directory. Handles both '/' and
21 '\' directory separators.
22
23 Examples:
24   Input                           Output 
25     index.html                    ""
26     dir/index.html                "../"
27     dir/subdir/index.html         "../../"
28     dir//index.html              "../"
29     dir/                          "../"
30     dir//                         "../"
31     \some\windows\path            "../../"
32     \some\windows\path\           "../../../"
33     \Program Files\mydir          "../"
34
35 Cannot handle ..'s in the path, so don't expect 'dir/subdir/../index.html' to
36 work.
37
38 -->
39 <xsl:stylesheet
40   version="1.0"
41   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
42   <xsl:template name="dotdots">
43     <xsl:param name="path"/>
44     <xsl:variable name="dirs" select="normalize-space(translate(concat($path, 'x'), ' /\', '_  '))"/>
45 <!-- The above does the following:
46        o Adds a trailing character to the path. This prevents us having to deal
47          with the special case of ending with '/'
48        o Translates all directory separators to ' ', and normalize spaces,
49                  cunningly eliminating duplicate '//'s. We also translate any real
50                  spaces into _ to preserve them.
51     -->
52     <xsl:variable name="remainder" select="substring-after($dirs, ' ')"/>
53     <xsl:if test="$remainder">
54 <xsl:text>../</xsl:text>
55       <xsl:call-template name="dotdots">
56         <xsl:with-param name="path" select="translate($remainder, ' ', '/')"/>
57 <!-- Translate back to /'s because that's what the template expects. -->
58       </xsl:call-template>
59     </xsl:if>
60   </xsl:template>
61 <!--
62   Uncomment to test.
63   Usage: saxon dotdots.xsl dotdots.xsl path='/my/test/path'
64
65   <xsl:param name="path"/>
66   <xsl:template match="/">
67     <xsl:message>Path: <xsl:value-of select="$path"/></xsl:message>
68     <xsl:call-template name="dotdots">
69       <xsl:with-param name="path" select="$path"/>
70     </xsl:call-template>
71   </xsl:template>
72  -->
73 </xsl:stylesheet>