[yelp-xsl] mal-if: Added support for if:choose/if:if/if:else
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp-xsl] mal-if: Added support for if:choose/if:if/if:else
- Date: Fri, 29 Apr 2011 14:02:09 +0000 (UTC)
commit aaf7d953bb26ec104be50897bc7cf110df3ecd7b
Author: Shaun McCance <shaunm gnome org>
Date: Thu Apr 28 22:53:59 2011 -0400
mal-if: Added support for if:choose/if:if/if:else
xslt/mallard/common/mal-if.xsl | 45 ++++++++++++++++++++++++++++++++++
xslt/mallard/html/mal2html-block.xsl | 18 +++++++++++++-
2 files changed, 62 insertions(+), 1 deletions(-)
---
diff --git a/xslt/mallard/common/mal-if.xsl b/xslt/mallard/common/mal-if.xsl
index 9fbbfea..d295607 100644
--- a/xslt/mallard/common/mal-if.xsl
+++ b/xslt/mallard/common/mal-if.xsl
@@ -78,6 +78,51 @@ string #{'true'}. Otherwise, it outputs nothing.
</xsl:choose>
</xsl:template>
+<!--**==========================================================================
+mal.if.choose
+Gets the position of the first matching condition in #{if:choose}
+:Revision:version="1.0" date="2011-04-28" status="review"
+$node: The #{if:choose} element to check.
+
+The #{if:choose} element takes a list of #{if:if} elements, optionally followed
+by an #{if:else} element. Given an #{if:choose} element, this template outputs
+the position of the first #{if:if} whose #{test} attribute evaluates to #{true}.
+If no #{if:if} elements are true, the output is empty.
+-->
+<xsl:template name="mal.if.choose">
+ <xsl:param name="node" select="."/>
+ <xsl:if test="if:if[1]">
+ <xsl:call-template name="_mal.if.choose.try">
+ <xsl:with-param name="node" select="if:if[1]"/>
+ <xsl:with-param name="pos" select="1"/>
+ </xsl:call-template>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template name="_mal.if.choose.try">
+ <xsl:param name="node"/>
+ <xsl:param name="pos"/>
+ <xsl:variable name="if">
+ <xsl:call-template name="mal.if.test">
+ <xsl:with-param name="node" select="$node"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="$if = 'true'">
+ <xsl:value-of select="$pos"/>
+ </xsl:when>
+ <xsl:when test="$node/following-sibling::if:if[1]">
+ <xsl:call-template name="_mal.if.choose.try">
+ <xsl:with-param name="node" select="$node/following-sibling::if:if[1]"/>
+ <xsl:with-param name="pos" select="$pos + 1"/>
+ </xsl:call-template>
+ </xsl:when>
+ </xsl:choose>
+</xsl:template>
+
+
+<!-- ======================================================================= -->
+
<func:function name="if:env">
<xsl:param name="env"/>
<xsl:choose>
diff --git a/xslt/mallard/html/mal2html-block.xsl b/xslt/mallard/html/mal2html-block.xsl
index 802892f..172591f 100644
--- a/xslt/mallard/html/mal2html-block.xsl
+++ b/xslt/mallard/html/mal2html-block.xsl
@@ -18,9 +18,10 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mal="http://projectmallard.org/1.0/"
+ xmlns:if="http://projectmallard.org/experimental/if/"
xmlns:msg="http://projects.gnome.org/yelp/gettext/"
xmlns="http://www.w3.org/1999/xhtml"
- exclude-result-prefixes="mal msg"
+ exclude-result-prefixes="mal if msg"
version="1.0">
<!--!!==========================================================================
@@ -456,4 +457,19 @@ in accordance with the Mallard specification on fallback block content.
</div>
</xsl:template>
+<!-- = if:choose = -->
+<xsl:template mode="mal2html.block.mode" match="if:choose">
+ <xsl:variable name="pos">
+ <xsl:call-template name="mal.if.choose"/>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="$pos != ''">
+ <xsl:apply-templates mode="mal2html.block.mode" select="if:if[position() = number($pos)]/*"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates mode="mal2html.block.mode" select="if:else/*"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
</xsl:stylesheet>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]