Copied to clipboard

Flag this post as spam?

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


  • Lee 95 posts 115 karma points
    Oct 20, 2013 @ 04:36
    Lee
    0

    Need help with NiceUrl

    Hi

    I am trying to create a back link on a page, so I have set up a property which is a content picker.

    I have then created an xslt and trying to grab the property that has been set and input into a nice url. An example of my code would be:

     

     

    <div class="tmpl4rtn">
    <ul>
    <li>
    <a>
    <xsl:variable name="link" select="umbraco.library:GetXmlNodeById($currentPage/returnLink)/@id"/>
    <xsl:attribute name="href">
    <xsl:value-of select="umbraco.library:NiceUrl(umbraco.library:GetXmlNodeById($currentPage/returnLink)/*[@isDoc][1]/@id)"/>
    </xsl:attribute>
    <xsl:value-of select="concat('&#171; ', umbraco.library:GetXmlNodeById($currentPage/returnLink)/@nodeName)"/>
    </a>
    </li>
    </ul>
    </div>

    but doing this returns the error:

     

    Error occured
    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

     

    Could anybody help me please?

    Thankyou

     

     

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Oct 20, 2013 @ 09:34
    Chriztian Steinmeier
    1

    Hi Lee,

    You're getting this error when you save the XSLT file in the backoffice, because Umbraco executes your macro to test for some basic XML errors - at that point, $currentPage is not set to any page in your site, so any call to GetXmlNodeById() or NiceUrl() will fail because there's no node to take the @id attribute from. Furthermore, you're also making the assumption that the page referenced in the returnLink property will have at least one childnode, which you're trying to link to - that could easily fail if you're not careful which pages the macro will be running on.

    If you check the "Ignore errors" checkbox, you can save the file and it will probably work fine on the website, however - it's much better to add some basic error handling inside the XSLT, by not calling those functions, unless there's an actual node available:

    <!-- Do we have a returnLink? -->
    <xsl:if test="normalize-space($currentPage/returnLink)">
        <div class="tmpl4rtn">
            <!-- Grab a reference to the node and its first child -->
            <xsl:variable name="returnPage" select="umbraco.library:GetXmlNodeById($currentPage/returnLink)" />
            <xsl:variable name="firstChild" select="$returnPage/*[@isDoc][1]" />
            <!-- Is there a firstChild node? -->
            <xsl:if test="$firstChild">
                <ul>
                    <li>
                        <a href="{umbraco.library:NiceUrl($firstChild/@id)}">
                            <xsl:value-of select="concat('&#171; ', $returnPage/@nodeName)" />
                        </a>
                    </li>
                </ul>
            </xsl:if>
        </div>
    </xsl:if>
    

    Also, note how much easier it is to see what's going on by adding a few variables...

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft