| 1 |
<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- --> |
| 2 |
<!-- |
| 3 |
This program is free software; you can redistribute it and/or modify it under |
| 4 |
the terms of the GNU Lesser General Public License as published by the Free |
| 5 |
Software Foundation; either version 2 of the License, or (at your option) any |
| 6 |
later version. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 10 |
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 11 |
details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU Lesser General Public License |
| 14 |
along with this program; see the file COPYING.LGPL. If not, see |
| 15 |
<http://www.gnu.org/licenses/>. |
| 16 |
--> |
| 17 |
|
| 18 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 19 |
xmlns:dyn="http://exslt.org/dynamic" |
| 20 |
xmlns:str="http://exslt.org/strings" |
| 21 |
exclude-result-prefixes="dyn str" |
| 22 |
version="1.0"> |
| 23 |
|
| 24 |
<!--!!========================================================================== |
| 25 |
Text Templates |
| 26 |
Perform simple substitutions in text files. |
| 27 |
@revision[version=40 date=2020-10-16 status=final] |
| 28 |
|
| 29 |
This stylesheet contains templates to perform simple substitutions on text |
| 30 |
and files containing text. The primary purpose of these templates is to allow |
| 31 |
CSS and JavaScript to be maintained in separate files outside the XSLT, but |
| 32 |
still allow those files to reference variables for things like color themes |
| 33 |
and text directionality. |
| 34 |
|
| 35 |
The substitution evaluates anything between `{{` and `}}`. Usually, this will |
| 36 |
be a reference to a parameter or variable, but it can be any XPath expression. |
| 37 |
For example, `{{$color.fg}}` will be replaced with the primary text color. |
| 38 |
|
| 39 |
This syntax is similar to XSLT attribute value templates, except that it uses |
| 40 |
double curly braces to avoid conflicts with the many curly braces used in CSS |
| 41 |
and JavaScript files. |
| 42 |
|
| 43 |
[note .plain] |
| 44 |
This stylesheet was added in version 40. |
| 45 |
--> |
| 46 |
|
| 47 |
|
| 48 |
<!--**========================================================================== |
| 49 |
tmpl.file |
| 50 |
Perform text substitutions on a file. |
| 51 |
@revision[version=40 date=2020-10-16 status=final] |
| 52 |
|
| 53 |
[xsl:params] |
| 54 |
$file: The filename of the file to process for substitutions. |
| 55 |
$node: The node to create CSS for. |
| 56 |
$direction: The directionality of the text, either `ltr` or `rtl`. |
| 57 |
$left: The starting alignment, either `left` or `right`. |
| 58 |
$right: The ending alignment, either `left` or `right`. |
| 59 |
|
| 60 |
This template reads the file specified by the $file parameter and performs |
| 61 |
text substitutions. Due to XSLT limitations, the file must be a well-formed |
| 62 |
XML document. However, this template simply takes the string value of the |
| 63 |
document, so it is sufficient to wrap the text in a dummy element and ensure |
| 64 |
any `<` and `&` characters are escaped. |
| 65 |
|
| 66 |
See {tmpl} for information on the substitution syntax. |
| 67 |
|
| 68 |
[note .plain] |
| 69 |
This template was added in version 40. |
| 70 |
--> |
| 71 |
<xsl:template name="tmpl.file"> |
| 72 |
<xsl:param name="file"/> |
| 73 |
<xsl:param name="node" select="."/> |
| 74 |
<xsl:param name="direction"> |
| 75 |
<xsl:call-template name="l10n.direction"> |
| 76 |
<xsl:with-param name="node" select="$node"/> |
| 77 |
</xsl:call-template> |
| 78 |
</xsl:param> |
| 79 |
<xsl:param name="left"> |
| 80 |
<xsl:call-template name="l10n.align.start"> |
| 81 |
<xsl:with-param name="direction" select="$direction"/> |
| 82 |
</xsl:call-template> |
| 83 |
</xsl:param> |
| 84 |
<xsl:param name="right"> |
| 85 |
<xsl:call-template name="l10n.align.end"> |
| 86 |
<xsl:with-param name="direction" select="$direction"/> |
| 87 |
</xsl:call-template> |
| 88 |
</xsl:param> |
| 89 |
|
| 90 |
<xsl:for-each select="document($file)"> |
| 91 |
<xsl:call-template name="tmpl.text"> |
| 92 |
<xsl:with-param name="text" select="string(.)"/> |
| 93 |
<xsl:with-param name="node" select="$node"/> |
| 94 |
<xsl:with-param name="direction" select="$direction"/> |
| 95 |
<xsl:with-param name="left" select="$left"/> |
| 96 |
<xsl:with-param name="right" select="$right"/> |
| 97 |
</xsl:call-template> |
| 98 |
</xsl:for-each> |
| 99 |
</xsl:template> |
| 100 |
|
| 101 |
|
| 102 |
<!--**========================================================================== |
| 103 |
tmpl.text |
| 104 |
Perform text substitutions on some text. |
| 105 |
@revision[version=40 date=2020-10-16 status=final] |
| 106 |
|
| 107 |
[xsl:params] |
| 108 |
$text: The text to process for substitutions. |
| 109 |
$node: The node to create CSS for. |
| 110 |
$direction: The directionality of the text, either `ltr` or `rtl`. |
| 111 |
$left: The starting alignment, either `left` or `right`. |
| 112 |
$right: The ending alignment, either `left` or `right`. |
| 113 |
|
| 114 |
This template performs text substitutions on the text in $text. It is called |
| 115 |
by {tmpl.file}, and it calls itself recursively after each substitution. |
| 116 |
|
| 117 |
See {tmpl} for information on the substitution syntax. |
| 118 |
|
| 119 |
[note .plain] |
| 120 |
This template was added in version 40. |
| 121 |
--> |
| 122 |
<xsl:template name="tmpl.text"> |
| 123 |
<xsl:param name="text" select="''"/> |
| 124 |
<xsl:param name="node" select="."/> |
| 125 |
<xsl:param name="direction"> |
| 126 |
<xsl:call-template name="l10n.direction"/> |
| 127 |
</xsl:param> |
| 128 |
<xsl:param name="left"> |
| 129 |
<xsl:call-template name="l10n.align.start"> |
| 130 |
<xsl:with-param name="direction" select="$direction"/> |
| 131 |
</xsl:call-template> |
| 132 |
</xsl:param> |
| 133 |
<xsl:param name="right"> |
| 134 |
<xsl:call-template name="l10n.align.end"> |
| 135 |
<xsl:with-param name="direction" select="$direction"/> |
| 136 |
</xsl:call-template> |
| 137 |
</xsl:param> |
| 138 |
<xsl:choose> |
| 139 |
<xsl:when test="contains($text, '{{')"> |
| 140 |
<xsl:variable name="aft" select="substring-after($text, '{{')"/> |
| 141 |
<xsl:choose> |
| 142 |
<xsl:when test="contains($aft, '}}')"> |
| 143 |
<xsl:value-of select="substring-before($text, '{{')"/> |
| 144 |
<xsl:value-of select="dyn:evaluate(substring-before($aft, '}}'))"/> |
| 145 |
<xsl:call-template name="tmpl.text"> |
| 146 |
<xsl:with-param name="text" select="substring-after($aft, '}}')"/> |
| 147 |
<xsl:with-param name="node" select="$node"/> |
| 148 |
<xsl:with-param name="direction" select="$direction"/> |
| 149 |
<xsl:with-param name="left" select="$left"/> |
| 150 |
<xsl:with-param name="right" select="$right"/> |
| 151 |
</xsl:call-template> |
| 152 |
</xsl:when> |
| 153 |
<xsl:otherwise> |
| 154 |
<xsl:value-of select="$text"/> |
| 155 |
</xsl:otherwise> |
| 156 |
</xsl:choose> |
| 157 |
</xsl:when> |
| 158 |
<xsl:otherwise> |
| 159 |
<xsl:value-of select="$text"/> |
| 160 |
</xsl:otherwise> |
| 161 |
</xsl:choose> |
| 162 |
</xsl:template> |
| 163 |
|
| 164 |
</xsl:stylesheet> |