I have a page template where when the site was setup it referenced the folder(Item ID), but now I have multiple sites and need it to reference ONLY the sites folders not just the main site. I am trying to run a query that will just select this folder from the selected site. So I have site Red and a site blue and a site green, under the sites I have the corresponding datasources and that is what I need to call in with this query. So site red needs to point to its corresponding red datasource with the countries folder under it, SAMPLE is the second image, trying to point to that countries folder.

Query Sample

enter image description here

2 Answers 2


What you need to do is walk back up the tree to your Site root item and then path down to the Datasource folder you need. You can do it something like this:

query:./ancestor-or-self::*[@@templatename='Your SiteRoot Template']/#red datasource#/Countries

This is saying ./ start at the current item, ancestor-or-self - get the first item either me or any of my parent (ancestor) items that match the template name of your site root template, /#red datasource/countries/* give me all the items at this path.

  • I forgot to mention this is for a multilist datasource, could this be possible to grab the ID for it since that is how it was setup before. Dec 31, 2021 at 17:11

So this is what I ended up coming up with, with the help of the above response.


So Richard thanks for helping me in the right direction.

  • 2
    You should accept the answer that actually solved your problem, not just repost the answer and self-tick it.
    – Mark Cassidy
    Jan 7, 2022 at 6:00
  • Your use of //* descendents query is likely to lead to performance issues too. You should follow the pattern that Richard had provided in the example and specify as much of the interim folder structure as possible.
    – jammykam
    Jan 7, 2022 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.