0
votes

I would like to have a query that looks at the name of its parent and then will navigate to the folder with the same sitename underneath the content folder and show the items underneath it in the multilist.

Basically the structure in the content tree looks as followed:

  • sitecore
    • content
      • Sitename1
        • (items that needs to be showed in the multilist)
      • Sitename2
        • (items that needs to be showed in the multilist)
    • medialibrary
      • Sitename1
        • PDF1 (with multiList with search)
      • Sitename2
        • PDF2 (with multiList with search)

Trouble starts when I would like to start comparing the "name" of the relative parent to the "name" of the child of the absolute path. In Xpath it would probably go something like it is described within: Compare attribute values using Xpath

In this case I had the following query up until now:

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

This query returns Sitename1 and Sitename2.

Funny thing is that if I replace "ancestor-or-se.." or "@@name" part bij "Sitename1", like so:

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

..and..

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

I get the wanted result: Sitename1.

Btw I'm using the build-in xpath builder for now, before it paste the query into the "multilist with search."

Any help would be appreciated.

Edit:
I think I found out that when I start the relative query (the "./ancestor::..." part) it actually is relative to the item where I ended up with the absolute query. So I should have the following query:

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

Here I get the error "Object must be of type String," which is probably because of the following part of the previous query:

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

The right part of this doesn't solve to a string. So the question remains, how to extract pure the string out of a sitecore item using sitecore xpath in order to be able to make a comparison.

1
How to ask an XPath question clearly: Show XML, not a pseudo outline. Then show the XML nodes that you wish to select, given a criteria clearly stated in terms of the actual XML and any variations that must be accomodated.kjhughes
Only thing is, as far as I know, I'm not aware of any xml for sitecore. I gave a representation of the sitecore content tree. Correct me if I'm wrong.Sam
Sitecore XPath does not return strings, it returns Items. Which is not for consumption by XPath but by code, i.e. it's been for very simple tree crawl queries. If you need to do something complex. So in the above, I presume the starting point in the Media Library item, and you are trying to find the matching /sitecore/content/ item... I don't think this will be possible without code.jammykam

1 Answers

0
votes

I figured out that Sitecore doesn't support subqueries at least for fast queries, I think same applies to normal ones (see also: "Subqueries are not supported" in here ). Which now lead me to using simple code where I perform two queries. A very simple way to do it is to inherit from IDatasource (in the sitecore.buckets.dll), you will need to write "code:{fullpath to class}, assemblyname.dll" (See also: here)