Can't ever seem to get the basic XSLT tasks to work
Hi All,
As always I have become very frustrated with the XSLT work in umbraco. I have been coding for 2 decades and xslt seems to spank me every time.
Why is it that I cannot seem to do something as simple as find a node by id? Anyone have an idea on how that should work because statements like this clearly do not.
obviously you change the nodeId and the property name to suit your project.
I agree that XSLT take a bit of getting used to, and I tend to gather snippets of useful information and keep them for future use. I just used the one above this evening. There may be another way to do this, plus you can extend this by putting the nodeId into a variable which can be passed in through a macro parameter as a content picker allowing you to be presented with a content picker each time you insert the macro which calls the XSLT saving you having to hard code the nodeId into the XSLT file.
Of course there may be otehr ways to achieve this same result, but this is the one I've used.
HTH
Tom
I'm pretty sure the GetXmlNodeById does not call the database, but rather searches through the cached pages and the xml in umbraco.config. The consensus about the methods in umbraco.library seems to be that only calls to certain methods related to the media section content causes visits to the database.
Can't ever seem to get the basic XSLT tasks to work
Hi All,
As always I have become very frustrated with the XSLT work in umbraco. I have been coding for 2 decades and xslt seems to spank me every time.
Why is it that I cannot seem to do something as simple as find a node by id? Anyone have an idea on how that should work because statements like this clearly do not.
select="/descendant::node/@id = '1047'"
neither does this
select="/descendant::node [@id = '1047']"
nor do any other variant I have tried.
Any thoughts would be greatly appreciated.
You can use this snippet to get data from a specific node:
<xsl:value-of select="umbraco.library:GetXmlNodeById(3106) [@alias = 'myProperty']" />
obviously you change the nodeId and the property name to suit your project. I agree that XSLT take a bit of getting used to, and I tend to gather snippets of useful information and keep them for future use. I just used the one above this evening. There may be another way to do this, plus you can extend this by putting the nodeId into a variable which can be passed in through a macro parameter as a content picker allowing you to be presented with a content picker each time you insert the macro which calls the XSLT saving you having to hard code the nodeId into the XSLT file. Of course there may be otehr ways to achieve this same result, but this is the one I've used. HTH Tomumbraco.library:GetXmlNodeById(1047) should return the node.
select="$currentPage/descendant::node [@ID = 1047]" should return the node if the node is a descendant of the current page.
Hope this helps, Kev
Or this to locate it anywhere in the structure:
$currentPage/ancestor::root//node [@ID = 1047]
I'm not sure about the GetXmlNodeById call mentioned above. Does it call the database and therefore have a possible negative impact on performance?
Wow guys you are are phenomenal!
I'm pretty sure the GetXmlNodeById does not call the database, but rather searches through the cached pages and the xml in umbraco.config. The consensus about the methods in umbraco.library seems to be that only calls to certain methods related to the media section content causes visits to the database.
Regards
Hauge
is working on a reply...