Copied to clipboard

Flag this post as spam?

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


  • Matt Salmon 22 posts 43 karma points
    Oct 21, 2010 @ 13:03
    Matt Salmon
    0

    Fetching a URL from a content picker on a specific page

    Hi,

    I'm trying to render the value of a URL from a content picker on a specific page (the root / home node) via XSLT.

    My XSLT looks something like this

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
    <xsl:variable name="homeId" select="$currentPage/ancestor-or-self::* [@level=1]/@id"/>

    <xsl:template match="/">
    <a class="voucher">
      <xsl:attribute name="href">
        <xsl:value-of select="umbraco.library:NiceUrl(umbraco.library:GetXmlNodeById($homeId)/*[@alias='giftVoucherLink'])"/>
      </xsl:attribute>
      <span>Buy a gift Voucher</span></a>
    </xsl:template>

    When I try to save the XSLT file, I get the following error:

    System.OverflowException: Value was either too large or too small for an Int32.

    So I suspect one of my arguments is of the wrong type. Can anyone shed any light on what I'm doing wrong?

    Thanks,

    Matt

  • Bas Schouten 135 posts 233 karma points
    Oct 21, 2010 @ 13:10
    Bas Schouten
    0

    Hi Matt,

    I think you have to insert a extra if?

    <xsl:if test="$homeId != '' ">

    </xsl:if>

    This topic has the same solution. http://our.umbraco.org/forum/developers/xslt/3102-Using-niceurl--Value-was-either-too-large-or-too-small-for-an-Int32-

    Cheers,

    Bas

  • Matt Salmon 22 posts 43 karma points
    Oct 21, 2010 @ 16:45
    Matt Salmon
    0

    Hi, I tried wrapping this 'if' block around the whole anchor element and still got the same error. Is that where you meant? ie

    <xsl:template match="/">
    <xsl:if test="$homeId != '' ">
      <a class="voucher">
      <xsl:attribute name="href">
        <xsl:value-of select="umbraco.library:NiceUrl(umbraco.library:GetXmlNodeById($homeId)/*[@alias='giftVoucherLink'])"/>
      </xsl:attribute>
      <span>Buy a gift Voucher</span></a>
    </xsl:if>
    </xsl:template>

    I'm confused about this suggested solution for 2 reasons

    1) The error occurs at the point I'm trying to save the XSLT in the back-end. Surely the 'if' statement is more of a run-time check when the XSLT engine actually kicks in?

    2) Why would the ID of the root node ever be empty anyway? I've got another, similar template which iterates through all the related links on the homepage based on the same ID variable and it works perfectly:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($homeId)/* [name() = $propertyAlias and not(@isDoc)]/links/link">

    What is the requirement for the 'NiceUrl' method? Am I trying to pass the wrong type of argument in?

  • Rich Green 2246 posts 4008 karma points
    Oct 21, 2010 @ 16:54
    Rich Green
    0

    This has been covered many, many times. (try searching Umbraco Value was either too large or too small for an Int32)

    This is a great description on the error by Doug Robar here http://forum.umbraco.org/yaf_postst3143_redirect.aspx

    (Copied here, in case the old forum disappears from google forever)

    "Yes, that's more or less the idea. What happens is that umbraco compiles and tests your xslt against some of the published nodes in your site. Depending on what your xslt does, and the nodes it gets tested against, you can get runtime errors. These aren't compile errors per se, and the xslt might run just great when used properly within your site. 

    This situation doesn't happen all that often, but when it does, you want a way to disable the "compile and test" that happens when you save your xslt. There are two ways to do that. One is to put a checkmark in the "skip testing" box. Your xslt will be saved and you can try it in your site to see if it runs properly. But the next time you open the xslt file you'll have to remember to tick that checkbox again. To bypass that process, the xsl:if scenario is used.

    Obviously, the compile and test check saves a lot of time for most error, but it isn't bullet-proof. For those situations in which you know your xslt is right, either tick the skip testing box or use the xsl:if. 

    cheers,
    doug."

     

    You are also probably getting problems as you're mixing pre 4.5 code with 4.5 code, there is no @alias in 4.5

    (umbraco.library:GetXmlNodeById($homeId)/*[@alias='giftVoucherLink'])

    Rich

  • Bas Schouten 135 posts 233 karma points
    Oct 21, 2010 @ 17:03
    Bas Schouten
    0

    Hi Matt,

     

    I think you need this:

    <a href="{umbraco.library:NiceUrl(umbraco.library:GetXmlNodeById($homeId)/giftVoucherLink)}">Your link name</a>

    Cheers,

    Bas

  • Matt Salmon 22 posts 43 karma points
    Oct 21, 2010 @ 17:04
    Matt Salmon
    0

    OK, thanks. That description from Doug helps clarify things no end, but you're right rich I was mixing my XML structure. This now works without problems:

    <xsl:param name="currentPage"/>
    <xsl:variable name="homeId" select="$currentPage/ancestor-or-self::* [@level=1]/@id"/>

    <xsl:template match="/">
     <a class="voucher">
      <xsl:attribute name="href">
        <xsl:value-of select="umbraco.library:NiceUrl(umbraco.library:GetXmlNodeById($homeId)/giftVoucherLink)"/>
      </xsl:attribute>
     <span>Buy a gift Voucher</span></a>
    </xsl:template>

    It's quite difficult for those that are learning both Umbraco and XSLT together to figure out which forum posts relate to which versions of the XML schema, but at least once you'd pointed me in the right direction it was easy enough to rectify.

    Thanks

  • Rich Green 2246 posts 4008 karma points
    Oct 21, 2010 @ 17:13
    Rich Green
    0

    Glad you got it sorted Matt.

    I agree that it can be difficult with all the old posts, this due to before 4.5 there was no other schema, so it was never mentioned.

    If you see @alias or nodeTypeAlias it's old, if you see * or name() or [isDoc] it's new

    Good post here on the new and old schema http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/no-more-@nodetypealias

    Sounds like you're getting your head around it all, it'll be second nature soon :)

    Rich

Please Sign in or register to post replies

Write your reply to:

Draft