Copied to clipboard

Flag this post as spam?

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


  • Ian Smedley 97 posts 192 karma points
    Nov 08, 2010 @ 17:59
    Ian Smedley
    0

    XSLT Macros rendering before .NET Usercontrols

    Hi,

    I have a strange error, I've got a page, with many XSLT macros, and also a .NET usercontrol macro.

    In my page, I wish to have 

    • XSLT macro 1
    • .NET macro 
    • XSLT macro 2
    • XSLT macro3 etc..

    But the order is coming through more like

    • XLT macro 1
    • XSLT macro 2
    • XSLT macro3
    • .NET macro 2
    So my .NET usercontrol is sitting in the wrong part of the page, breaking my HTML..
            <umbraco:Macro Alias="XSLT1" runat="server"></umbraco:Macro>
            <umbraco:Macro Alias=".NET1" runat="server"></umbraco:Macro>
            <umbraco:Macro Alias="XSLT2" runat="server"></umbraco:Macro>
    
            <div id="div">
                <umbraco:Item field="field" runat="server"></umbraco:Item>
                <umbraco:Macro ID="XSLT3" Alias="XSLT3" runat="server"></umbraco:Macro>
            </div>  
        </div>
    
        <umbraco:Macro Alias="XSLT4" runat="server"></umbraco:Macro><div2><umbraco:Macro Alias="XSLT5" runat="server"></umbraco:Macro></div>

    Above is an example of the template markup, now strangley the .NET macro is coming through before "XSLT5" and after <div2>

    I'm not sure what's going on quite, this is an umbraco 4.0.3 instance, (I've changed the macro names to try and explain better what's happening)

    My .NET user control renders on the "onRender" function a HTML table...

    Has anybody seen this before?

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Nov 08, 2010 @ 18:42
    Sebastiaan Janssen
    0

    If you add umbDebugShowTrace=true to your querystring, you'll definitely see the order in which the macro's are rendered. My guess is that the mark-up is causing you to see weird ordering. I've seen sort-of the same behaviour if you have accidental self-closing tags in your XSLT. So for example if you have something like this:

    <ul>
     <xsl:for-each select="$someNodeSet">
      <li>
       <xsl:value-of select="data [@alias = 'myAlias']">
      </li>
     </xsl:for-each>
    </ul>

    It is very well possible that the nodeset is empy or your alias is not filled. This will result in either a <ul/> or a <li/> in your output. This causes rendering to fail as it HAS to be something like <ul>something</ul> or <li>something</li>.

    What I do in for-each loops is always first do a count > 0 before I start outputting thing:

    <ul>
     <xsl:if test="count($someNodeSet) != 0">
      <xsl:for-each select="$someNodeSet">
       <xsl:if test="data [@alias = 'myAlias'] != ''">
        <li>
         <xsl:value-of select="data [@alias = 'myAlias']">
        </li>
       </xsl:if>
      </xsl:for-each>
     </xsl:if>
    </ul>

     

     

     

  • Ian Smedley 97 posts 192 karma points
    Nov 09, 2010 @ 09:48
    Ian Smedley
    1

    Hi Sebastiaan,

    You got me thinking on the right tracks, turns out my XSLT was being too clever and messing with the tags, and my .NET user control had missed a  tag off, I went to looking at the source code of the page, rather than the DOM tools, and noticed where things were going wrong, instead of calling 2 XSLT macro's and a .NET usercontrol, I have brought the simple functionality of the two XSLT macros inside the .NET usercontrol, and everything is rendering properly again.

    Cheers!

    Ian.

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft