[yelp-xsl] [mal-link.xsl] Move see-also to mal-link, fix duplicate/dropped links



commit 33941fb4265ec9b2276fe1a09676456dd4c34c87
Author: Shaun McCance <shaunm gnome org>
Date:   Fri Mar 19 14:20:30 2010 -0500

    [mal-link.xsl] Move see-also to mal-link, fix duplicate/dropped links
    
    I moved the guide and topic links to mal-link before, using linkid to allow
    extensions like Sites to do the right thing.  I've done the same for see-also
    links now, and fixed duplicate and dropped links in all types of links when
    using Sites.

 xslt/mallard/common/mal-link.xsl    |  169 ++++++++++++++++++++++++-----------
 xslt/mallard/html/mal2html-page.xsl |   32 +++----
 2 files changed, 130 insertions(+), 71 deletions(-)
---
diff --git a/xslt/mallard/common/mal-link.xsl b/xslt/mallard/common/mal-link.xsl
index 1df5a1d..7a1004b 100644
--- a/xslt/mallard/common/mal-link.xsl
+++ b/xslt/mallard/common/mal-link.xsl
@@ -294,7 +294,7 @@ tooltip for #{mailto:} URLs in ${href}.
 <!--**==========================================================================
 mal.link.guidelinks
 Output the guide links for a page or section.
-:Revision:version="1.0" date="2010-01-02"
+:Revision:version="1.0" date="2010-03-19"
 $node: The #{page} or #{section} element to generate links for.
 
 This template outputs all the guide links for a page or section, whether
@@ -318,23 +318,27 @@ The output is a result tree fragment.  To use these results, call
       <xsl:with-param name="node" select="$node"/>
     </xsl:call-template>
   </xsl:variable>
-  <xsl:for-each select="$node/mal:info/mal:link[ type = 'guide']">
-    <xsl:variable name="linklinkid">
-      <xsl:call-template name="mal.link.xref.linkid"/>
-    </xsl:variable>
-    <mal:link xref="{$linklinkid}">
-      <mal:title type="sort">
-        <xsl:for-each select="$mal.cache">
-          <xsl:value-of select="key('mal.cache.key', $linklinkid)/mal:info/mal:title[ type = 'sort'][1]"/>
-        </xsl:for-each>
-      </mal:title>
-    </mal:link>
-  </xsl:for-each>
+  <xsl:variable name="links">
+    <xsl:for-each select="$node/mal:info/mal:link[ type = 'guide']">
+      <xsl:variable name="linklinkid">
+        <xsl:call-template name="mal.link.xref.linkid"/>
+      </xsl:variable>
+      <mal:link xref="{$linklinkid}">
+        <mal:title type="sort">
+          <xsl:for-each select="$mal.cache">
+            <xsl:value-of select="key('mal.cache.key', $linklinkid)/mal:info/mal:title[ type = 'sort'][1]"/>
+          </xsl:for-each>
+        </mal:title>
+      </mal:link>
+    </xsl:for-each>
+  </xsl:variable>
+  <xsl:copy-of select="$links"/>
+  <xsl:variable name="linknodes" select="exsl:node-set($links)/*"/>
   <xsl:for-each select="$mal.cache//*[mal:info/mal:link[ type = 'topic'][ xref = $linkid]]">
     <xsl:variable name="linklinkid">
       <xsl:call-template name="mal.link.linkid"/>
     </xsl:variable>
-    <xsl:if test="not($node/mal:info/mal:link[ type = 'guide'][ xref = $linklinkid])">
+    <xsl:if test="not($linknodes[ xref = $linklinkid])">
       <mal:link xref="{$linklinkid}">
         <mal:title type="sort">
           <xsl:value-of select="mal:info/mal:title[ type = 'sort'][1]"/>
@@ -348,7 +352,7 @@ The output is a result tree fragment.  To use these results, call
 <!--**==========================================================================
 mal.link.topiclinks
 Output the topic links for a page or section.
-:Revision:version="1.0" date="2010-01-02"
+:Revision:version="1.0" date="2010-03-19"
 $node: The #{page} or #{section} element to generate links for.
 
 This template outputs all the topic links for a guide page or section, whether
@@ -393,49 +397,53 @@ The output is a result tree fragment.  To use these results, call
       </xsl:if>
     </xsl:for-each>
   </xsl:variable>
-  <xsl:for-each select="$node/mal:info/mal:link[ type = 'topic']">
-    <xsl:variable name="xref">
-      <xsl:call-template name="mal.link.xref.linkid"/>
-    </xsl:variable>
-    <xsl:variable name="link" select="."/>
-    <xsl:variable name="grouppos">
-      <xsl:if test="$link/@group">
-        <xsl:for-each select="$groupslist">
-          <xsl:if test="string(.) = $link/@group">
-            <xsl:value-of select="position()"/>
-          </xsl:if>
-        </xsl:for-each>
-      </xsl:if>
-    </xsl:variable>
-    <xsl:variable name="groupsort">
-      <xsl:value-of select="$grouppos"/>
-      <xsl:if test="string($grouppos) = ''">
-        <xsl:value-of select="$defaultpos"/>
-      </xsl:if>
-    </xsl:variable>
-    <mal:link xref="{$xref}">
-      <xsl:attribute name="group">
-        <xsl:value-of select="$groupslist[number($groupsort)]"/>
-      </xsl:attribute>
-      <xsl:attribute name="groupsort">
-        <xsl:value-of select="$groupsort"/>
-      </xsl:attribute>
-      <mal:title type="sort">
-        <xsl:for-each select="$mal.cache">
-          <xsl:value-of select="key('mal.cache.key', $xref)/mal:info/mal:title[ type = 'sort'][1]"/>
-        </xsl:for-each>
-      </mal:title>
-    </mal:link>
-  </xsl:for-each>
+  <xsl:variable name="links">
+    <xsl:for-each select="$node/mal:info/mal:link[ type = 'topic']">
+      <xsl:variable name="linklinkid">
+        <xsl:call-template name="mal.link.xref.linkid"/>
+      </xsl:variable>
+      <xsl:variable name="link" select="."/>
+      <xsl:variable name="grouppos">
+        <xsl:if test="$link/@group">
+          <xsl:for-each select="$groupslist">
+            <xsl:if test="string(.) = $link/@group">
+              <xsl:value-of select="position()"/>
+            </xsl:if>
+          </xsl:for-each>
+        </xsl:if>
+      </xsl:variable>
+      <xsl:variable name="groupsort">
+        <xsl:value-of select="$grouppos"/>
+        <xsl:if test="string($grouppos) = ''">
+          <xsl:value-of select="$defaultpos"/>
+        </xsl:if>
+      </xsl:variable>
+      <mal:link xref="{$linklinkid}">
+        <xsl:attribute name="group">
+          <xsl:value-of select="$groupslist[number($groupsort)]"/>
+        </xsl:attribute>
+        <xsl:attribute name="groupsort">
+          <xsl:value-of select="$groupsort"/>
+        </xsl:attribute>
+        <mal:title type="sort">
+          <xsl:for-each select="$mal.cache">
+            <xsl:value-of select="key('mal.cache.key', $linklinkid)/mal:info/mal:title[ type = 'sort'][1]"/>
+          </xsl:for-each>
+        </mal:title>
+      </mal:link>
+    </xsl:for-each>
+  </xsl:variable>
+  <xsl:copy-of select="$links"/>
+  <xsl:variable name="linknodes" select="exsl:node-set($links)/*"/>
   <xsl:for-each select="$mal.cache//mal:info/mal:link[ type = 'guide'][ xref = $linkid]">
     <xsl:variable name="source" select="../.."/>
-    <xsl:variable name="xref">
+    <xsl:variable name="linklinkid">
       <xsl:call-template name="mal.link.xref.linkid">
         <xsl:with-param name="node" select="$source"/>
         <xsl:with-param name="xref" select="$source/@id"/>
       </xsl:call-template>
     </xsl:variable>
-    <xsl:if test="not($node/mal:info/mal:link[ type = 'topic'][ xref = $xref])">
+    <xsl:if test="not($linknodes[ xref = $linklinkid])">
       <xsl:variable name="link" select="."/>
       <xsl:variable name="grouppos">
         <xsl:if test="$link/@group">
@@ -452,7 +460,7 @@ The output is a result tree fragment.  To use these results, call
           <xsl:value-of select="$defaultpos"/>
         </xsl:if>
       </xsl:variable>
-      <mal:link xref="{$xref}">
+      <mal:link xref="{$linklinkid}">
         <xsl:attribute name="group">
           <xsl:value-of select="$groupslist[number($groupsort)]"/>
         </xsl:attribute>
@@ -469,6 +477,63 @@ The output is a result tree fragment.  To use these results, call
 
 
 <!--**==========================================================================
+mal.link.seealsolinks
+Output the see-also links for a page or section.
+:Revision:version="1.0" date="2010-03-19"
+$node: The #{page} or #{section} element to generate links for.
+
+This template outputs all the see-also links for a page or section, whether
+declared in the page or section or in another page or section.  It outputs
+each of the links as a #{link} element within the Mallard namespace.  Each
+#{link} element has an #{xref} attribute pointing to the target page or section.
+
+Each #{link} element contains a #{title} with #{type="sort"} providing the
+sort title of the target page or section.  The results are not sorted when
+returned from this template.  Use #{xsl:sort} on the sort titles to sort
+the results.
+
+The output is a result tree fragment.  To use these results, call
+#{exsl:node-set} on them.
+-->
+<xsl:template name="mal.link.seealsolinks">
+  <xsl:param name="node" select="."/>
+  <xsl:variable name="linkid">
+    <xsl:call-template name="mal.link.linkid">
+      <xsl:with-param name="node" select="$node"/>
+    </xsl:call-template>
+  </xsl:variable>
+  <xsl:variable name="links">
+    <xsl:for-each select="$node/mal:info/mal:link[ type = 'seealso']">
+      <xsl:variable name="linklinkid">
+        <xsl:call-template name="mal.link.xref.linkid"/>
+      </xsl:variable>
+      <mal:link xref="{$linklinkid}">
+        <mal:title type="sort">
+          <xsl:for-each select="$mal.cache">
+            <xsl:value-of select="key('mal.cache.key', $linklinkid)/mal:info/mal:title[ type = 'sort'][1]"/>
+          </xsl:for-each>
+        </mal:title>
+      </mal:link>
+    </xsl:for-each>
+  </xsl:variable>
+  <xsl:copy-of select="$links"/>
+  <xsl:variable name="linknodes" select="exsl:node-set($links)/*"/>
+  <xsl:for-each select="$mal.cache//*[mal:info/mal:link[ type = 'seealso'][ xref = $linkid]]">
+    <xsl:variable name="linklinkid">
+      <xsl:call-template name="mal.link.linkid"/>
+    </xsl:variable>
+    <xsl:if test="not($linknodes[ xref = $linklinkid])">
+      <mal:link xref="{$linklinkid}">
+        <mal:title type="sort">
+          <xsl:value-of select="mal:info/mal:title[ type = 'sort'][1]"/>
+        </mal:title>
+      </mal:link>
+    </xsl:if>
+  </xsl:for-each>
+</xsl:template>
+
+
+<!--**==========================================================================
 mal.link.linktrails
 Output link trails for a page or section.
 $node: The #{page} or #{section} element to generate links for.
diff --git a/xslt/mallard/html/mal2html-page.xsl b/xslt/mallard/html/mal2html-page.xsl
index 182da82..98466b3 100644
--- a/xslt/mallard/html/mal2html-page.xsl
+++ b/xslt/mallard/html/mal2html-page.xsl
@@ -244,18 +244,19 @@ REMARK: Describe this template
       </xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
-  <!-- FIXME: // is slow -->
-  <xsl:variable name="inlinks"
-                select="$mal.cache//*[mal:info/mal:link[ type = 'seealso'][ xref = $id]]"/>
-  <xsl:variable name="outlinks"
-                select="$node/mal:info/mal:link[ type = 'seealso']"/>
   <xsl:variable name="guidelinks">
     <xsl:call-template name="mal.link.guidelinks">
       <xsl:with-param name="node" select="$node"/>
     </xsl:call-template>
   </xsl:variable>
   <xsl:variable name="guidenodes" select="exsl:node-set($guidelinks)/*"/>
-  <xsl:if test="$inlinks or $outlinks or $guidenodes">
+  <xsl:variable name="seealsolinks">
+    <xsl:call-template name="mal.link.seealsolinks">
+      <xsl:with-param name="node" select="$node"/>
+    </xsl:call-template>
+  </xsl:variable>
+  <xsl:variable name="seealsonodes" select="exsl:node-set($seealsolinks)/*"/>
+  <xsl:if test="$guidenodes or $seealsonodes">
     <div class="sect autolinkssection">
       <div class="header">
         <xsl:element name="{concat('h', $depth)}" namespace="{$mal2html.namespace}">
@@ -271,13 +272,13 @@ REMARK: Describe this template
       <div class="autolinks">
         <xsl:if test="$guidenodes">
           <div class="title"><span>
-            <!-- FIXME: i18n -->
             <xsl:call-template name="l10n.gettext">
-                <xsl:with-param name="msgid" select="'More About'"/>
+              <xsl:with-param name="msgid" select="'More About'"/>
             </xsl:call-template>
           </span></div>
           <ul>
             <xsl:for-each select="$guidenodes">
+              <xsl:sort select="mal:title[ type = 'sort']"/>
               <xsl:call-template name="mal2html.page.autolink">
                 <xsl:with-param name="xref" select="@xref"/>
                 <xsl:with-param name="role" select="'guide'"/>
@@ -285,22 +286,15 @@ REMARK: Describe this template
             </xsl:for-each>
           </ul>
         </xsl:if>
-
-        <xsl:if test="$inlinks or $outlinks">
+        <xsl:if test="$seealsonodes">
           <div class="title"><span>
-            <!-- FIXME: i18n -->
             <xsl:call-template name="l10n.gettext">
-                <xsl:with-param name="msgid" select="'See Also'"/>
+              <xsl:with-param name="msgid" select="'See Also'"/>
             </xsl:call-template>
           </span></div>
           <ul>
-            <xsl:for-each select="$inlinks">
-              <xsl:call-template name="mal2html.page.autolink">
-                <xsl:with-param name="page" select="."/>
-                <xsl:with-param name="role" select="'seealso'"/>
-              </xsl:call-template>
-            </xsl:for-each>
-            <xsl:for-each select="$outlinks">
+            <xsl:for-each select="$seealsonodes">
+              <xsl:sort select="mal:title[ type = 'sort']"/>
               <xsl:call-template name="mal2html.page.autolink">
                 <xsl:with-param name="xref" select="@xref"/>
                 <xsl:with-param name="role" select="'seealso'"/>



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