Hi, I'm using the same macro to list different types of content on different pages, one of the document types has a (mandatory) date field while the other doesn't.
What I'm trying to do is to check whether the first item has a date set, then use that to sort the list. If it doesn't then just use the @createDate.
My XSLT is currently as follows, but I get the error of xsl:sort has to be the first item inside the xsl:for-each.
Setting the value of xsl:sort with a xsl:choose?
Hi, I'm using the same macro to list different types of content on different pages, one of the document types has a (mandatory) date field while the other doesn't.
What I'm trying to do is to check whether the first item has a date set, then use that to sort the list. If it doesn't then just use the @createDate.
My XSLT is currently as follows, but I get the error of xsl:sort has to be the first item inside the xsl:for-each.
<xsl:variable name="sortBy">
<xsl:choose>
<xsl:when test="contentDate > 0">
<xsl:text>contentDate</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>@createDate</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:sort select="$sortBy" order="descending" />
Can anybody think of a way of doing this?
Thanks!
Hi Probocop,
You can't use the variable's value directly in the sort's select - as that requires an XPath expression... so try this instead:
It's a little dirty workaround that Chriztian taught me! ;-)
Cheers, Lee
is working on a reply...