asp.net - Sitecore Xpath 比较两个字段
问题描述
我想要一个查询,查看其父级的名称,然后导航到内容文件夹下具有相同站点名称的文件夹,并在多列表中显示其下的项目。
基本上内容树中的结构如下所示:
- 网站核心
- 内容
- 站点名称1
- (需要在多列表中显示的项目)
- 站点名称2
- (需要在多列表中显示的项目)
- 站点名称1
- 媒体图书馆
- 站点名称1
- PDF1(带有搜索的多列表)
- 站点名称2
- PDF2(带有搜索的多列表)
- 站点名称1
- 内容
当我想开始将相对父级的“名称”与绝对路径的子级的“名称”进行比较时,麻烦就开始了。在 Xpath 中,它可能会像下面描述的那样: 使用 Xpath 比较属性值
在这种情况下,到目前为止我有以下查询:
/sitecore/content/*[ancestor-or-self::*[@@templateid='{Template Id of Sitename}']=@@name and @@templateid='{Template Id of Sitename}']
此查询返回 Sitename1 和 Sitename2。
有趣的是,如果我替换“ancestor-or-se..”或“@@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}]]
在这里,我收到错误“对象必须是字符串类型”,这可能是由于上一个查询的以下部分:
@@name=ancestor::*[@@templateid='{Template Id of root item aka "sitecore"}']//*[@@templateid={Template Id of Sitename}]
正确的部分不能解决字符串。所以问题仍然存在,如何使用 sitecore xpath 从 sitecore 项目中提取纯字符串以便能够进行比较。
解决方案
推荐阅读
- python - AttributeError:“namespace#”对象的属性“FileStream”是只读的
- spring-boot - 当我在春季启动 cosmosDb 中执行 repository.save 时,Mono 值是 MonoOnErrorResume
- typescript - 有没有办法使用 ECMAScript 私有字段在 Typescript 中实现 Singleton 类?
- java - 验证 max Int , max long 值
- python - 如何在openpyxl中从上到下在单元格中写入文本
- r - 使用 dplyr 对以字符串开头的列进行平均
- system - 在我的炸弹实验室问题中,%rsp、%rbp 是什么意思?
- javascript - 如何在 KendoUI Grid 中定义数据绑定,语法非常混乱?
- javascript - 使用 javascript 根据其属性从数组中删除对象
- c# - 部署发布 asp.net 核心应用程序的正确方法。控制台/IIS/WinService