emoji-catalog/resources/xslt/emoji.xsl
jawira 5f5971badb Added docblock to Emoji class #2
Builfile wasn't improved as requested by ticket,
however Emoji class has docblock with more details
about Emoji.
2019-09-30 23:14:58 +02:00

117 lines
4.3 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="2.0" encoding="UTF-8" indent="no"/>
<xsl:template match="/">
<xsl:for-each select="//table//tr[./td//img]">
<xsl:text> /**&#10;</xsl:text>
<xsl:text> * </xsl:text>
<xsl:call-template name="get-name"/>
<xsl:text>&#10;</xsl:text>
<xsl:text> *&#10;</xsl:text>
<xsl:text> * Code point(s): </xsl:text>
<xsl:call-template name="get-code"/>
<xsl:text>&#10;</xsl:text>
<xsl:text> */&#10;</xsl:text>
<xsl:text> const </xsl:text>
<xsl:call-template name="get-constant-name"/>
<xsl:text> = "</xsl:text>
<xsl:call-template name="get-alt"/>
<xsl:text>";&#10;&#10;</xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template name="get-code">
<xsl:value-of select="./td[2]//a/text()"/>
</xsl:template>
<xsl:template name="get-name">
<xsl:variable name="short-name" select="./td[last()]/text()"/>
<xsl:variable name="removable" select="'⊛⊖'"/>
<xsl:variable name="cleaned" select="translate($short-name, $removable, '')"/>
<xsl:value-of select="normalize-space($cleaned)"/>
</xsl:template>
<xsl:template name="get-alt">
<xsl:value-of select="./td[3]/text()"/>
</xsl:template>
<xsl:template name="get-constant-name">
<xsl:variable name="short-name" select="./td[last()]/text()"/>
<xsl:variable name="removable" select="':;.,⊛’!“”()⊖'"/>
<xsl:variable name="cleaned" select="translate($short-name, $removable, '')"/>
<xsl:variable name="lowercase" select="'Åãabcçdeéfghíijklmnoôpqrstuvwxyz-&amp;'"/>
<xsl:variable name="uppercase" select="'AAABCCDEEFGHIIJKLMNOOPQRSTUVWXYZ N'"/>
<xsl:variable name="no-accents" select="translate($cleaned, $lowercase, $uppercase)"/>
<xsl:variable name="normalized" select="normalize-space($no-accents)"/>
<xsl:variable name="no-spaces" select="translate($normalized, ' ', '_')"/>
<xsl:variable name="no-1st">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$no-spaces"/>
<xsl:with-param name="replace" select="'1ST'"/>
<xsl:with-param name="by" select="'FIRST'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="no-2nd">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$no-1st"/>
<xsl:with-param name="replace" select="'2ND'"/>
<xsl:with-param name="by" select="'SECOND'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="no-3rd">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$no-2nd"/>
<xsl:with-param name="replace" select="'3RD'"/>
<xsl:with-param name="by" select="'THIRD'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="no-number">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$no-3rd"/>
<xsl:with-param name="replace" select="'#'"/>
<xsl:with-param name="by" select="'NUMBER'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="no-asterisk">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$no-number"/>
<xsl:with-param name="replace" select="'*'"/>
<xsl:with-param name="by" select="'ASTERISK'"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$no-asterisk"/>
</xsl:template>
<!-- http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx -->
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>