使用Sitecore进行XSL排序

时间:2012-03-01 19:32:38

标签: xslt sitecore

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

谢谢!

2 个答案:

答案 0 :(得分:0)

这只是一个猜测,因为你没有真正提供足够的信息让任何人做更多的事情而不是猜测......

在你的for-each中,你指的是$ root,例如<xsl:value-of select="$root/@name" />

我猜测$ root参数包含某种类型的列表,您应该根据当前for-each上下文中的某些值选择此列表的一部分

答案 1 :(得分:0)

看起来您正在尝试从错误的节点读取菜单标题字段。你应该从上下文节点读取它 - &gt; &lt; -

试试这个

<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="." />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="./@name" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
</xsl:template>
相关问题