]> git.draconx.ca Git - homepage.git/blob - layouts/functions.xsl
cdfb4829fc69fc11d20f7ffcec947260c1004164
[homepage.git] / layouts / functions.xsl
1 <!--
2   Nick's web site: XSLT helper functions.
3
4   Copyright © 2019 Nick Bowler
5
6   This program is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program.  If not, see <https://www.gnu.org/licenses/>
18 -->
19 <xsl:stylesheet version='1.0'
20   xmlns:xhtml='http://www.w3.org/1999/xhtml'
21   xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
22   xmlns:func='http://exslt.org/functions'
23   xmlns:f='http://draconx.ca/my-functions'
24   extension-element-prefixes='func f'>
25
26 <!-- Returns true iff the given element is an XHTML span-level element -->
27 <func:function name='f:element-is-span'>
28   <xsl:param name='node' select='.' />
29   <func:result select='$node/self::xhtml:a
30                     or $node/self::xhtml:abbr
31                     or $node/self::xhtml:acronym
32                     or $node/self::xhtml:b
33                     or $node/self::xhtml:bdo
34                     or $node/self::xhtml:big
35                     or $node/self::xhtml:br
36                     or $node/self::xhtml:button
37                     or $node/self::xhtml:cite
38                     or $node/self::xhtml:code
39                     or $node/self::xhtml:dfn
40                     or $node/self::xhtml:em
41                     or $node/self::xhtml:i
42                     or $node/self::xhtml:img
43                     or $node/self::xhtml:input
44                     or $node/self::xhtml:kbd
45                     or $node/self::xhtml:label
46                     or $node/self::xhtml:map
47                     or $node/self::xhtml:object
48                     or $node/self::xhtml:q
49                     or $node/self::xhtml:samp
50                     or $node/self::xhtml:script
51                     or $node/self::xhtml:select
52                     or $node/self::xhtml:small
53                     or $node/self::xhtml:span
54                     or $node/self::xhtml:strong
55                     or $node/self::xhtml:sub
56                     or $node/self::xhtml:sup
57                     or $node/self::xhtml:textarea
58                     or $node/self::xhtml:time
59                     or $node/self::xhtml:tt
60                     or $node/self::xhtml:var' />
61 </func:function>
62
63 <!-- Returns true iff the node is a nonempty text node or a span element -->
64 <func:function name='f:node-is-span'>
65   <xsl:param name='node' select='.' />
66   <func:result test='( $node/self::text() and normalize-text($node) )
67                      or f:element-is-span($node)' />
68 </func:function>
69
70 </xsl:stylesheet>