Copied to clipboard

Flag this post as spam?

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


  • Mark Olbert 87 posts 117 karma points
    Nov 03, 2009 @ 17:09
    Mark Olbert
    0

    Converting String Parameter Value to Number

    I'm trying to write some xslt that will display a link only if a user is in a particular role. However, I can't get even this basic stub to work (header/preamble omitted)

    <xsl:variable name="pageID" select="/macro/pageID"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->
        <a href="{umbraco.library:NiceUrl(number($pageID))}">Hi There!</a>
    </xsl:template>

    Whenever I try to save this I get a "System.OverflowException: Value was either too large or too small for an Int32" error. Yet if I change the offending line to

    <a href="{umbraco.library:NiceUrl(1212)}">Hi There!</a>

    It saves just fine...but it's not very useful :).

    I've also tried:

    <xsl:variable name="pageID" select="number(/macro/pageID")/>

    and

    <a href="{umbraco.library:NiceUrl(<xsl:value-of select='number($pageID)')}">Hi There!</a>

    which don't work either.

    What am I doing wrong?

    - Mark

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Nov 03, 2009 @ 17:31
    Thomas Höhler
    0

    does the xslt save when you check the Skip testing checkbox? and is it runnung fine then?

    If so it is the following problem: when the xslt is beeing saved it will be checked against the first node in the content. If this nodes does not contain then macro property it will give you the error that it is not a number. So just wrap an if test around and this will be fine:

    <xsl:if test="$pageId != ''">
    <a href="{umbraco.library:NiceUrl(number($pageID))}">Hi There!</a>
    </xsl:if>

    hth, Thomas

     

  • Mark Olbert 87 posts 117 karma points
    Nov 04, 2009 @ 00:46
    Mark Olbert
    0

    That did it, thanks!

    - Mark

Please Sign in or register to post replies

Write your reply to:

Draft