<xsl:template name="related-links:get-best-priority-in-sequence">
<xsl:param name="priorities"/>
<xsl:param name="tunnel"/>
<xsl:param name="partial-result"/>
<xsl:param name="best-group" select="'#none#'"/>
<xsl:param name="best-priority" select="-1"/>
<xsl:param name="lesser-priorities"/>
<xsl:choose>
<xsl:when test="contains($priorities, ';')">
<xsl:choose>
<!-- First group always wins. -->
<xsl:when test="$best-group = '#none#'">
<xsl:call-template name="related-links:get-best-priority-in-sequence">
<xsl:with-param name="priorities" select="substring-after($priorities, ';')"/>
<xsl:with-param name="tunnel" select="$tunnel"/>
<xsl:with-param name="partial-result" select="$partial-result"/>
<xsl:with-param name="best-priority" select="substring-before(substring-before($priorities, ';'), ' ')"/>
<xsl:with-param name="best-group" select="substring-after(substring-before($priorities, ';'), ' ')"/>
<xsl:with-param name="lesser-priorities" select="$lesser-priorities"/>
</xsl:call-template>
</xsl:when>
<!-- Higher-priority group found; shunt best-so-far to lesser priorities and continue. -->
<xsl:when test="substring-before(substring-before($priorities, ';'), ' ') > $best-priority">
<xsl:call-template name="related-links:get-best-priority-in-sequence">
<xsl:with-param name="priorities" select="substring-after($priorities, ';')"/>
<xsl:with-param name="tunnel" select="$tunnel"/>
<xsl:with-param name="partial-result" select="$partial-result"/>
<xsl:with-param name="best-priority" select="substring-before(substring-before($priorities, ';'), ' ')"/>
<xsl:with-param name="best-group" select="substring-after(substring-before($priorities, ';'), ' ')"/>
<xsl:with-param name="lesser-priorities" select="concat($lesser-priorities, $best-priority, ' ', $best-group, ';')"/>
</xsl:call-template>
</xsl:when>
<!-- Best-so-far priority is still supreme. -->
<xsl:otherwise>
<xsl:call-template name="related-links:get-best-priority-in-sequence">
<xsl:with-param name="priorities" select="substring-after($priorities, ';')"/>
<xsl:with-param name="tunnel" select="$tunnel"/>
<xsl:with-param name="partial-result" select="$partial-result"/>
<xsl:with-param name="best-priority" select="$best-priority"/>
<xsl:with-param name="best-group" select="$best-group"/>
<xsl:with-param name="lesser-priorities" select="concat($lesser-priorities, substring-before($priorities, ';'), ';')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- Best priority found. -->
<xsl:otherwise>
<xsl:call-template name="related-links:get-sequence-from-priorities">
<xsl:with-param name="priorities" select="$lesser-priorities"/>
<xsl:with-param name="tunnel" select="$tunnel"/>
<xsl:with-param name="partial-result">
<xsl:choose>
<!-- Duplicate; just move on. (Should not happen.) -->
<xsl:when test="contains(concat(';', $partial-result), concat(';', $best-group, ';'))">
<xsl:value-of select="$partial-result"/>
</xsl:when>
<!-- Add group to list and move on. -->
<xsl:otherwise>
<xsl:value-of select="concat($partial-result, $best-group, ';')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template> |