for loops, variable xpath selector, converting to newer schema
I've been stuck on this for a while. I'm rewriting an XSLT written against the old schema. Let's call it "FeaturedContent.xslt". This particular XSLT displays content selected from different content pickers placed on document types all throughout a site. The content picker alias (now a MultiNodePicker alias in newer Umbraco version) and its selected nodes used to be stored as XML attributes of an XML node, but now everything is stored in separate XML nodes (seems to make more sense.) The alias for the MultiNodePicker (MNP) is passed in via a macro parameter and stored in a variable called "position".
What I want to be able to do is have my XPATH selector select the MultiNodePicker-picked nodes based on this "position" variable that gets passed in as a macro parameter. The string value will always match the name of the MultiNodePicker.
Let's say my MNP is called "MNPLatestNews", normally, I could just loop through it's nodes, like this
<xsl:for-each select="msxsl:node-set($nodes)"> <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById(.)" /> do some stuff here </xsl:for-each>
But I just get an error when rendering (the XSLT editor save it w/no error though).
Next I tried setting my variable a little differently:
This sort of works, except that my for loop then only prints out the LAST node stored in my MultiNodePicker. Also, I don't really want to do it this way because then every time a add a new MNP to a docType, I'll have to come in and edit this macro if I want to use it on different templates.
In the old XLST, it worked like this: The alias was used to get a comma separated list of node ids, then they were split and looped through.
Regarding the rest of the XSLT - I'd suggest you had a look at a couple of articles I wrote about using match templates and specifically using the Multi-Node Tree Picker .
Using match templates is how XSLT actually works, and it will help you separate stuff, not having everything in one very long template... it's a totally different way of thinking though (compared to traditional programming languages), so may take a while to "grasp" fully if you haven't tried something like that before.
for loops, variable xpath selector, converting to newer schema
I've been stuck on this for a while. I'm rewriting an XSLT written against the old schema. Let's call it "FeaturedContent.xslt". This particular XSLT displays content selected from different content pickers placed on document types all throughout a site. The content picker alias (now a MultiNodePicker alias in newer Umbraco version) and its selected nodes used to be stored as XML attributes of an XML node, but now everything is stored in separate XML nodes (seems to make more sense.) The alias for the MultiNodePicker (MNP) is passed in via a macro parameter and stored in a variable called "position".
What I want to be able to do is have my XPATH selector select the MultiNodePicker-picked nodes based on this "position" variable that gets passed in as a macro parameter. The string value will always match the name of the MultiNodePicker.
Let's say my MNP is called "MNPLatestNews", normally, I could just loop through it's nodes, like this
But I want to do it in general, like this:
...
That's not going to work I guess because I can't use a variable after the first one in an XPATH selector?
I've tried a number of different approaches. The one I would like to get working sets the XPATH selector in a global variable, like this:
Then I can use it like this:
But I just get an error when rendering (the XSLT editor save it w/no error though).
Next I tried setting my variable a little differently:
This sort of works, except that my for loop then only prints out the LAST node stored in my MultiNodePicker. Also, I don't really want to do it this way because then every time a add a new MNP to a docType, I'll have to come in and edit this macro if I want to use it on different templates.
In the old XLST, it worked like this: The alias was used to get a comma separated list of node ids, then they were split and looped through.
I just want to adapt the existing XSLT as quickly as possible and move on. Here's the old XSLT
Hi Jacob,
You can use the name() function to select the Multi-Node Tree Picker property by name - like this:
Regarding the rest of the XSLT - I'd suggest you had a look at a couple of articles I wrote about using match templates and specifically using the Multi-Node Tree Picker .
Using match templates is how XSLT actually works, and it will help you separate stuff, not having everything in one very long template... it's a totally different way of thinking though (compared to traditional programming languages), so may take a while to "grasp" fully if you haven't tried something like that before.
/Chriztian
Thanks a bunch, and thanks for getting me started on some other approaches to for-each
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.