Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
blob: 53a3195920b407919e1105fbda5f8a1ac06ee30e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  Additional functionality provided by dslc

  XSL does not provide every feature suitable for compilation (which is no
  suprise, since this was not its intended use case). As such, dslc provides
  additional features that are defined/abstracted within this file; every
  template that is intended for use with dslc should include this.
-->
<xsl:stylesheet version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<!--
  Package source path, stripped of its extension

  XSL does not provide a means of exposing the file path (nor should it,
  really). This param will hold the source path of the package, sans its
  extension, relative to the project root that was used during compilation.

  I.e., given this source path:
    suppliers/common/foo.xml
  we would expect this value for __srcpkg:
    suppliers/common/foo

  By stripping the extension, we have the benefit of being void of any semantics
  that may be associated with it (e.g. xml vs xmlo vs xmle); rather, that
  information should be derived from the structe of the document itself and the
  path can be used as an identifier to describe the document as a whole,
  regardless of what form it is in.

  Consequently, no two files are able to have the same __srcpkg string; this
  value may therefore be used for disambiguation.
-->
<xsl:param name="__srcpkg" />


<!--
  Relative path to project root

  The project root is determined entirely by __srcpath by repeating the string
  "../" for the number of occurrances of "/".
-->
<xsl:param name="__relroot" />


<!--
  Random value that may be used to seed random values

  XSLT is deterministic and does not offer support for generating random values;
  its generate-id() function is not sufficient for cross-package generation.
-->
<xsl:param name="__rseed" />


<!--
  Root node of template on which stylesheet was invoked

  This points to the original, unprocessed document. This is especially
  important for `document' function calls, which use nodes as a reference
  point for resolving relative paths.
-->
<xsl:variable name="__entry-root" select="/" />



<!--
  Apply relative root to PATH

  If PATH is an absolute path, it will be prefixed with the relative root
  with the leading path delimiter stripped; otherwise, it will be echoed
  as-is.
-->
<xsl:template name="__apply-relroot">
  <xsl:param name="path" />

  <xsl:choose>
    <xsl:when test="starts-with( $path, '/' )">
      <xsl:value-of select="$__relroot" />
      <xsl:value-of select="substring-after( $path, '/' )" />
    </xsl:when>

    <xsl:otherwise>
      <xsl:value-of select="$path" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>