【问题标题】:XSL Sorting With Sitecore使用 Sitecore 进行 XSL 排序
【发布时间】: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 标记时,它会导致每个菜单项的数据出现多次。日期应该只出现一次,不能重复。

标签: xslt sitecore


【解决方案1】:

您似乎正试图从错误的节点读取菜单标题字段。您应该从上下文节点读取它 --> .

试试这个

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

【讨论】:

    【解决方案2】:

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

    在您的 for-each 中,您指的是 $root,例如&lt;xsl:value-of select="$root/@name" /&gt;

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多