Sitecore Xpath比较两个字段

问题描述 投票:0回答:1

我希望有一个查询其父级名称的查询,然后将导航到内容文件夹下面具有相同网站名称的文件夹,并在多列表中显示其下方的项目。

基本上,内容树中的结构如下所示:

  • Sitecore的 内容 Sitename1 (需要在多列表中显示的项目) Sitename2 (需要在多列表中显示的项目) medialibrary Sitename1 PDF1(带有搜索的multiList) Sitename2 PDF2(带搜索的multiList)

当我想开始将相对父级的“名称”与绝对路径的子级的“名称”进行比较时,麻烦就开始了。在Xpath中,它可能会像下面描述的那样:Compare attribute values using Xpath

在这种情况下,我到目前为止进行了以下查询:

/sitecore/content/*[ancestor-or-self::*[@@templateid='{Template Id of Sitename}']=@@name and @@templateid='{Template Id of Sitename}']

此查询返回Sitename1和Sitename2。

有趣的是,如果我更换“祖先或者说......”或“@@ name”部分bij“Sitename1”,就像这样:

/sitecore/content/*['Sitename1'=@@name and @@templateid='{Template Id of Sitename}']

..和..

/sitecore/content/*[./ancestor-or-self::*[@@templateid='{Template Id of Sitename}']='DSW' and @@templateid='{Template Id of Sitename}']

我得到了想要的结果:Sitename1。

顺便说一句,我现在正在使用内置xpath构建器,然后将查询粘贴到“带搜索的多列表”中。

任何帮助,将不胜感激。

编辑: 我想我发现当我启动相对查询(“./ancestor :: ...”部分)时,它实际上是相对于我最终得到绝对查询的项目。所以我应该有以下查询:

./ancestor-or-self::*[@@templateid='{Template Id of Sitename}' and @@name=ancestor::*[@@templateid='{Template Id of root item aka "sitecore"}']//*[@@templateid={Template Id of Sitename}]]  

这里我得到错误“对象必须是String类型”,这可能是因为上一个查询的以下部分:

@@name=ancestor::*[@@templateid='{Template Id of root item aka "sitecore"}']//*[@@templateid={Template Id of Sitename}]  

这部分的正确部分不能解决为字符串。所以问题仍然存在,如何使用sitecore xpath从sitecore项中提取纯字符串,以便能够进行比较。

asp.net xpath sitecore sitecore8
1个回答
0
投票

我发现Sitecore至少对快速查询不支持子查询,我认为同样适用于普通查询(另请参阅:here中不支持子查询)。现在,这导致我使用简单的代码执行两个查询。一个非常简单的方法是从IDatasource继承(在sitecore.buckets.dll中),你需要编写“code:{fullpath to class},assemblyname.dll”(参见:here

© www.soinside.com 2019 - 2024. All rights reserved.