[yelp-xsl] mal2html: Conditional if:test attribute on blocks & items



commit b00739ea7778747a513968537987ddf95af94a61
Author: Shaun McCance <shaunm gnome org>
Date:   Thu Apr 28 22:39:32 2011 -0400

    mal2html: Conditional if:test attribute on blocks & items

 xslt/mallard/html/mal2html-block.xsl |   31 +++++++++++++-----
 xslt/mallard/html/mal2html-list.xsl  |   56 ++++++++++++++++++++++++++++++----
 xslt/mallard/html/mal2html-media.xsl |   19 +++++++-----
 xslt/mallard/html/mal2html-page.xsl  |    2 +-
 xslt/mallard/html/mal2html-svg.xsl   |    2 +
 xslt/mallard/html/mal2html-table.xsl |    2 +
 6 files changed, 88 insertions(+), 24 deletions(-)
---
diff --git a/xslt/mallard/html/mal2html-block.xsl b/xslt/mallard/html/mal2html-block.xsl
index c98ea02..802892f 100644
--- a/xslt/mallard/html/mal2html-block.xsl
+++ b/xslt/mallard/html/mal2html-block.xsl
@@ -46,6 +46,7 @@ automatically strip leading and trailing newlines using *{utils.strip_newlines}.
 <xsl:template name="mal2html.pre">
   <xsl:param name="node" select="."/>
   <xsl:param name="numbered" select="contains(concat(' ', @style, ' '), 'numbered')"/>
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <xsl:variable name="first" select="$node/node()[1]/self::text()"/>
   <xsl:variable name="last" select="$node/node()[last()]/self::text()"/>
   <div>
@@ -138,6 +139,7 @@ automatically strip leading and trailing newlines using *{utils.strip_newlines}.
       </xsl:if>
     </pre>
   </div>
+</xsl:if>
 </xsl:template>
 
 
@@ -192,6 +194,7 @@ in accordance with the Mallard specification on fallback block content.
 
 <!-- = comment = -->
 <xsl:template mode="mal2html.block.mode" match="mal:comment">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <xsl:if test="$mal2html.editor_mode
                 or processing-instruction('mal2html.show_comment')">
     <div class="comment">
@@ -207,6 +210,7 @@ in accordance with the Mallard specification on fallback block content.
       </div>
     </div>
   </xsl:if>
+</xsl:if>
 </xsl:template>
 
 <!-- = comment/cite = -->
@@ -253,14 +257,17 @@ in accordance with the Mallard specification on fallback block content.
 
 <!-- = example = -->
 <xsl:template mode="mal2html.block.mode" match="mal:example">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <div class="example">
     <xsl:call-template name="html.lang.attrs"/>
     <xsl:apply-templates mode="mal2html.block.mode"/>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!-- = figure = -->
 <xsl:template mode="mal2html.block.mode" match="mal:figure">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <div class="figure">
     <xsl:call-template name="html.lang.attrs"/>
     <div class="inner">
@@ -285,10 +292,12 @@ in accordance with the Mallard specification on fallback block content.
       <xsl:apply-templates mode="mal2html.block.mode" select="mal:desc"/>
     </div>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!-- = listing = -->
 <xsl:template mode="mal2html.block.mode" match="mal:listing">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <div class="listing">
     <xsl:call-template name="html.lang.attrs"/>
     <div class="inner">
@@ -301,10 +310,12 @@ in accordance with the Mallard specification on fallback block content.
       </div>
     </div>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!-- = note = -->
 <xsl:template mode="mal2html.block.mode" match="mal:note">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <xsl:variable name="notestyle">
     <xsl:choose>
       <xsl:when test="contains(concat(' ', @style, ' '), ' advanced ')">
@@ -342,6 +353,7 @@ in accordance with the Mallard specification on fallback block content.
       </div>
     </div>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!-- = info = -->
@@ -349,19 +361,17 @@ in accordance with the Mallard specification on fallback block content.
 
 <!-- = p = -->
 <xsl:template mode="mal2html.block.mode" match="mal: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: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 = -->
 <xsl:template mode="mal2html.block.mode" match="mal:quote">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <div class="quote">
     <xsl:call-template name="html.lang.attrs"/>
     <div class="inner">
@@ -374,6 +384,7 @@ in accordance with the Mallard specification on fallback block content.
       <xsl:apply-templates mode="mal2html.block.mode" select="mal:cite"/>
     </div>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!-- = quote/cite = -->
@@ -406,6 +417,7 @@ in accordance with the Mallard specification on fallback block content.
 
 <!-- = synopsis = -->
 <xsl:template mode="mal2html.block.mode" match="mal:synopsis">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <div class="synopsis">
     <xsl:call-template name="html.lang.attrs"/>
     <div class="inner">
@@ -418,6 +430,7 @@ in accordance with the Mallard specification on fallback block content.
       </div>
     </div>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!-- = title = -->
diff --git a/xslt/mallard/html/mal2html-list.xsl b/xslt/mallard/html/mal2html-list.xsl
index 1cbe4db..e041c0f 100644
--- a/xslt/mallard/html/mal2html-list.xsl
+++ b/xslt/mallard/html/mal2html-list.xsl
@@ -18,8 +18,9 @@ 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:str="http://exslt.org/strings";
                 xmlns="http://www.w3.org/1999/xhtml";
-                exclude-result-prefixes="mal"
+                exclude-result-prefixes="mal str"
                 version="1.0">
 
 <!--!!==========================================================================
@@ -34,6 +35,7 @@ as well as any special processing for child #{item} elements.
 
 <!-- = list = -->
 <xsl:template mode="mal2html.block.mode" match="mal:list">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <xsl:variable name="style" select="concat(' ', @style, ' ')"/>
   <xsl:variable name="el">
     <xsl:choose>
@@ -65,18 +67,22 @@ as well as any special processing for child #{item} elements.
       <xsl:apply-templates select="mal:item"/>
     </xsl:element>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!-- = list/item = -->
 <xsl:template match="mal:list/mal:item">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <li class="list">
     <xsl:call-template name="html.lang.attrs"/>
     <xsl:apply-templates mode="mal2html.block.mode"/>
   </li>
+</xsl:if>
 </xsl:template>
 
 <!-- = steps = -->
 <xsl:template mode="mal2html.block.mode" match="mal:steps">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <div class="steps">
     <xsl:call-template name="html.lang.attrs"/>
     <xsl:apply-templates mode="mal2html.block.mode" select="mal:title"/>
@@ -84,18 +90,22 @@ as well as any special processing for child #{item} elements.
       <xsl:apply-templates select="mal:item"/>
     </ol>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!-- = steps/item = -->
 <xsl:template match="mal:steps/mal:item">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <li class="steps">
     <xsl:call-template name="html.lang.attrs"/>
     <xsl:apply-templates mode="mal2html.block.mode"/>
   </li>
+</xsl:if>
 </xsl:template>
 
 <!-- = terms = -->
 <xsl:template mode="mal2html.block.mode" match="mal:terms">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <xsl:variable name="style" select="concat(' ', @style, ' ')"/>
   <div class="terms">
     <xsl:call-template name="html.lang.attrs"/>
@@ -110,10 +120,12 @@ as well as any special processing for child #{item} elements.
       <xsl:apply-templates select="mal:item"/>
     </dl>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!-- = terms/item = -->
 <xsl:template match="mal:terms/mal:item">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <xsl:for-each select="mal:title">
     <dt class="terms">
       <xsl:call-template name="html.lang.attrs">
@@ -126,10 +138,12 @@ as well as any special processing for child #{item} elements.
     <xsl:call-template name="html.lang.attrs"/>
     <xsl:apply-templates mode="mal2html.block.mode" select="*[not(self::mal:title)]"/>
   </dd>
+</xsl:if>
 </xsl:template>
 
 <!-- = tree = -->
 <xsl:template mode="mal2html.block.mode" match="mal:tree">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <xsl:variable name="lines" select="contains(concat(' ', @style, ' '), ' lines ')"/>
   <div>
     <xsl:call-template name="html.lang.attrs"/>
@@ -145,6 +159,7 @@ as well as any special processing for child #{item} elements.
       </xsl:apply-templates>
     </ul>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!--%%==========================================================================
@@ -163,6 +178,21 @@ neighboring #{item} elements, and passes that prefix to child elements.
 <xsl:template mode="mal2html.tree.mode" match="mal:item">
   <xsl:param name="lines" select="false()"/>
   <xsl:param name="prefix" select="''"/>
+  <xsl:variable name="if">
+    <xsl:choose>
+      <!-- We do the tests as we process children, to get lines right, and
+           only apply-templates to what we have to. So if this is a deep
+           item, don't spend the CPU cycles testing it again.
+      -->
+      <xsl:when test="parent::mal:item">
+        <xsl:text>true</xsl:text>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="mal.if.test"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:if test="$if = 'true'">
   <li class="tree">
     <xsl:call-template name="html.lang.attrs"/>
     <div>
@@ -173,16 +203,29 @@ neighboring #{item} elements, and passes that prefix to child elements.
       <xsl:apply-templates mode="mal2html.inline.mode"
                            select="node()[not(self::mal:item)]"/>
     </div>
-    <xsl:if test="mal:item">
+    <xsl:variable name="items">
+      <xsl:for-each select="mal:item">
+        <xsl:variable name="itemif">
+          <xsl:call-template name="mal.if.test"/>
+        </xsl:variable>
+        <xsl:if test="$itemif = 'true'">
+          <xsl:value-of select="concat(position(), ':')"/>
+        </xsl:if>
+      </xsl:for-each>
+    </xsl:variable>
+    <xsl:if test="$items != ''">
       <ul class="tree">
-        <xsl:for-each select="mal:item">
-          <xsl:apply-templates mode="mal2html.tree.mode" select=".">
+        <xsl:variable name="node" select="."/>
+        <xsl:for-each select="str:split($items, ':')">
+          <xsl:variable name="itempos" select="number(.)"/>
+          <xsl:variable name="item" select="$node/mal:item[position() = $itempos]"/>
+          <xsl:apply-templates mode="mal2html.tree.mode" select="$item">
             <xsl:with-param name="lines" select="$lines"/>
             <xsl:with-param name="prefix">
               <xsl:if test="$lines">
                 <xsl:variable name="dir">
                   <xsl:call-template name="l10n.direction">
-                    <xsl:with-param name="lang" select="ancestor-or-self::*[ xml:lang][1]/@xml:lang"/>
+                    <xsl:with-param name="lang" select="$item/ancestor-or-self::*[ xml:lang][1]/@xml:lang"/>
                   </xsl:call-template>
                 </xsl:variable>
                 <xsl:value-of select="translate(translate(translate(translate(
@@ -193,7 +236,7 @@ neighboring #{item} elements, and passes that prefix to child elements.
                                       '&#x2518;', '&#x202F;')"/>
                 <xsl:text>&#x202F;&#x202F;&#x202F;&#x202F;</xsl:text>
                 <xsl:choose>
-                  <xsl:when test="following-sibling::mal:item">
+                  <xsl:when test="position() != last()">
                     <xsl:choose>
                       <xsl:when test="$dir = 'rtl'">
                         <xsl:text>&#x2524;</xsl:text>
@@ -221,6 +264,7 @@ neighboring #{item} elements, and passes that prefix to child elements.
       </ul>
     </xsl:if>
   </li>
+  </xsl:if>
 </xsl:template>
 
 </xsl:stylesheet>
diff --git a/xslt/mallard/html/mal2html-media.xsl b/xslt/mallard/html/mal2html-media.xsl
index 69fe5d5..c70cfae 100644
--- a/xslt/mallard/html/mal2html-media.xsl
+++ b/xslt/mallard/html/mal2html-media.xsl
@@ -145,7 +145,12 @@ FIXME
 <xsl:template mode="mal2html.block.mode" match="tt:*"/>
 
 <xsl:template mode="mal2html.ttml.mode" match="tt:tt">
-  <xsl:apply-templates mode="mal2html.ttml.mode" select="tt:body"/>
+  <xsl:variable name="if">
+    <xsl:call-template name="mal.if.test"/>
+  </xsl:variable>
+  <xsl:if test="$if = 'true'">
+    <xsl:apply-templates mode="mal2html.ttml.mode" select="tt:body"/>
+  </xsl:if>
 </xsl:template>
 
 <xsl:template mode="mal2html.ttml.mode" match="tt:body">
@@ -290,7 +295,9 @@ FIXME
 
 <!-- = mal2html.block.mode % media = -->
 <xsl:template mode="mal2html.block.mode" match="mal:media">
-  <xsl:param name="first_child" select="not(preceding-sibling::*)"/>
+  <xsl:variable name="if">
+    <xsl:call-template name="mal.if.test"/>
+  </xsl:variable>
   <xsl:variable name="style" select="concat(' ', @style, ' ')"/>
   <xsl:variable name="class">
     <xsl:choose>
@@ -307,11 +314,9 @@ FIXME
         <xsl:text> floatright</xsl:text>
       </xsl:when>
     </xsl:choose>
-    <xsl:if test="$first_child">
-      <xsl:text> first-child</xsl:text>
-    </xsl:if>
   </xsl:variable>
   <xsl:choose>
+    <xsl:when test="$if != 'true'"/>
     <xsl:when test="@type = 'image'">
       <div>
         <xsl:attribute name="class">
@@ -347,9 +352,7 @@ FIXME
     </xsl:when>
     <xsl:otherwise>
       <xsl:for-each select="mal:*">
-        <xsl:apply-templates mode="mal2html.block.mode" select=".">
-          <xsl:with-param name="first_child" select="position() = 1 and $first_child"/>
-        </xsl:apply-templates>
+        <xsl:apply-templates mode="mal2html.block.mode" select="."/>
       </xsl:for-each>
     </xsl:otherwise>
   </xsl:choose>
diff --git a/xslt/mallard/html/mal2html-page.xsl b/xslt/mallard/html/mal2html-page.xsl
index 5646a8e..42b465a 100644
--- a/xslt/mallard/html/mal2html-page.xsl
+++ b/xslt/mallard/html/mal2html-page.xsl
@@ -1270,7 +1270,7 @@ ul.tree {
   margin: 0; padding: 0;
   list-style-type: none;
 }
-li.tree { margin: 0; padding: 0; }
+li.tree { margin: -2px 0 0 0; padding: 0; }
 li.tree div { margin: 0; padding: 0; }
 ul.tree ul.tree {
   margin-</xsl:text><xsl:value-of select="$left"/><xsl:text>: 1.44em;
diff --git a/xslt/mallard/html/mal2html-svg.xsl b/xslt/mallard/html/mal2html-svg.xsl
index e6bf856..5a0a80b 100644
--- a/xslt/mallard/html/mal2html-svg.xsl
+++ b/xslt/mallard/html/mal2html-svg.xsl
@@ -85,6 +85,7 @@ certain Mallard extensions, for example to use the Mallard linking mechanism.
 </xsl:template>
 
 <xsl:template mode="mal2html.block.mode" match="svg:svg">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <xsl:variable name="id">
     <xsl:choose>
       <xsl:when test="@xml:id">
@@ -113,6 +114,7 @@ certain Mallard extensions, for example to use the Mallard linking mechanism.
       </exsl:document>
     </xsl:otherwise>
   </xsl:choose>
+</xsl:if>
 </xsl:template>
 
 </xsl:stylesheet>
diff --git a/xslt/mallard/html/mal2html-table.xsl b/xslt/mallard/html/mal2html-table.xsl
index 62b1f6c..e17b994 100644
--- a/xslt/mallard/html/mal2html-table.xsl
+++ b/xslt/mallard/html/mal2html-table.xsl
@@ -34,6 +34,7 @@ REMARK: Describe this module
 
 <!-- = table = -->
 <xsl:template mode="mal2html.block.mode" match="mal:table">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if = 'true'">
   <xsl:variable name="cols" select="mal:col | mal:colgroup/mal:col"/>
   <xsl:variable name="style">
     <xsl:if test="@frame and @frame != 'none'">
@@ -199,6 +200,7 @@ REMARK: Describe this module
       </xsl:apply-templates>
     </table>
   </div>
+</xsl:if>
 </xsl:template>
 
 <!-- = tbody = -->



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