diff options
Diffstat (limited to 'gmi.xslt')
-rw-r--r-- | gmi.xslt | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/gmi.xslt b/gmi.xslt new file mode 100644 index 0000000..d52fab1 --- /dev/null +++ b/gmi.xslt @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xhtml="http://www.w3.org/1999/xhtml"> + <xsl:output method="text" encoding="UTF-8"/> + <xsl:variable name="root">https://loang.net</xsl:variable> + <xsl:template match="text()"> + <xsl:value-of select="normalize-space()"/> + </xsl:template> + + <xsl:template name="link"> + <xsl:for-each select=".//xhtml:a"> + <xsl:text>=> </xsl:text> + <xsl:if test="substring(@href, 1, 1) = '/'"> + <xsl:value-of select="$root"/> + </xsl:if> + <xsl:value-of select="@href"/> + <xsl:text> </xsl:text> + <xsl:value-of select="."/> + <xsl:text> </xsl:text> + </xsl:for-each> + <xsl:text> </xsl:text> + </xsl:template> + + <xsl:template match="xhtml:a"> + <xsl:variable name="pre"> + <xsl:value-of select="preceding::text()[1]"/> + </xsl:variable> + <xsl:choose> + <!-- consecutive anchors --> + <xsl:when test="$pre = ' ' or $pre = ' '"> + <xsl:text> </xsl:text> + </xsl:when> + <!-- whitespace noise --> + <xsl:when test="normalize-space($pre) = ''"/> + <!-- text ending with a whitespace --> + <xsl:when test="substring($pre, string-length($pre), 1) = ' '"> + <xsl:text> </xsl:text> + </xsl:when> + <xsl:when test="substring($pre, string-length($pre), 1) = ' '"> + <xsl:text> </xsl:text> + </xsl:when> + </xsl:choose> + <xsl:value-of select="."/> + <xsl:variable name="suf"> + <xsl:value-of select="substring(following::text()[1], 1, 1)"/> + </xsl:variable> + <xsl:if test="$suf = ' ' or $suf = ' '"> + <xsl:text> </xsl:text> + </xsl:if> + </xsl:template> + + <xsl:template match="xhtml:h1"> + <xsl:text># </xsl:text> + <xsl:value-of select="."/> + <xsl:text> </xsl:text> + </xsl:template> + <xsl:template match="xhtml:h2"> + <xsl:text>## </xsl:text> + <xsl:value-of select="."/> + <xsl:text> </xsl:text> + </xsl:template> + <xsl:template match="xhtml:h3"> + <xsl:text>### </xsl:text> + <xsl:value-of select="."/> + <xsl:text> </xsl:text> + </xsl:template> + + <xsl:template match="xhtml:p"> + <xsl:apply-templates select="text()|*"/> + <xsl:text> </xsl:text> + <xsl:call-template name="link"/> + </xsl:template> + + <xsl:template match="xhtml:li"> + <xsl:text>* </xsl:text> + <xsl:apply-templates select="text()|*"/> + <xsl:text> </xsl:text> + </xsl:template> + <xsl:template match="xhtml:ul"> + <xsl:apply-templates select="*"/> + <xsl:call-template name="link"/> + </xsl:template> + + <xsl:template match="xhtml:head"/> + <xsl:template match="xhtml:body"> + <xsl:apply-templates select="*"/> + </xsl:template> +</xsl:stylesheet> |