Copied to clipboard

Flag this post as spam?

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


  • Sean Parsons 23 posts 38 karma points
    Sep 22, 2009 @ 23:58
    Sean Parsons
    0

    umbraco.library - skip testing...

    Is there any reason why I am not able to compile a macro that has {umbraco.library...} etc in it?

    For example, the line 

    <a href="{umbraco.library:NiceUrl($selectedNode/@id)}" alt="{$selectedNode/@nodeName}">Read more...</a>

    will not compile. If I skip testing, I get the desired output and the link works as expected...

     

    Whole macro:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
        version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library" 
        exclude-result-prefixes="msxml umbraco.library">
    
    
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>
    <xsl:param name="position" select="/macro/position"/>
    
    <xsl:template match="/">
    
    <!-- start writing XSLT -->
    
    <xsl:variable name="selectedNode" select="$currentPage/node[position()=$position]"/>
    
    <a href="{umbraco.library:NiceUrl($selectedNode/@id)}" alt="{$selectedNode/@nodeName}">Read more...</a>
    
    </xsl:template>
    
    </xsl:stylesheet>

    Thanks for any ideas.

    Sean

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Sep 23, 2009 @ 04:21
    Casey Neehouse
    1

    Sean,

    The macro is failing as the position parameter is not set during testing.  Thus, your selectedNode variable fails to get a proper node.

    You can use default values in case the parameter is blank:

    <xsl:variable name="position">
    <xsl:choose>
    <xsl:when test="/macro/position"><xsl:value-of select="/macro/position"/></xsl:when>
    <xsl:otherwise>1</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    Case

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Sep 23, 2009 @ 04:22
    Casey Neehouse
    0

    Another option is to test the selectedNode for an id before using it in NiceUrl.

  • Sean Parsons 23 posts 38 karma points
    Sep 23, 2009 @ 08:16
    Sean Parsons
    0

    Hi Casey, thanks for the response.

     

    I did test my values with the copy-of statement prior to posting, and as I mentioned above,

    'If I skip testing, I get the desired output and the link works as expected...'

     

    In other words, if I place a tick in the 'skip testing' checkbox, the macro saves and works in the published site.

    I was wondering if there was a setting or something else that I needed to do to get the macro parsing/testing working with the umbraco library extensions.

     

    I will take on board the checking for a value as that seems good practice.

    Thanks again.

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Sep 23, 2009 @ 09:46
    Richard Soeteman
    0

    Hi Sean,

    Found this post on the old forum describing why XSLT sometimes throws an error while saving. Usually when I see the message I also press skip testing and test it in the site.

    Cheers,

    Richard

     

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Sep 23, 2009 @ 10:39
    Dave Woestenborghs
    0

    This should solve it

    <xsl:if test="$selectedNode/@id != ''">
    <a
    href="{umbraco.library:NiceUrl($selectedNode/@id)}" alt="{$selectedNode/@nodeName}">Read more...</a>
    </xsl:if>
  • Petr Snobelt 923 posts 1534 karma points
    Sep 23, 2009 @ 10:51
    Petr Snobelt
    0

    umbraco.library:IsLoggedOn sometimes doing same problems, is there any check which helps with it?

  • Sean Parsons 23 posts 38 karma points
    Sep 23, 2009 @ 11:50
    Sean Parsons
    0

    Thanks all,

    I have just read a comment from Dirk on another thread that says:

    (Reason: the parameters passed in don't have a value until runtime, and calling NiceUrl with a number that gets converted from an empty string results in an OverflowException, which is probably the exception message you've received in the 'red rectangle')

    so I have a feeling that dawoe's solution will work. I'm presuming that as $position won't have a value at parse check time, it will mean that $selectedNode will be unassigned so I presume then that the parser will fail without the

    <xsl:if test="$selectedNode/@id != ''">
    ....
    </xsl:if>

    I'll have to test this at home tonight and mark the thread as solved if this works.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies