代码之家  ›  专栏  ›  技术社区  ›  Kjensen

在XLST中对节点排序

  •  3
  • Kjensen  · 技术社区  · 16 年前

    此代码选择节点,我要处理…:

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

    如何在其中放置排序/排序依据,以便首先显示具有较新createdDate的项?

    我正在使用CWS初学者工具包,需要更改subnavi.xslt中显示项目的顺序。

    2 回复  |  直到 16 年前
        1
  •  5
  •   sebastiaan    16 年前

    您可以在每个for后面的第一行中进行排序,如下所示:

    <xsl:for-each select="$rootTextpageNode">
    <xsl:sort select="@createDate" order="descending" />
        <xsl:value-of select="@nodeName" />
    </xsl:for-each>
    
        2
  •  4
  •   marc_s MisterSmith    16 年前

    不确定是否可以将排序添加到此变量分配中-通常,在应用模板或执行foreach时进行排序:

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

    <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>
    

    Sorting XSLT Where to put the Sort information

    马克