Sort nodes in XLST

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

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

How can I put sort / orderby there, so the elements with the newer createdDate are displayed first?

I use the CWS starter kit and you need to reorder the items displayed in SubNavi.xslt

+3
source share
2 answers

You can do the sorting in the first line after each of them, for example:

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

I'm not sure that you can add sorting to this variable assignment - as a rule, you sort either when applying the template, or when you do 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 XSLT Sort and Where to Place Sort Data

Mark

+4
source

Source: https://habr.com/ru/post/1717559/


All Articles