diff options
author | Shaun McCance <shaunm@gnome.org> | 2014-01-29 13:21:52 -0500 |
---|---|---|
committer | Shaun McCance <shaunm@gnome.org> | 2014-01-29 13:21:52 -0500 |
commit | 34c6ceca3967fd845b8a42f4fe54309073273d4b (patch) | |
tree | 89178c92201e8bbc5deed99b584721a67f2cc637 /xslt | |
parent | 5ba2a0d240b84ac66a386b06bdcc21fc3101c68c (diff) | |
download | yelp-tools-34c6ceca3967fd845b8a42f4fe54309073273d4b.tar.gz |
yelp-check: Added tool to check Mallard page licenses
Diffstat (limited to 'xslt')
-rw-r--r-- | xslt/Makefile.am | 1 | ||||
-rw-r--r-- | xslt/mal-license.xsl | 102 |
2 files changed, 103 insertions, 0 deletions
diff --git a/xslt/Makefile.am b/xslt/Makefile.am index 5dd0ef4..d2dc1e3 100644 --- a/xslt/Makefile.am +++ b/xslt/Makefile.am @@ -5,6 +5,7 @@ xsl_DATA = \ mal-epub.xsl \ mal-opf.xsl \ mal-files.xsl \ + mal-license.xsl \ mal-ncx.xsl \ mal-status.xsl \ mal-rng.xsl diff --git a/xslt/mal-license.xsl b/xslt/mal-license.xsl new file mode 100644 index 0000000..cf3a98d --- /dev/null +++ b/xslt/mal-license.xsl @@ -0,0 +1,102 @@ +<xsl:stylesheet + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:mal="http://projectmallard.org/1.0/" + xmlns:str="http://exslt.org/strings" + xmlns:exsl="http://exslt.org/common" + version="1.0"> + +<xsl:output method="text"/> + +<xsl:param name="only" select="''"/> +<xsl:variable name="only_" select="concat(' ', translate($only, ',', ' '), ' ')"/> +<xsl:param name="except" select="''"/> +<xsl:variable name="except_" select="concat(' ', translate($except, ',', ' '), ' ')"/> +<xsl:param name="totals" select="''"/> + +<xsl:template match="/"> + <xsl:variable name="idents"> + <xsl:if test="not(/mal:page/mal:info/mal:license)"> + <ident>none</ident> + </xsl:if> + <xsl:for-each select="/mal:page/mal:info/mal:license"> + <ident> + <xsl:call-template name="license.identifier"/> + </ident> + </xsl:for-each> + </xsl:variable> + <xsl:variable name="display"> + <xsl:for-each select="exsl:node-set($idents)/*"> + <xsl:choose> + <xsl:when test="$only != ''"> + <xsl:if test="contains($only_, concat(' ', ., ' '))"> + <xsl:text>1</xsl:text> + </xsl:if> + </xsl:when> + <xsl:when test="$except != ''"> + <xsl:if test="not(contains($except_, concat(' ', ., ' ')))"> + <xsl:text>1</xsl:text> + </xsl:if> + </xsl:when> + <xsl:otherwise> + <xsl:text>1</xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> + </xsl:variable> + <xsl:if test="$display != ''"> + <xsl:choose> + <xsl:when test="$totals = ''"> + <xsl:value-of select="concat(/mal:page/@id, ': ')"/> + <xsl:for-each select="exsl:node-set($idents)/*"> + <xsl:if test="position() != 1"> + <xsl:text>, </xsl:text> + </xsl:if> + <xsl:value-of select="."/> + </xsl:for-each> + <xsl:text>
</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:for-each select="exsl:node-set($idents)/*"> + <xsl:value-of select="."/> + <xsl:text>
</xsl:text> + </xsl:for-each> + </xsl:otherwise> + </xsl:choose> + </xsl:if> +</xsl:template> + +<xsl:template name="license.identifier"> + <xsl:param name="href" select="@href"/> + <xsl:choose> + <xsl:when test="$href = ''"> + <xsl:text>unknown</xsl:text> + </xsl:when> + <xsl:when test="starts-with($href, 'http://creativecommons.org/licenses/')"> + <xsl:text>cc-</xsl:text> + <xsl:for-each select="str:split(substring-after($href, 'http://creativecommons.org/licenses/'), '/')"> + <xsl:if test="position() != 1"> + <xsl:text>-</xsl:text> + </xsl:if> + <xsl:value-of select="."/> + </xsl:for-each> + </xsl:when> + <xsl:when test="starts-with($href, 'http://www.gnu.org/licenses/')"> + <xsl:variable name="basename"> + <xsl:value-of select="substring-after($href, 'http://www.gnu.org/licenses/')"/> + </xsl:variable> + <xsl:choose> + <xsl:when test="substring($basename, string-length($basename) - 4) = '.html'"> + <xsl:value-of select="substring($basename, 1, string-length($basename) - 5)"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$basename"/> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:otherwise> + <xsl:text>unknown</xsl:text> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +</xsl:stylesheet> |