Pregunta
Tengo un conjunto de nodos de Sitecore:
<item>
<item>
<item />
</item>
<item /> <!-- (1) -->
<item />
</item>
<item>
<item />
<item />
</item>
Puedo obtener la ruta de estos utilizando una función sc: ruta (.), que devuelve algo como '/ item / item' para el punto marcado (1).
Lo que quiero poder hacer es agrupar el elemento según su ruta.
Entonces mi salida sería algo así como:
<ul>
<li>in item
<ul>
...
</ul>
</li>
<li>in item/item
<ul>
...
</ul>
</li>
</ul>
Estoy jugando con los ejes anteriores en este momento, como en el siguiente código:
<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>
... pero sc: ruta (anterior) no devuelve nada. Por lo tanto, mi cheque no funciona.
¿Qué estoy haciendo mal?
Solución
No estoy seguro de qué pretendes hacer con
<xsl:when test="sc:path(preceding)">
Esto se lee como " alimenta a los hijos llamados <preceding>
como un conjunto de nodos a la función sc:path()
" ;.
Mirando su entrada, no hay elementos secundarios con ese nombre.
¿Podría ser que te refieres a algo como
<xsl:when test="sc:path(preceding-sibling::item[1])">
?
Sin saber nada sobre Sitecore, lo intentaré con:
<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>