Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    May 12, 2010 @ 14:23
    Dirk De Grave
    0

    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've tried:

    <xsl:for-each select="$ProjectsItemNodes//value [umbraco.library:GetXmlNodeById(.)/error = 0]">

    but that doesn't make a difference (hence me thinking this not the correct statement)

    Any thoughts, solutions are more than welcome.

     

    Cheers,

    /Dirk

     

     

     

     

     

     

     

     

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    May 12, 2010 @ 14:28
    Douglas Robar
    4

    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.

  • Kim Andersen 1447 posts 2196 karma points MVP
    May 12, 2010 @ 14:29
    Kim Andersen
    0

    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

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 12, 2010 @ 14:34
    Matt Brailsford
    0

    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?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 12, 2010 @ 14:41
    Matt Brailsford
    0

    Sorry, just realised you meant completly deleted nodes, rather than just in the recycle bin.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 12, 2010 @ 14:42
    Matt Brailsford
    0

    You could go another route and have an event handler to detect documents being removed an auto update any docs that link to it?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    May 12, 2010 @ 14:47
    Dirk De Grave
    0

    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

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    May 12, 2010 @ 14:48
    Morten Bock
    0

    I think you should be able to do something like:

    <xsl:for-each select="$ProjectsItemNodes//value [//root/descendant::node[id = ./text()]]">

    to avoid the external call.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    May 12, 2010 @ 14:50
    Dirk De Grave
    0

    @Matt,

    seems like a nice idea for a new package me thinks, or does such functionality already exist?

     

    Cheers,

    /Dirk

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 12, 2010 @ 14:55
    Matt Brailsford
    0

    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

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    May 12, 2010 @ 15:06
    Dirk De Grave
    0

    Good point Doug, should have mentioned what solution i'm using now, here it goes...

    <xsl:for-each select="$ProjectsItemNodes//value [umbraco.library:GetXmlNodeById(./text())/@nodeName != '']">

    @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

Please Sign in or register to post replies

Write your reply to:

Draft