在umbraco中按id选择节点集

时间:2009-06-12 20:35:33

标签: xslt xpath umbraco

umbraco是否有更直接的方法来根据ID列表迭代节点?

$currentPage/ancestor-or-self::root/descendant::node[contains($idList, @id)]

我只是好奇。在遍历回来之前,从currentPage节点遍历树以查找根似乎是不合适的。

2 个答案:

答案 0 :(得分:0)

您可以使用@path属性,该属性包含节点祖先ID的csv列表。然后抓住第一个或任何一个感兴趣的。

另一种技术可能是使用@level在树中特定深度的祖先中选择一个节点。

目前不在我的电脑前会更新我的详细信息。

答案 1 :(得分:0)

在您感兴趣的节点上定义xsl:key可能会更高效,更容易,然后使用key()函数检索它们。

<xsl:key name="node-ids" match="node" use="id"/>
<!-- put the "at" sign in front of "id",
  a blockquote is generated when I try it -->
<xsl:for-each select="$currentPage">
  <xsl:apply-templates select="key( 'node-by-id', $idList)"/>
</xsl:for-each>

请参阅:key() function (spec)。注意第二个参数可能是node-set类型。如果$ idList是以逗号分隔的字符串,则可能需要更改为node-set。

相关问题