]> git.draconx.ca Git - homepage.git/blobdiff - layouts/functions.xsl
Work around Nokogiri pretty-print issues.
[homepage.git] / layouts / functions.xsl
diff --git a/layouts/functions.xsl b/layouts/functions.xsl
new file mode 100644 (file)
index 0000000..cdfb482
--- /dev/null
@@ -0,0 +1,70 @@
+<!--
+  Nick's web site: XSLT helper functions.
+
+  Copyright © 2019 Nick Bowler
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <https://www.gnu.org/licenses/>
+-->
+<xsl:stylesheet version='1.0'
+  xmlns:xhtml='http://www.w3.org/1999/xhtml'
+  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+  xmlns:func='http://exslt.org/functions'
+  xmlns:f='http://draconx.ca/my-functions'
+  extension-element-prefixes='func f'>
+
+<!-- Returns true iff the given element is an XHTML span-level element -->
+<func:function name='f:element-is-span'>
+  <xsl:param name='node' select='.' />
+  <func:result select='$node/self::xhtml:a
+                    or $node/self::xhtml:abbr
+                    or $node/self::xhtml:acronym
+                    or $node/self::xhtml:b
+                    or $node/self::xhtml:bdo
+                    or $node/self::xhtml:big
+                    or $node/self::xhtml:br
+                    or $node/self::xhtml:button
+                    or $node/self::xhtml:cite
+                    or $node/self::xhtml:code
+                    or $node/self::xhtml:dfn
+                    or $node/self::xhtml:em
+                    or $node/self::xhtml:i
+                    or $node/self::xhtml:img
+                    or $node/self::xhtml:input
+                    or $node/self::xhtml:kbd
+                    or $node/self::xhtml:label
+                    or $node/self::xhtml:map
+                    or $node/self::xhtml:object
+                    or $node/self::xhtml:q
+                    or $node/self::xhtml:samp
+                    or $node/self::xhtml:script
+                    or $node/self::xhtml:select
+                    or $node/self::xhtml:small
+                    or $node/self::xhtml:span
+                    or $node/self::xhtml:strong
+                    or $node/self::xhtml:sub
+                    or $node/self::xhtml:sup
+                    or $node/self::xhtml:textarea
+                    or $node/self::xhtml:time
+                    or $node/self::xhtml:tt
+                    or $node/self::xhtml:var' />
+</func:function>
+
+<!-- Returns true iff the node is a nonempty text node or a span element -->
+<func:function name='f:node-is-span'>
+  <xsl:param name='node' select='.' />
+  <func:result test='( $node/self::text() and normalize-text($node) )
+                     or f:element-is-span($node)' />
+</func:function>
+
+</xsl:stylesheet>