Copied to clipboard

Flag this post as spam?

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


  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 18, 2010 @ 11:37
    Sebastiaan Janssen
    0

    Need to check if a node still exists

    XSLT masters, can this be done in a better way?

    I have a contentpicker that allows me to link related content to my current page. However, if the related content is unpublished or deleted, I don't want to see the div that contains links to this content. Currently I am doing a GetXmlNodeById() and checking if there is a nodeName property on the related item.

    I can't help but feel that this could be done a little more efficiently, just don't know how:

    <xsl:if test="count($currentPage/data [@alias='relatedContent']/content/id[umbraco.library:GetXmlNodeById(text())/@nodeName]) &gt; 0">
      <div>Content here</div>
    </xsl:if>
  • dandrayne 1138 posts 2262 karma points
    May 18, 2010 @ 11:42
    dandrayne
    1

    What about something like this?  Not sure how much more efficient it will be

    <xsl:variable name="currentItem" select="umbraco.library:GetXmlNodeById(.)"/>
    <xsl:if test="not(contains($currentItem, 'No published item exist'))">
    <li>
    <a href="{umbraco.library:NiceUrl($currentItem/@id)}"><xsl:value-of select="$currentItem/@nodeName" /></a>
    </li>
    </xsl:if>

    Dan

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    May 18, 2010 @ 11:46
    Lee Kelleher
    1

    I'd do as Dan suggests, but instead of checking for "No published item exist", I'd do a "count($currentItem/error) = 0".

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    May 18, 2010 @ 11:54
    Douglas Robar
    2

    I've not run tests to confirm this myself, but knowing that umbraco.library calls have more overhead than good xpath statements, here are my thoughts...

    If you can avoid calls to the umbraco.library you'll generally have a faster macro. Not that the umbraco library is slow, but if you're trying to get every last drop of performance then the fewer calls the better.

    Your alternative would be to go up the content tree from $currentPage and then search for the [@id = $id] entirely in xpath.

    If you have a massive content structure to go through this may take longer than the umbraco.library:GetXmlNodeById() call and not be a good option. Though your content tree would need to be truly large.

    Thus, there is no firm answer as to which is best. Rather, look at the performance of your specific situation and choose the one better suited to your needs.

    Let us know what you find out.

    cheers,
    doug.

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    May 18, 2010 @ 11:55
    Douglas Robar
    0

    And, of course, after you've gotten the best performing macro... think about caching the macro for even better performance.

    Adding ?umbDebugShowTrace=true to the url will show you how long each macro takes to run so you can easily do your own A/B tests.

    cheers,
    doug.

Please Sign in or register to post replies

Write your reply to:

Draft