【发布时间】:2012-03-01 19:32:38
【问题描述】:
我对 xsl 不是很熟悉,所以我有点磕磕绊绊。
我的 xsl 文件正在构建一个菜单。我正在尝试按 Sitecore 中菜单标题字段中的值对菜单项进行排序。当我运行代码时,它没有排序。它只是将每个菜单项写出四次。
谁能解释一下我错过了什么?
<xsl:template name="show-title">
<xsl:param name="root" />
<xsl:for-each select="$sc_currentitem/item">
<xsl:sort select="sc:fld('menu title',.)" order="ascending"/>
<xsl:choose>
<xsl:when test="sc:fld('menu title',$root)!=''">
<sc:text field="menu title" select="$root" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$root/@name" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
编辑:下面是上面代码生成的数据 示例输出:
- 03/05/201203/05/201203/05/201203/05/2012
- 03/01/201203/01/201203/01/201203/01/2012
- 03/08/201203/08/201203/08/201203/08/2012
- 03/02/201203/02/201203/02/201203/02/2012
- 03/07/201203/07/201203/07/201203/07/2012
我正在尝试让它生成以下内容:
- 03/01/2012
- 03/02/2012
- 03/05/2012
- 03/07/2012
- 03/08/2012
谢谢!
【问题讨论】:
-
示例输入 xml 以及调用该模板的上下文会很有帮助
-
这是我的问题的一部分。我不确定我在处理什么。我基本上只是想弄清楚如何对日期进行排序(“菜单标题”)。当我尝试将 sc_currentitem/item 添加到 for-each 标记时,它会导致每个菜单项的数据出现多次。日期应该只出现一次,不能重复。