What I want to do is get all documents of a certain doctype that exist on the site and loop through them using for-each. To my eye it looks like they generate the same result, but one makes use of the Umbraco API?
I'm interested in all info related to this since it's a very common thing (at least on my sites) and I want to make sure I do it the most effective way. Im guessing traversing the entire XML-structure can be rather costly, at least on a big site.
I will try it later on however I don't know what you are trying to achief with the $currentPage parameter. You simply don't need that parameter at all. The only time you need to use that is when you need specific information about the current page.
What the $currentPage parameter does is give you a iterator with points to the current page no more no less.
We should probably take this discussion elsewhere, but in umbraco $currentPage is the way you get the site XML - the XML your XSLT gets (in the standard XML/XSLT way) is very light - amounts to a root element named "macro" and its associated parameters (if any). Your answer suggests to me you're not aware of this (?).
Actually, the colons belong to the anscestor-or-self:: part - root is what umbraco decided to name the root element of the XML. So it's not a "::root" operator, but it's the XPath way of asking for elements named "root" that are either the current one, or one of its ancestors (parent, parent's parent and so on). Double colons are needed to distinguish from namespace prefixes which use a single colon.
I'm new to umbraco so I'd definitely run into said situation with multiple sites one day, so thanks for the heads-up :-)
However, you will need to add some criteria to the currentSiteRoot variable, because a select statement will return all the elements matching (and there's probably more than one node element in the ancestor chain for many pages). The only reason the "absoluteRoot" variable works is because we know that there's only one element named root. So we'll need to do something like this instead:
Thanks Chriztian, that actually made everything make much more sense! I love XSLT, but I don't understand some of it yet, obviously!
However, if you're going to travel upwards from the $currentPage to find all the parent "node" element and upwards to find another "node" element, then you'll never end up at the "root" element, because it is not called "node". So in the end you'll still stay within the tree for the current website.
So, luckily, you won't have to know the specific site name. This comes in very handy because you can keep your XSLT file generic for all of your sites.. they just operate on the nodes within the site you're visiting at that moment.
Which is the most effective way of traversing from root?
Which is more effective:
or
?
What I want to do is get all documents of a certain doctype that exist on the site and loop through them using for-each. To my eye it looks like they generate the same result, but one makes use of the Umbraco API?
I'm interested in all info related to this since it's a very common thing (at least on my sites) and I want to make sure I do it the most effective way. Im guessing traversing the entire XML-structure can be rather costly, at least on a big site.
Regards,
Thomas Kahn
Comment author was deleted
I would prefer the first option (so not using umbraco.library).But I doubt that there is a huge difference in performance between the 2
Me too - doing it the pure XSLT-way seems the best way to go.
/Thomas
The default position of the iterator is the root.
So the best way to start from there is:
//node[INSERT CRITERIA HERE]
If you have the iterator positioned somewhere else:
///node[INSERT CRITERIA HERE]
The first / means start from root.
Ron
@Ron - nice tip, thanks.
Excellent! I didn't know that! Thanks Ron!
/Thomas K
@Ron: Adding that extra slash won't cut it, I'm afraid.
Because of the way your data is handed to you in umbraco (by way of a parameter), I always add a variable after the currentPage one to grab the root:
That way, I can always grab stuff "from the root" by using something like:
/Chriztian
Hi Chriztian,
I will try it later on however I don't know what you are trying to achief with the $currentPage parameter.
You simply don't need that parameter at all. The only time you need to use that is when you need specific information about the current page.
What the $currentPage parameter does is give you a iterator with points to the current page no more no less.
Its an interesting issue tho.
Ron
I gues that you are think the only way to reach your data is by using the $currentPage which is a commen misunderstanding.
Correct me if I'me wrong
Ron
Hi Ron,
We should probably take this discussion elsewhere, but in umbraco $currentPage is the way you get the site XML - the XML your XSLT gets (in the standard XML/XSLT way) is very light - amounts to a root element named "macro" and its associated parameters (if any). Your answer suggests to me you're not aware of this (?).
I'me wrong you are right ;)
I was confused with some other senario.
However, it would by nice to have the whole xml as default data tho.
maybe for the next version.
That's great, I had no idea the "::root" operator existed.
For future reference, I'd like to point out something that you would run into when running multiple sites from one umbraco instance.
You would have a content structure that looks like this:
Content
- sitename1.com
-- Home
- sitename2.org
-- Home
By using "::root", you go to the absolute root, which means that you start looking from Umbraco's default "Content" node for your criteria.
However, if you want to only find pages that are in your current site (let's say we're on sitename2.org), you will need to use "::node":
Actually, the colons belong to the anscestor-or-self:: part - root is what umbraco decided to name the root element of the XML. So it's not a "::root" operator, but it's the XPath way of asking for elements named "root" that are either the current one, or one of its ancestors (parent, parent's parent and so on). Double colons are needed to distinguish from namespace prefixes which use a single colon.
I'm new to umbraco so I'd definitely run into said situation with multiple sites one day, so thanks for the heads-up :-)
However, you will need to add some criteria to the currentSiteRoot variable, because a select statement will return all the elements matching (and there's probably more than one node element in the ancestor chain for many pages). The only reason the "absoluteRoot" variable works is because we know that there's only one element named root. So we'll need to do something like this instead:
or if we already assigned the absoluteRoot variable and we know the site roots are children thereof:
/Chriztian
Thanks Chriztian, that actually made everything make much more sense! I love XSLT, but I don't understand some of it yet, obviously!
However, if you're going to travel upwards from the $currentPage to find all the parent "node" element and upwards to find another "node" element, then you'll never end up at the "root" element, because it is not called "node". So in the end you'll still stay within the tree for the current website.
So, luckily, you won't have to know the specific site name. This comes in very handy because you can keep your XSLT file generic for all of your sites.. they just operate on the nodes within the site you're visiting at that moment.
is working on a reply...