summaryrefslogtreecommitdiff
path: root/xslt
diff options
context:
space:
mode:
authorShaun McCance <shaunm@gnome.org>2011-05-31 09:36:03 -0400
committerShaun McCance <shaunm@gnome.org>2011-05-31 09:36:03 -0400
commite9fc5a765f7c5ecd74b364106316588e15ce4590 (patch)
tree813f05a372539ecf80155b608aa14dd5479fae03 /xslt
parent322c23b00349b3113ba75c3160aa62890ba61115 (diff)
downloadyelp-tools-e9fc5a765f7c5ecd74b364106316588e15ce4590.tar.gz
yelp-check: Adding comments subcommand for M and D
Diffstat (limited to 'xslt')
-rw-r--r--xslt/Makefile.am1
-rw-r--r--xslt/comments.xsl120
2 files changed, 121 insertions, 0 deletions
diff --git a/xslt/Makefile.am b/xslt/Makefile.am
index 4d4aa7c..2c26e6d 100644
--- a/xslt/Makefile.am
+++ b/xslt/Makefile.am
@@ -1,6 +1,7 @@
xsldir=$(datadir)/yelp-tools/xslt
xsl_DATA = \
+ comments.xsl \
mal-epub.xsl \
mal-opf.xsl \
mal-ncx.xsl \
diff --git a/xslt/comments.xsl b/xslt/comments.xsl
new file mode 100644
index 0000000..61e1cdb
--- /dev/null
+++ b/xslt/comments.xsl
@@ -0,0 +1,120 @@
+<xsl:stylesheet
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:mal="http://projectmallard.org/1.0/"
+ xmlns:db="http://docbook.org/ns/docbook"
+ exclude-result-prefixes="mal db"
+ version="1.0">
+
+<xsl:output method="text"/>
+
+<xsl:param name="basename"/>
+
+<xsl:template match="/*[namespace-uri(.) = ''] | /db:*">
+ <xsl:for-each select="//remark | //db:remark">
+ <xsl:text>Page: </xsl:text>
+ <xsl:value-of select="$basename"/>
+ <xsl:if test="ancestor::*/@id | ancestor::*/@xml:id">
+ <xsl:text>#</xsl:text>
+ <xsl:value-of select="(ancestor::*/@id | ancestor::*/@xml:id)[last()]"/>
+ </xsl:if>
+ <xsl:text>&#x000A;</xsl:text>
+ <xsl:if test="@revisionflag">
+ <xsl:text>Flag: </xsl:text>
+ <xsl:value-of select="@revisionflag"/>
+ <xsl:text>&#x000A;</xsl:text>
+ </xsl:if>
+ <xsl:text>&#x000A;</xsl:text>
+ <xsl:call-template name="fill">
+ <xsl:with-param name="text" select="normalize-space(.)"/>
+ <xsl:with-param name="pad" select="' '"/>
+ </xsl:call-template>
+ <xsl:text>&#x000A;</xsl:text>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="/mal:page">
+ <xsl:for-each select="//mal:comment">
+ <xsl:variable name="id">
+ <xsl:value-of select="/mal:page/@id"/>
+ <xsl:if test="ancestor::mal:section[1]/@id">
+ <xsl:text>#</xsl:text>
+ <xsl:value-of select="ancestor::mal:section[1]/@id"/>
+ </xsl:if>
+ </xsl:variable>
+ <xsl:text>Page: </xsl:text>
+ <xsl:value-of select="$id"/>
+ <xsl:text>&#x000A;</xsl:text>
+ <xsl:if test="mal:cite">
+ <xsl:text>From: </xsl:text>
+ <xsl:value-of select="mal:cite[1]"/>
+ <xsl:if test="starts-with(mal:cite[1]/@href, 'mailto:')">
+ <xsl:text> &lt;</xsl:text>
+ <xsl:value-of select="substring-after(mal:cite[1]/@href, 'mailto:')"/>
+ <xsl:text>&gt;</xsl:text>
+ </xsl:if>
+ <xsl:text>&#x000A;</xsl:text>
+ <xsl:if test="mal:cite[1]/@date">
+ <xsl:text>Date: </xsl:text>
+ <xsl:value-of select="mal:cite[1]/@date"/>
+ <xsl:text>&#x000A;</xsl:text>
+ </xsl:if>
+ </xsl:if>
+ <xsl:text>&#x000A;</xsl:text>
+ <xsl:for-each select="*[not(self::mal:cite)]">
+ <xsl:choose>
+ <xsl:when test="self::mal:p">
+ <xsl:call-template name="fill">
+ <xsl:with-param name="text" select="normalize-space(.)"/>
+ <xsl:with-param name="pad" select="' '"/>
+ </xsl:call-template>
+ <xsl:text>&#x000A;</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text> FIXME: &lt;</xsl:text>
+ <xsl:value-of select="local-name(.)"/>
+ <xsl:text>&gt;>...&lt;/</xsl:text>
+ <xsl:value-of select="local-name(.)"/>
+ <xsl:text>&gt;</xsl:text>
+ <xsl:text>&#x000A;&#x000A;</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:if test="not(*[not(self::mal:cite)])">
+ <xsl:text>&#x000A;&#x000A;</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template name="fill">
+ <xsl:param name="text" select="''"/>
+ <xsl:param name="pad" select="''"/>
+ <xsl:param name="end" select="80 - string-length($pad)"/>
+ <xsl:param name="col" select="$end"/>
+ <xsl:choose>
+ <xsl:when test="$col &gt; string-length($text)">
+ <xsl:value-of select="$pad"/>
+ <xsl:value-of select="$text"/>
+ <xsl:text>&#x000A;</xsl:text>
+ </xsl:when>
+ <xsl:when test="substring($text, $col, 1) = ' '">
+ <xsl:value-of select="$pad"/>
+ <xsl:value-of select="substring($text, 0, $col)"/>
+ <xsl:text>&#x000A;</xsl:text>
+ <xsl:call-template name="fill">
+ <xsl:with-param name="text" select="substring($text, $col + 1)"/>
+ <xsl:with-param name="end" select="$end"/>
+ <xsl:with-param name="pad" select="$pad"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="fill">
+ <xsl:with-param name="text" select="$text"/>
+ <xsl:with-param name="end" select="$end"/>
+ <xsl:with-param name="pad" select="$pad"/>
+ <xsl:with-param name="col" select="$col - 1"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>