multiple tree picker, checking whether node still exists?
First, some background:
Assume you've a got a lot of nodes, and you've got a document that uses a multi tree picker to select any number of nodes from another base node in the content section:
- Questions
-- Question 1
-- Question 2
...
-- Question n
I've also got a content node that has a property of type multiple tree picker that selects any number of child nodes from the 'Questions' parent node.
However, if a 'Question' node gets deleted that has previously selected using the picker, and the 'Question' node is still in the recycle bin (thus still exists), the document still has that node id in its value property
I'm using the split function to search for the selected nodes, and iterate those splitted value to get the specific node. Ok, I know how to check whether the node still exists by checking whether there's an error tag in the returned xml from GetXmlNodeById(), but the point is that I need to alternate classes set on the div elements (currently using position() mod 2), but it won't work using the following construct:
<xsl:for-each select="$ItemNodes//value ['what should I add here to filter for only still existing nodes']">
<xsl:variable name="Node" select="umbraco.library:GetXmlNodeById(.)" />
<xsl:if test="count($Node/error) = 0">
<div>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="position() mod 2">
<xsl:text>class1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>class2</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</div>
</xsl:if>
Currently, the if statement checks whether the node still exists, but would need to move it into the for-each to make sure that non existing nodes are filtered out.
I'd do a @path check in your xpath. If it doesn't start with -1, then it isn't in the active content tree. -20 is the recycle bin, by the way.
But then you still have the problem that if you delete it from the recycle bin you will get an error when trying to get the xml node.
So....
I would create a named template to recursively create a node-set of the valid output. And THEN use that in your for-each. That way you can add as much error-handling as you need.
Great, thanks for all the suggestions, as Kim was so kind to get some code sample up here, and it WORKS, I've been giving him the karma... too bad you can't hand out more karma...
@Matt, don't think it would be advisable to look up all nodes from the recycle bin, as they're no longer in the published xml, hence you'd need a db call to get to those nodes, which seems like overkill and a possible performance bottle neck.
@Morten: I did try to avoid using GetXmlNodeById() in the xpath query, but didn't work out as expected, or I just made some small mistakes... could be due to the fact that we have separated content and data tree structure
multiple tree picker, checking whether node still exists?
First, some background:
Assume you've a got a lot of nodes, and you've got a document that uses a multi tree picker to select any number of nodes from another base node in the content section:
- Questions
-- Question 1
-- Question 2
...
-- Question n
I've also got a content node that has a property of type multiple tree picker that selects any number of child nodes from the 'Questions' parent node.
However, if a 'Question' node gets deleted that has previously selected using the picker, and the 'Question' node is still in the recycle bin (thus still exists), the document still has that node id in its value property
I'm using the split function to search for the selected nodes, and iterate those splitted value to get the specific node. Ok, I know how to check whether the node still exists by checking whether there's an error tag in the returned xml from GetXmlNodeById(), but the point is that I need to alternate classes set on the div elements (currently using position() mod 2), but it won't work using the following construct:
Currently, the if statement checks whether the node still exists, but would need to move it into the for-each to make sure that non existing nodes are filtered out.
I've tried:
but that doesn't make a difference (hence me thinking this not the correct statement)
Any thoughts, solutions are more than welcome.
Cheers,
/Dirk
I'd do a @path check in your xpath. If it doesn't start with -1, then it isn't in the active content tree. -20 is the recycle bin, by the way.
But then you still have the problem that if you delete it from the recycle bin you will get an error when trying to get the xml node.
So....
I would create a named template to recursively create a node-set of the valid output. And THEN use that in your for-each. That way you can add as much error-handling as you need.
cheers,
doug.
Hi Dirk
Could you try something like this:
<xsl:for-each select="$ItemNodes//value[./text() != '' and umbraco.library:GetXmlNodeById(./text())/@nodeName != '']"/>
I think I have used somethink like the above in one of my earlier projects, though I used an apply-templates instead of the for-each.
/Kim A
You could look up all nodes in the recycle bin and store their IDs, then in your for-each, only list items whos id is not in the recycle node list?
Sorry, just realised you meant completly deleted nodes, rather than just in the recycle bin.
You could go another route and have an event handler to detect documents being removed an auto update any docs that link to it?
Great, thanks for all the suggestions, as Kim was so kind to get some code sample up here, and it WORKS, I've been giving him the karma... too bad you can't hand out more karma...
@Matt, don't think it would be advisable to look up all nodes from the recycle bin, as they're no longer in the published xml, hence you'd need a db call to get to those nodes, which seems like overkill and a possible performance bottle neck.
Love this community!
Cheers,
/Dirk
I think you should be able to do something like:
to avoid the external call.
@Matt,
seems like a nice idea for a new package me thinks, or does such functionality already exist?
Cheers,
/Dirk
Nearest I could think of would be the broken link checker package.
http://our.umbraco.org/projects/broken-link-checker
I might look into it.
Matt
Good point Doug, should have mentioned what solution i'm using now, here it goes...
@Morten: I did try to avoid using GetXmlNodeById() in the xpath query, but didn't work out as expected, or I just made some small mistakes... could be due to the fact that we have separated content and data tree structure
Cheers,
/Dirk
is working on a reply...