Copied to clipboard

Flag this post as spam?

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


  • Mike Chambers 636 posts 1253 karma points c-trib
    Nov 06, 2012 @ 14:09
    Mike Chambers
    0

    xslt to razor conversion issues... order of enumeration of descendants...:-(

    so I have a simple get descendants...

    from xslt

          <ul>
    <xsl:for-each select="$currentPage/descendant-or-self::*[@isDoc]"> 
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}" title="{altTitle}">
           <xsl:value-of select="@nodeName"/> : <xsl:value-of select="@id"/>
        </a>
      </li>
      </xsl:for-each>
      </ul>
    
    

    razor

    DynamicNodeList d = homePage.DescendantsOrSelf();
    
        //NextNode
        //GetDescendants descendants that are available (firstOne)
    
        \
    @foreach (DynamicNode item in d)
    {
        <li><a title="@item.GetPropertyValue(" href="http://mce_host/forum/developers/razor/@item.Url/simpledoc">@item.Name : @item.Id</a></li>
    }
    

    looks pretty simple... however, they enumerate the nodes differently :-(

    xslt follows the site hierarchy... razor doesn't but renders all children of node before then looping though each child to render there children...

     

    eg

    xslt

    • 1
      • 1.1
      • 1.2
        • 1.2.1
        • 1.2.2
      • 1.3
    • 2
    • 3
    but razor
    1
    2
    3
    1.1
    1.2
    1.3
    1.2.1
    1.2.2
    Is this how it is supposed to work????
    (umb 4.8.1)
  • Mike Chambers 636 posts 1253 karma points c-trib
    Nov 06, 2012 @ 17:58
    Mike Chambers
    0

    Did some more digging...

    and

    DynamicNodeList d = homePage.DescendantsOrSelf();
    DynamicNodeList d = homePage.XPath("descendant-or-self::*");

    whilst looking the same produce different enumerations the top one we are as said before loops though children, then their children etc..

    the second one goes down the heirachy child, has children? etc before moving on to the next sibling (as the xslt of old).

    But there is a 10x performance hit... on a small set of nodes <50 (this is looking just at the execution time for the macro in the debugtrace)

    [Done Executing Macro Script (file: Scratch) from last in s]

    incorrect order .DescendantsOrSelf(); 0.014s

    correct order .XPath("descendant-or-self::*") 0.11s !!!

    and as far as I can tell the same in xslt 0.003s!!!!!

     

    Starting to wonder why I'm recoding to razor.... yes it's easier to read and prob the way forward with mvc on the horizon... but it's painful when it's not replicating expected structures.

Please Sign in or register to post replies

Write your reply to:

Draft