aboutsummaryrefslogtreecommitdiff
path: root/source/99_result
diff options
context:
space:
mode:
authorAdrian Kummerlaender2014-08-26 23:56:10 +0200
committerAdrian Kummerlaender2014-08-26 23:56:10 +0200
commit7db86c66b4f187c4d10776428af1ce8817d3459c (patch)
tree1f72e7b3cdc660c6fecafed713a1a0b8ca9100d5 /source/99_result
parent8aca155ea840cb3064d58b78508195be3bbcfdb3 (diff)
downloadblog.kummerlaender.eu-7db86c66b4f187c4d10776428af1ce8817d3459c.tar
blog.kummerlaender.eu-7db86c66b4f187c4d10776428af1ce8817d3459c.tar.gz
blog.kummerlaender.eu-7db86c66b4f187c4d10776428af1ce8817d3459c.tar.bz2
blog.kummerlaender.eu-7db86c66b4f187c4d10776428af1ce8817d3459c.tar.lz
blog.kummerlaender.eu-7db86c66b4f187c4d10776428af1ce8817d3459c.tar.xz
blog.kummerlaender.eu-7db86c66b4f187c4d10776428af1ce8817d3459c.tar.zst
blog.kummerlaender.eu-7db86c66b4f187c4d10776428af1ce8817d3459c.zip
Implemented a more balanced category sort logic
* random sort order of page-entries on category pages led to unsatisfing results * the entries are now sorted in an alternating fashion depending on their digest length * this produces a much more consistent and balanced output
Diffstat (limited to 'source/99_result')
-rw-r--r--source/99_result/category/category.xsl57
1 files changed, 40 insertions, 17 deletions
diff --git a/source/99_result/category/category.xsl b/source/99_result/category/category.xsl
index 2b54348..1713c84 100644
--- a/source/99_result/category/category.xsl
+++ b/source/99_result/category/category.xsl
@@ -2,7 +2,8 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:math="http://exslt.org/math"
+ xmlns:xalan="http://xml.apache.org/xalan"
+ exclude-result-prefixes="xalan"
>
<xsl:include href="[utility/master.xsl]"/>
@@ -17,33 +18,55 @@
<xsl:value-of select="/datasource/category/entry/@handle"/>
</xsl:template>
+<xsl:template name="page_entry">
+ <xsl:param name="source"/>
+
+ <li>
+ <em>»</em>
+ <a href="{$url}/page/{$source/@handle}">
+ <strong><xsl:value-of select="$source/title"/></strong>
+ <p>
+ <xsl:copy-of select="$source/digest/node()"/>
+ </p>
+ </a>
+ </li>
+</xsl:template>
+
<xsl:template match="category/entry">
<h3>
<xsl:text>All pages categorized as &#187;</xsl:text>
<xsl:value-of select="@handle"/>
- <xsl:text>&#171; in random order</xsl:text>
+ <xsl:text>&#171;</xsl:text>
</h3>
<div class="archiv columns">
<ul class="prettylist">
- <xsl:for-each select="page">
- <xsl:sort select="position() mod math:random()" order="descending"/>
+ <xsl:variable name="ceiling" select="count(page) + 1"/>
+ <xsl:variable name="boundary" select="$ceiling div 2"/>
+
+ <xsl:variable name="sorted_pages">
+ <xsl:for-each select="page">
+ <xsl:sort select="digest/@size" order="ascending"/>
+ <xsl:copy-of select="."/>
+ </xsl:for-each>
+ </xsl:variable>
- <xsl:apply-templates select="."/>
+ <xsl:for-each select="xalan:nodeset($sorted_pages)/page">
+ <xsl:variable name="index" select="position()"/>
+
+ <xsl:if test="$index &lt;= $boundary">
+ <xsl:call-template name="page_entry">
+ <xsl:with-param name="source" select="."/>
+ </xsl:call-template>
+
+ <xsl:if test="$ceiling - $index != $index">
+ <xsl:call-template name="page_entry">
+ <xsl:with-param name="source" select="xalan:nodeset($sorted_pages)/page[$ceiling - $index]"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
</xsl:for-each>
</ul>
</div>
</xsl:template>
-<xsl:template match="category/entry/page">
- <li>
- <em>»</em>
- <a href="{$url}/page/{@handle}">
- <strong><xsl:value-of select="title"/></strong>
- <p>
- <xsl:copy-of select="digest/node()"/>
- </p>
- </a>
- </li>
-</xsl:template>
-
</xsl:stylesheet>