<!--
Nick's web site: XSLT helper functions.
- Copyright © 2019 Nick Bowler
+ Copyright © 2019-2020 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
</xsl:choose>
</func:function>
+<!--
+ Convert the given node to a string containing an XHTML listing for that node.
+-->
+<func:function name='f:xhtml-listing'>
+ <xsl:param name='nodeset' select='.' />
+ <xsl:variable name='node' select='$nodeset[1]' />
+
+ <func:result>
+ <xsl:choose>
+ <xsl:when test='$node/self::text()'>
+ <!-- text node -->
+ <xsl:value-of select='$node' />
+ </xsl:when>
+ <xsl:when test='$node/self::comment()'>
+ <!-- comment node -->
+ <xsl:value-of select='concat("<!--", $node, "-->")' />
+ </xsl:when>
+ <xsl:when test='$node/self::*'>
+ <!-- element node -->
+ <xsl:value-of select='concat("<", local-name($node))' />
+ <xsl:value-of select='f:xhtml-listing($node/@*)' />
+ <xsl:if test='not($node/node())'>/</xsl:if>
+ <xsl:value-of select='concat(">", f:xhtml-listing($node/node()))' />
+ <xsl:if test='$node/node()'>
+ <xsl:value-of select='concat("</", local-name($node), ">")' />
+ </xsl:if>
+ </xsl:when>
+ <xsl:when test='$node'>
+ <!-- attribute node -->
+ <xsl:value-of select='concat(" ", local-name($node), "=")' />
+ <xsl:value-of select='concat("'", $node, "'")' />
+ </xsl:when>
+ </xsl:choose>
+ <xsl:for-each select='$nodeset[position()>1]'>
+ <xsl:value-of select='f:xhtml-listing()' />
+ </xsl:for-each>
+ </func:result>
+</func:function>
+
</xsl:stylesheet>