[yelp-xsl] Support multiple desc elements for links



commit d03c6b37df9556649666bbfd136bd665c0a23840
Author: Shaun McCance <shaunm redhat com>
Date:   Tue Jan 28 15:34:01 2020 +0100

    Support multiple desc elements for links
    
    http://projectmallard.org/mep/mep0008

 xslt/mallard/common/mal-link.xsl | 41 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/xslt/mallard/common/mal-link.xsl b/xslt/mallard/common/mal-link.xsl
index 25ae61d2..128e248f 100644
--- a/xslt/mallard/common/mal-link.xsl
+++ b/xslt/mallard/common/mal-link.xsl
@@ -329,7 +329,7 @@ attributes containing slash or colon characters.
 <xsl:template name="mal.link.content.custom">
   <xsl:param name="node" select="."/>
   <xsl:param name="action" select="$node/@action"/>
-  <xsl:param name="xref" select="$node/@xref"/>
+ <xsl:param name="xref" select="$node/@xref"/>
   <xsl:param name="href" select="$node/@href"/>
   <xsl:param name="role" select="''"/>
   <xsl:param name="info" select="/false"/>
@@ -415,9 +415,42 @@ element.
         <xsl:choose>
           <xsl:when test="$target or $info">
             <xsl:variable name="infos" select="$target/mal:info | $info"/>
-            <xsl:variable name="descs" select="$infos/mal:desc"/>
-            <xsl:apply-templates mode="mal.link.content.mode"
-                                 select="$descs[1]/node()"/>
+            <xsl:variable name="typedescs" select="$infos/mal:desc[@type = 'link']"/>
+            <xsl:variable name="notypedescs" select="$infos/mal:desc[not(@type)]"/>
+            <xsl:variable name="typerole">
+              <xsl:for-each select="str:split($role)">
+                <xsl:variable name="thisrole" select="string(.)"/>
+                <xsl:if test="$typedescs[@role=$thisrole]">
+                  <xsl:value-of select="concat($thisrole, ' ')"/>
+                </xsl:if>
+              </xsl:for-each>
+            </xsl:variable>
+            <xsl:variable name="notyperole">
+              <xsl:for-each select="str:split($role)">
+                <xsl:variable name="thisrole" select="string(.)"/>
+                <xsl:if test="$notypedescs[@role=$thisrole]">
+                  <xsl:value-of select="concat($thisrole, ' ')"/>
+                </xsl:if>
+              </xsl:for-each>
+            </xsl:variable>
+            <xsl:choose>
+              <xsl:when test="$typerole != ''">
+                <xsl:apply-templates mode="mal.link.content.mode"
+                                     select="$typedescs[@role = substring-before($typerole, ' 
')][1]/node()"/>
+              </xsl:when>
+              <xsl:when test="$notyperole != ''">
+                <xsl:apply-templates mode="mal.link.content.mode"
+                                     select="$notypedescs[@role = substring-before($notyperole, ' 
')][1]/node()"/>
+              </xsl:when>
+              <xsl:when test="$typedescs[not(@role)]">
+                <xsl:apply-templates mode="mal.link.content.mode"
+                                     select="$typedescs[not(@role)][1]/node()"/>
+              </xsl:when>
+              <xsl:when test="$notypedescs[not(@role)]">
+                <xsl:apply-templates mode="mal.link.content.mode"
+                                     select="$notypedescs[not(@role)][1]/node()"/>
+              </xsl:when>
+            </xsl:choose>
           </xsl:when>
         </xsl:choose>
       </xsl:for-each>


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