DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore

Question

This code selects the nodes, I want to work on...:

<xsl:variable name="rootTextpageNode" 
     select="$currentPage/ancestor-or-self::node [@level = 2 and
             @nodeTypeAlias = 'CWS_Textpage']" />

How can I put a sort/orderby in there, so items with newer createdDate are displayed first?

I'm using the CWS starter kit, and need to change the order of items displayed in SubNavi.xslt

Solution

You can do a sort in the first line after a for-each, like so:

<xsl:for-each select="$rootTextpageNode">
<xsl:sort select="@createDate" order="descending" />
    <xsl:value-of select="@nodeName" />
</xsl:for-each>

OTHER TIPS

Not sure if you can add sorting to this variable assignment - typically, you sort either when you apply a template, or when you do a foreach:

<xsl:template match="employees">
    <xsl:apply-templates>
      <xsl:sort select="salary"/>
    </xsl:apply-templates>
  </xsl:template>

or

<xsl:for-each select="catalog/cd">
  <xsl:sort select="artist"/>
  <tr>
    <td><xsl:value-of select="title"/></td>
    <td><xsl:value-of select="artist"/></td>
  </tr>
</xsl:for-each>

See Sorting XSLT and Where to put the Sort information

Marc

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow