diff options
author | Shaun McCance <shaunm@gnome.org> | 2013-11-02 11:07:15 -0400 |
---|---|---|
committer | Shaun McCance <shaunm@gnome.org> | 2013-11-02 11:07:15 -0400 |
commit | 69014c0374ae8acbc0c93b3d43f28264791dca75 (patch) | |
tree | 4059c1283bdd1b6a0fe1486c70be0412cbf50b24 /xslt | |
parent | e414c6afd3f2e20992ad489b07ea512dadd31f81 (diff) | |
download | yelp-tools-69014c0374ae8acbc0c93b3d43f28264791dca75.tar.gz |
yelp-build: Better Mallard templates to determine files to copy
Instead of a second run using a stripped down stylesheet, we now use
the primary stylesheet, which gives us access to the same logic of
which elements to process, including conditional processing.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=709951
Diffstat (limited to 'xslt')
-rw-r--r-- | xslt/Makefile.am | 1 | ||||
-rw-r--r-- | xslt/mal-files.xsl | 249 |
2 files changed, 250 insertions, 0 deletions
diff --git a/xslt/Makefile.am b/xslt/Makefile.am index 2c26e6d..5dd0ef4 100644 --- a/xslt/Makefile.am +++ b/xslt/Makefile.am @@ -4,6 +4,7 @@ xsl_DATA = \ comments.xsl \ mal-epub.xsl \ mal-opf.xsl \ + mal-files.xsl \ mal-ncx.xsl \ mal-status.xsl \ mal-rng.xsl diff --git a/xslt/mal-files.xsl b/xslt/mal-files.xsl new file mode 100644 index 0000000..9ecabe0 --- /dev/null +++ b/xslt/mal-files.xsl @@ -0,0 +1,249 @@ +<xsl:stylesheet + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:mal="http://projectmallard.org/1.0/" + xmlns:if="http://projectmallard.org/if/1.0/" + xmlns:e="http://projectmallard.org/experimental/" + xmlns:exsl="http://exslt.org/common" + xmlns:html="http://www.w3.org/1999/xhtml" + version="1.0"> + +<xsl:param name="mal.files.copy.icon.dir"/> +<xsl:param name="mal.files.copy.js.dir"/> + +<xsl:template name="mal.files.copy"> + <xsl:param name="node" select="."/> + <xsl:param name="href"/> + <xsl:value-of select="concat('+', $mal.files.copy.js.dir, '/jquery.js ./
')"/> + <xsl:value-of select="concat('+', $mal.files.copy.js.dir, '/jquery.syntax.js ./
')"/> + <xsl:value-of select="concat('+', $mal.files.copy.js.dir, '/jquery.syntax.core.js ./
')"/> + <xsl:value-of select="concat('+', $mal.files.copy.js.dir, '/jquery.syntax.layout.yelp.js ./
')"/> + <xsl:apply-templates mode="mal.files.copy.block.mode"> + <xsl:with-param name="dir"> + <xsl:call-template name="mal.files.copy.dirname"> + <xsl:with-param name="href" select="$href"/> + </xsl:call-template> + </xsl:with-param> + </xsl:apply-templates> +</xsl:template> + +<xsl:template name="mal.files.copy.dirname"> + <xsl:param name="href"/> + <xsl:if test="contains($href, '/')"> + <xsl:value-of select="substring-before($href, '/')"/> + <xsl:text>/</xsl:text> + <xsl:call-template name="mal.files.copy.dirname"> + <xsl:with-param name="href" select="substring-after($href, '/')"/> + </xsl:call-template> + </xsl:if> +</xsl:template> + +<xsl:template mode="mal.files.copy.media.mode" match="*"/> + +<xsl:template mode="mal.files.copy.media.mode" match="mal:media | e:mouseover"> + <xsl:param name="dir"/> + <xsl:if test="not(contains(@src, ':') or substring(@src, 1, 1) = '/')"> + <xsl:value-of select="concat('-', $dir, @src, ' ', @src, '
')"/> + </xsl:if> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="text()"/> + +<xsl:template mode="mal.files.copy.block.mode" match="*"> + <xsl:param name="dir"/> + <xsl:param name="restricted" select="false()"/> + <xsl:if test="not($restricted)"> + <xsl:variable name="if"> + <xsl:call-template name="mal.if.test"/> + </xsl:variable> + <xsl:if test="$if != ''"> + <xsl:apply-templates mode="mal.files.copy.block.mode"> + <xsl:with-param name="dir" select="$dir"/> + <xsl:with-param name="restricted" select="true()"/> + </xsl:apply-templates> + </xsl:if> + </xsl:if> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="mal:info"> + <xsl:param name="dir"/> + <xsl:apply-templates mode="mal.files.copy.block.mode" + select="mal:title | mal:desc | mal:license/* | mal:link/* | mal:revision/* | mal:credit"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="mal:p | mal:screen"> + <xsl:param name="dir"/> + <xsl:variable name="if"> + <xsl:call-template name="mal.if.test"/> + </xsl:variable> + <xsl:if test="$if != ''"> + <xsl:apply-templates mode="mal.files.copy.media.mode" select=".//mal:media"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> + </xsl:if> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="mal:title | mal:subtitle | mal:desc | mal:cite | mal:credit"> + <xsl:param name="dir"/> + <xsl:apply-templates mode="mal.files.copy.media.mode" select=".//mal:media"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="mal:code"> + <xsl:param name="dir"/> + <xsl:variable name="if"> + <xsl:call-template name="mal.if.test"/> + </xsl:variable> + <xsl:if test="$if != ''"> + <xsl:apply-templates mode="mal.files.copy.media.mode" select=".//mal:media"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> + <xsl:if test="$html.syntax.highlight and @mime"> + <xsl:variable name="brush"> + <xsl:call-template name="html.syntax.class"/> + </xsl:variable> + <xsl:if test="starts-with($brush, 'syntax brush-')"> + <xsl:value-of select="concat('+', $mal.files.copy.js.dir, '/jquery.syntax.brush.', + substring-after($brush, 'syntax brush-'), '.js ./
')"/> + </xsl:if> + </xsl:if> + </xsl:if> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" + match="mal:example | mal:quote | mal:listing | mal:figure | + mal:synopsis | mal:links | mal:list | mal:steps | + mal:terms | mal:tree | mal:item | mal:table | + mal:section | if:if"> + <xsl:param name="dir"/> + <xsl:variable name="if"> + <xsl:call-template name="mal.if.test"/> + </xsl:variable> + <xsl:if test="$if != ''"> + <xsl:apply-templates mode="mal.files.copy.block.mode"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> + </xsl:if> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="mal:media | e:mouseover"> + <xsl:param name="dir"/> + <xsl:variable name="if"> + <xsl:call-template name="mal.if.test"/> + </xsl:variable> + <xsl:if test="$if != ''"> + <xsl:apply-templates mode="mal.files.copy.media.mode" select="."> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> + </xsl:if> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="mal:comment"> + <xsl:param name="dir"/> + <xsl:variable name="if"> + <xsl:call-template name="mal.if.test"/> + </xsl:variable> + <xsl:if test="$if != ''"> + <xsl:if test="$mal2html.editor_mode + or processing-instruction('mal2html.show_comment')"> + <xsl:apply-templates mode="mal.files.copy.block.mode"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> + </xsl:if> + </xsl:if> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="mal:note"> + <xsl:param name="dir"/> + <xsl:variable name="if"> + <xsl:call-template name="mal.if.test"/> + </xsl:variable> + <xsl:if test="$if != ''"> + <xsl:variable name="style" select="concat(' ', @style, ' ')"/> + <xsl:choose> + <!-- + <xsl:when test="contains($style, ' advanced ')"> + <xsl:value-of select="concat('+', $mal.files.copy.icon.dir, '/yelp-note-advanced.png ./
')"/> + </xsl:when> + --> + <xsl:when test="contains($style, ' bug ')"> + <xsl:value-of select="concat('+', $mal.files.copy.icon.dir, '/yelp-note-bug.png ./
')"/> + </xsl:when> + <xsl:when test="contains($style, ' important ')"> + <xsl:value-of select="concat('+', $mal.files.copy.icon.dir, '/yelp-note-important.png ./
')"/> + </xsl:when> + <xsl:when test="contains($style, ' sidebar ')"/> + <xsl:when test="contains($style, ' tip ')"> + <xsl:value-of select="concat('+', $mal.files.copy.icon.dir, '/yelp-note-tip.png ./
')"/> + </xsl:when> + <xsl:when test="contains($style, ' warning ')"> + <xsl:value-of select="concat('+', $mal.files.copy.icon.dir, '/yelp-note-warning.png ./
')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="concat('+', $mal.files.copy.icon.dir, '/yelp-note.png ./
')"/> + </xsl:otherwise> + </xsl:choose> + <xsl:apply-templates mode="mal.files.copy.block.mode"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> + </xsl:if> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="mal:tr | mal:td"> + <xsl:param name="dir"/> + <xsl:apply-templates mode="mal.files.copy.block.mode"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="if:choose"> + <xsl:param name="dir"/> + <xsl:apply-templates mode="mal.files.copy.block.mode" select="if:when[1]"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="if:when"> + <xsl:param name="dir"/> + <xsl:variable name="if"> + <xsl:call-template name="mal.if.test"/> + </xsl:variable> + <xsl:if test="$if != ''"> + <xsl:apply-templates mode="mal.files.copy.block.mode"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> + </xsl:if> + <xsl:if test="$if != 'true'"> + <xsl:apply-templates mode="mal.files.copy.block.mode" select="following-sibling::*[1]"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> + </xsl:if> +</xsl:template> + +<xsl:template mode="mal.files.copy.block.mode" match="if:else"> + <xsl:param name="dir"/> + <xsl:apply-templates mode="mal.files.copy.block.mode"> + <xsl:with-param name="dir" select="$dir"/> + </xsl:apply-templates> +</xsl:template> + +<xsl:template match="/false"> +<!-- + <xsl:variable name="dir"> + <xsl:call-template name="mal.files.dirname"> + <xsl:with-param name="str" select="substring-after(@cache:href, 'file://')"/> + </xsl:call-template> + </xsl:variable> +--> + <xsl:variable name="node" select="document(@cache:href)/mal:page"/> + + + <!-- Syntax --> + + <!-- Icons --> + <xsl:for-each select="$node//mal:note"> + </xsl:for-each> +</xsl:template> +</xsl:stylesheet> |