我有一组Sitecore节点:

<item>
  <item>
    <item />    
  </item>
  <item /> <!-- (1) -->
  <item />
</item>
<item>
  <item />
  <item />
</item>

我可以使用函数sc:path(。)获取这些路径,它为标记为(1)的点返回类似'/ item / item'的内容。

我希望能够根据路径对项目进行分组。

所以我的输出会是这样的:

<ul>
  <li>in item
    <ul>
...
    </ul>
  </li>
  <li>in item/item
    <ul>
...
    </ul>
  </li>
</ul>

我正在玩前面的轴,如下面的代码所示:

<xsl:for-each select="exsl:node-set($processedResult)/item">
  <xsl:sort 
    select="substring-before(substring-after(sc:path(.),'/sitecore/media library/'),'.aspx')"
    data-type="text"
    order="ascending" />
  <xsl:variable 
    name="path" 
    select="search:GetFriendlyPath('/sitecore/media library/',sc:path(.))" />
    <!-- returns: item/item from /sitecore/media library/item/item/item.aspx -->                    
  <xsl:variable name="lastPath">
    <xsl:choose>
      <xsl:when test="sc:path(preceding)">
        <xsl:value-of 
          select="search:GetFriendlyPath('sitecore/media library',sc:path(preceding))" />
      </xsl:when>
      <xsl:otherwise>none</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>               
  <xsl:if test="$path != $lastPath"> <!-- grouping test -->
    <li>
      <strong>in <xsl:value-of select="$path" /></strong>
    </li>
  </xsl:if>
  <li>
  <!-- render detail -->
  </li>
</xsl:for-each>

...但是sc:path(前面)没有返回任何内容。因此我的检查不起作用。

我做错了什么?

有帮助吗?

解决方案

我不确定你打算用

做什么
<xsl:when test="sc:path(preceding)">

这读为<!>“;将名为<preceding>的子节点作为节点集提供给sc:path()函数<!>”;

查看您的输入,没有具有该名称的子元素。

可能是你的意思

<xsl:when test="sc:path(preceding-sibling::item[1])">

对Sitecore一无所知,我会给它一个镜头:

<xsl:for-each select="exsl:node-set($processedResult)/item">
  <xsl:sort select="
    substring-before(
      substring-after(sc:path(.), '/sitecore/media library/'),
      '.aspx'
    )"
    data-type="text"
    order="ascending"
  />
  <xsl:variable name="path" select="
    search:GetFriendlyPath(
      '/sitecore/media library/', sc:path(.)
    )
  " />
  <xsl:variable name="lastPath">
    <xsl:choose>
      <xsl:when test="preceding-sibling::item[1]">
        <xsl:value-of select="
          search:GetFriendlyPath(
            'sitecore/media library', sc:path(preceding-sibling::item[1])
          )"
        />
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>none</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <!-- grouping test -->
  <xsl:if test="$path != $lastPath">
    <li>
      <strong>
        <xsl:text>in </xsl:text>
        <xsl:value-of select="$path" />
      </strong>
    </li>
  </xsl:if>

  <li>
    <!-- render detail -->
  </li>
</xsl:for-each>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top