It gives the the child RHSItemPickerCC in my $RHSItemNode variable. Lovely.
However, now I want to set RHSItemNode to be either $currentPage/RHSItemPickerCC, if it exists, or $currentPage/RHSItemPickerGA if it doesn't . I am trying this:
When I output the results of each method each using <xsl:copy-of select="$RHSItemNode"/> I get the same markup for both as expected. BUT when I do this:
It breaks for the second method of setting $RHSItemNode. I'm aware of the node-set function, but I don't understand why I would need it in this situation.
How can I set RHSItemNode correctly? What am I missing here?
Thanks for the suggestion but that line works fine when I set RHSItemNode using the first method above. The problem is that when I set the variable using the second method, it throws an error - the usual one - when I try to count the nodes:
David, you can easily debug you XSLT files while running them as well, just attach Visual Studio to the worker process and VS will break on any errors thrown by XSLT, the error message you would get should provide you with some more information.
@Jon - yeah I tried that too but I've found that when working with nodesets using copy-of works best - so far at least :) Using value-of in this situation doesn't seem to make any difference.
@Sebastiaan - I'd forgotten about that - thanks for the tip! The current project doesn't have any .NET in it (yet) and so I'd forgotten about that feature. However, it doesn't seem to be throwing any errors for me in VS. The xslt files I'm editing in a different directory and using post-build events to copy them to the webroot. Could this be the reason for debugging not working?
Nah, VS will use the runtime files, but I'm not very familiar with other setups than my own. If you'd be willing to set it up like that blog post, you might have a bit more luck. :-)
Thanks to everyone for their input. However, I'm still stumped. Outputting the results of both the first and second method of creating the variable (as per the original post) result in the exact same output:
Using the copy-of will basically just give you some xml. What you want is a node set, so I would look in to expressing you logic in a single xpath statement instead of having the the xsl:choose element.
Will have a play with it and see what I can come up with.
Thanks @Morten - that works a treat! Do you know how to change it so that it's recursive?
Each node in the site can have ONLY ONE of EITHER RHSItemPickerCC OR RHSItemPickerGA - and I want to recurse and use the FIRST of EITHER type that I find.
Is this possible? I know how to recurse to get the first CC or GA item, but not how to say use the first of either that I find...
Great work mate, thanks very much. Each step you've given works as expected and hopefully having them here will help others having similar requirements. It's certainly helped me to improve my understanding of XPATH queries!
4.1 schema - issue selecting nodes
Hi all.
This works great:
It gives the the child RHSItemPickerCC in my $RHSItemNode variable. Lovely.
However, now I want to set RHSItemNode to be either $currentPage/RHSItemPickerCC, if it exists, or $currentPage/RHSItemPickerGA if it doesn't . I am trying this:
When I output the results of each method each using <xsl:copy-of select="$RHSItemNode"/> I get the same markup for both as expected. BUT when I do this:
It breaks for the second method of setting $RHSItemNode. I'm aware of the node-set function, but I don't understand why I would need it in this situation.
How can I set RHSItemNode correctly? What am I missing here?
Thanks,
David
Maybe obvious, could "count" be a reserved word? Try "counter" in the variable name instead.
Hi Sebastiaan,
Thanks for the suggestion but that line works fine when I set RHSItemNode using the first method above. The problem is that when I set the variable using the second method, it throws an error - the usual one - when I try to count the nodes:
Cheers,
David
Try using value-of instead of copy of. I had an odd issue that revolved around using copy-of reciently.
Jon
David, you can easily debug you XSLT files while running them as well, just attach Visual Studio to the worker process and VS will break on any errors thrown by XSLT, the error message you would get should provide you with some more information.
@Jon - yeah I tried that too but I've found that when working with nodesets using copy-of works best - so far at least :) Using value-of in this situation doesn't seem to make any difference.
@Sebastiaan - I'd forgotten about that - thanks for the tip! The current project doesn't have any .NET in it (yet) and so I'd forgotten about that feature. However, it doesn't seem to be throwing any errors for me in VS. The xslt files I'm editing in a different directory and using post-build events to copy them to the webroot. Could this be the reason for debugging not working?
look at using msxsl node-set command
Nah, VS will use the runtime files, but I'm not very familiar with other setups than my own. If you'd be willing to set it up like that blog post, you might have a bit more luck. :-)
Another thought:
use the descendant selector ("//") instead of child, as you are possibly not getting anything due to the xpath not matching.
Thanks to everyone for their input. However, I'm still stumped. Outputting the results of both the first and second method of creating the variable (as per the original post) result in the exact same output:
gives me:
What I'm trying to understand is why if both variables have the same value, that one causes the count statement to break, and the other doesn't?
Here is a reduced version of my xslt to illustrate exactly what I'm up to (with standard umbraco xslt stuff removed):
Cheers,
David
Using the copy-of will basically just give you some xml. What you want is a node set, so I would look in to expressing you logic in a single xpath statement instead of having the the xsl:choose element.
Will have a play with it and see what I can come up with.
Okay the node-set function works as a work-around as Casey mentioned, although I'm puzzled that you can't create a node set using the
syntax.
The workaround should you require it is (further to the sample code in my last post):
If anyone knows how to create a node set so you don't need to use msxml:node-set function - I'd love to hear how!
Thanks,
David
@Morten - Meant to add thanks for the explanation, makes things a little clearer in my addled brain :)
Try this:
It basically does a join on the two expressions, which have opposite [] constraints after them. So you get one or the other.
Thanks @Morten - that works a treat! Do you know how to change it so that it's recursive?
Each node in the site can have ONLY ONE of EITHER RHSItemPickerCC OR RHSItemPickerGA - and I want to recurse and use the FIRST of EITHER type that I find.
Is this possible? I know how to recurse to get the first CC or GA item, but not how to say use the first of either that I find...
Hmm. I will take up the challenge while watching the status bars on my installing machine :-)
Ok, I made it a two step thing. First get the closest node that has one of the two elements, and the select the one that exists:
Or if you want the first one that has text in it:
Morten that's fantastic!
But I'm going to keep pushing :)
How about if I want the first one that has at least one item child node? I've tried a variety of things along the lines of
But no joy - one last one perhaps? How are those status bars - surely not finished just yet ;)
Thanks!
I do like a challenge :-) Status bars still working...
This should get you the first one that has a non-empty item child node:
Hey Morten,
Great work mate, thanks very much. Each step you've given works as expected and hopefully having them here will help others having similar requirements. It's certainly helped me to improve my understanding of XPATH queries!
Thanks again,
David
is working on a reply...