[yelp-xsl] mal-if.xsl: Initial work on conditional processing



commit 584d116420b31a9017bd2121506da21821d8c180
Author: Shaun McCance <shaunm gnome org>
Date:   Thu Apr 28 17:07:41 2011 -0400

    mal-if.xsl: Initial work on conditional processing

 xslt/mallard/common/Makefile.am      |    2 +-
 xslt/mallard/common/mal-if.xsl       |   93 ++++++++++++++++++++++++++++++++++
 xslt/mallard/common/mal-link.xsl     |    2 +-
 xslt/mallard/html/mal2html-block.xsl |   13 +++--
 xslt/mallard/html/mal2xhtml.xsl      |    2 +
 5 files changed, 106 insertions(+), 6 deletions(-)
---
diff --git a/xslt/mallard/common/Makefile.am b/xslt/mallard/common/Makefile.am
index d9101e0..f1682f1 100644
--- a/xslt/mallard/common/Makefile.am
+++ b/xslt/mallard/common/Makefile.am
@@ -1,5 +1,5 @@
 xsldir=$(datadir)/yelp-xsl/xslt/mallard/common
 
-xsl_DATA = mal-link.xsl mal-sort.xsl
+xsl_DATA = mal-if.xsl mal-link.xsl mal-sort.xsl
 
 EXTRA_DIST=$(xsl_DATA)
diff --git a/xslt/mallard/common/mal-if.xsl b/xslt/mallard/common/mal-if.xsl
new file mode 100644
index 0000000..9fbbfea
--- /dev/null
+++ b/xslt/mallard/common/mal-if.xsl
@@ -0,0 +1,93 @@
+<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
+<!--
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free
+Software Foundation; either version 2 of the License, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this program; see the file COPYING.LGPL.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+-->
+
+<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:dyn="http://exslt.org/dynamic";
+                xmlns:func="http://exslt.org/functions";
+                xmlns:str="http://exslt.org/strings";
+                exclude-result-prefixes="mal if dyn func str"
+                extension-element-prefixes="func"
+                version="1.0">
+
+<!--!!==========================================================================
+Mallard Conditionals
+Support for run-time conditional processing.
+:Revision:version="1.0" date="2011-04-28" status="review"
+
+This stylesheet contains utilities for handling conditional processing
+in Mallard documents.
+-->
+
+
+<!--@@==========================================================================
+mal.if.env
+The list of env strings.
+:Revision:version="1.0" date="2011-04-28" status="review"
+
+This parameter takes a space-separated list of strings for the #{if:env}
+conditional processing function. The #{if:env} function will return #{true}
+if its argument is in this list.
+-->
+<xsl:param name="mal.if.env" select="''"/>
+<xsl:variable name="_mal.if.env" select="concat(' ', $mal.if.env, ' ')"/>
+
+
+<!--**==========================================================================
+mal.if.test
+Test if a condition is true.
+:Revision:version="1.0" date="2011-04-28" status="review"
+$node: The element to check the condition for.
+$test: The XPath expression to check.
+
+This template tests whether the ${test} is true, evaluating it with
+the Mallard conditional functions. The ${test} parameter is expected
+to be a valid XPath expression. If not provided, it defaults to the
+#{if:test} attribute of ${node}, or the non-namespaced #{test}
+attribute if ${node} is a #{if:if} element.
+
+If ${test} evaluates to #{true}, this template outputs the literal
+string #{'true'}. Otherwise, it outputs nothing.
+-->
+<xsl:template name="mal.if.test">
+  <xsl:param name="node" select="."/>
+  <xsl:param name="test" select="$node/self::if:if/@test | $node[not(self::if:if)]/@if:test"/>
+  <xsl:choose>
+    <xsl:when test="string($test) = ''">
+      <xsl:text>true</xsl:text>
+    </xsl:when>
+    <xsl:when test="dyn:evaluate($test)">
+      <xsl:text>true</xsl:text>
+    </xsl:when>
+  </xsl:choose>
+</xsl:template>
+
+<func:function name="if:env">
+  <xsl:param name="env"/>
+  <xsl:choose>
+    <xsl:when test="contains($_mal.if.env, $env)">
+      <func:result select="true()"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <func:result select="false()"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</func:function>
+
+</xsl:stylesheet>
diff --git a/xslt/mallard/common/mal-link.xsl b/xslt/mallard/common/mal-link.xsl
index 106bdb1..2f3f67e 100644
--- a/xslt/mallard/common/mal-link.xsl
+++ b/xslt/mallard/common/mal-link.xsl
@@ -30,7 +30,7 @@ Mallard Links
 Common linking utilities for Mallard documents.
 :Revision:version="1.0" date="2010-01-02" status="final"
 
-This stylesheets contains various utilities for handling links in Mallard
+This stylesheet contains various utilities for handling links in Mallard
 documents.  The templates in this stylesheet make it easier to handle the
 different linking mechanisms in Mallard, including the dynamic automatic
 linking systems.
diff --git a/xslt/mallard/html/mal2html-block.xsl b/xslt/mallard/html/mal2html-block.xsl
index 53b8729..c98ea02 100644
--- a/xslt/mallard/html/mal2html-block.xsl
+++ b/xslt/mallard/html/mal2html-block.xsl
@@ -349,10 +349,15 @@ in accordance with the Mallard specification on fallback block content.
 
 <!-- = p = -->
 <xsl:template mode="mal2html.block.mode" match="mal:p">
-  <p class="p">
-    <xsl:call-template name="html.lang.attrs"/>
-    <xsl:apply-templates mode="mal2html.inline.mode"/>
-  </p>
+  <xsl:variable name="if">
+    <xsl:call-template name="mal.if.test"/>
+  </xsl:variable>
+  <xsl:if test="$if = 'true'">
+    <p class="p">
+      <xsl:call-template name="html.lang.attrs"/>
+      <xsl:apply-templates mode="mal2html.inline.mode"/>
+    </p>
+  </xsl:if>
 </xsl:template>
 
 <!-- = quote = -->
diff --git a/xslt/mallard/html/mal2xhtml.xsl b/xslt/mallard/html/mal2xhtml.xsl
index 5bebb6b..839e973 100644
--- a/xslt/mallard/html/mal2xhtml.xsl
+++ b/xslt/mallard/html/mal2xhtml.xsl
@@ -35,8 +35,10 @@ REMARK: Describe this module
 <xsl:import href="../../common/html.xsl"/>
 <xsl:import href="../../common/utils.xsl"/>
 
+<xsl:import href="../common/mal-if.xsl"/>
 <xsl:import href="../common/mal-link.xsl"/>
 
+<xsl:param name="mal.if.env" select="'html'"/>
 <xsl:param name="mal.link.extension" select="$html.extension"/>
 
 <xsl:include href="mal2html-block.xsl"/>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]