Skip to content

Instantly share code, notes, and snippets.

@nul800sebastiaan
Created June 23, 2011 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nul800sebastiaan/1042579 to your computer and use it in GitHub Desktop.
Save nul800sebastiaan/1042579 to your computer and use it in GitHub Desktop.
Conditional sorting for XSLTSearch 1.0
<xsl:choose>
<xsl:when test="umbraco.library:RequestQueryString('sortbydate') != ''">
<xsl:for-each select="$matchedNodes">
<!-- sort on the page score of the node, within ALL the nodes to return (the sorting must happen before choosing the nodes for this page) -->
<xsl:sort select="@createDate" order="descending"/>
<!-- only the nodes for this page -->
<xsl:if test="position() &gt;= $startMatch and position() &lt;= $endMatch">
<xsl:call-template name="postlist" />
</xsl:if>
<xsl:comment/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$matchedNodes">
<!-- sort on the page score of the node, within ALL the nodes to return (the sorting must happen before choosing the nodes for this page) -->
<xsl:sort select="substring-before(substring-after($pageScoreList, concat(';',generate-id(.),'=')),';')" data-type="number" order="descending"/>
<!-- only the nodes for this page -->
<xsl:if test="position() &gt;= $startMatch and position() &lt;= $endMatch">
<xsl:call-template name="postlist" />
</xsl:if>
<xsl:comment/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
@greystate
Copy link

Problem with this is that the first selects an attribute, whereas the other selects a string - you cannot put a predicate on a string, so you'd need to wrap that somehow...

Hmmm... edge-case...

/Chriztian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment