Copied to clipboard

Flag this post as spam?

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


  • Mike 81 posts 101 karma points
    Dec 14, 2011 @ 18:33
    Mike
    0

    XSLT is not seeing the home node

    I did the navi episode for CWS and I implemented it into my site. However the xslt was getting the following error

     

    Error occured

    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    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)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    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)

     

    I narrowed it down to this line

    <a href="{umbraco.library:NiceUrl($homeNode/@id)}">

    Then I figured out that there is not any data coming back - $homeNode/@id

    <!-- Root Node -->
    <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::root" />

    <!-- Homepage -->
    <xsl:variable name="homeNode" select="$rootNode/Home [@isDoc]" />

    My Root Node is "Home"

    What else can I look at to see why data is not being found?

    Thanks for any help

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Dec 14, 2011 @ 18:56
    Jan Skovgaard
    0

    Hi Mike

    It's because the value of the passed id is not known untill runtime. When you edit the XSLT file inside Umbraco you should be able to "fix" this by checking the "skip error checking" box before you hit the save button.

    If you edited the file outside of Umbraco using an external editor this error would not occur.

    /Jan

  • Mike 81 posts 101 karma points
    Dec 14, 2011 @ 19:03
    Mike
    0

    Thanks for the Reply Jan. IF I add the line -<a href="{umbraco.library:NiceUrl($homeNode/@id)}">- back in, I get this error "Error parsing XSLT file".

    IF I remove <a href="{umbraco.library:NiceUrl($homeNode/@id)}"> and add in something along the lines of <xsl:value-of select="$homeNode/@nodeName" /> + <xsl:value-of select="$homeNode/@id" /> + <xsl:value-of select="$homeNode" /> It does not return any data. I believe the the NiceUrl Method is choking because an ID is not being passed even at runtime.

    Which I am trying to understand why the xpath is not working with these two lines

    <!-- Root Node -->
    <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::root" />

    <!-- Homepage -->
    <xsl:variable name="homeNode" select="$rootNode/Home [@isDoc]" />

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Dec 14, 2011 @ 19:08
    Jan Skovgaard
    0

    Hi Mike

    Ah sorry, I simply just skimmed the post before. My bad.

    Instead of using the root axe try doing this instead

    <xsl:variable name="homeNode" select="umbraco.library:NiceUrl($currentPage/ancestor-or-self::Home/@id)" />

    <a href="{$homeNode}"/>link</a>

    /Jan

  • Mike 81 posts 101 karma points
    Dec 14, 2011 @ 19:26
    Mike
    0

    No Worries Jan! However I am still getting an XSLT parsing error. It's like it cannot find "Home". The top nav xslt example however IS working

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Dec 14, 2011 @ 20:05
    Jan Skovgaard
    0

    Hi Mike

    What is the name of the document type of your homepage? Is it named Home? Or does it have another name? And what version of Umbraco are you using?

    /Jan

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 14, 2011 @ 21:50
    Kim Andersen
    0

    Hi Mike

    As Jan asks, what's the name of your document type that Home is based on?

    When you are writing your XPATH, you need to use the name of the document type, and not the node name. You could use the node name if you want to by doing somthing like this:

    /*[@nodeName='Home']

    Anyway, I'd suggest that you are using the document type alias, as the noge name might change some day, and then the code wouldn't work anymore.

    /Kim A

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Dec 14, 2011 @ 21:58
    Chriztian Steinmeier
    0

    If you want to generically select the website "root", go upwards from $currentPage until you reach level 1:

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

    No mater where you are in the site, you can get to the top this way - the level attribute is always called that, and if you have multiple sites in the same installation, you won't accidentally end up in another language or (God forbid!) another product catalogue :-)

    /Chriztian

  • Mike 81 posts 101 karma points
    Dec 14, 2011 @ 22:37
    Mike
    0

    Kim and Chriztian, you both rock! Kim you explained to me how the nodes work (it was homePage!! ) and Chriztian you told me a great way to make sure I am at the top for mulitple sites and the reason why my topnav was working and the left nav was not!

    Thanks to both of you!!!

  • Mike 81 posts 101 karma points
    Dec 14, 2011 @ 23:24
    Mike
    0

    Okay, I totally get how it's supposed to work but it's still throwing an error. Below is all of the XSLT 

    <?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:variable name="level" select="1"/>
      <xsl:template match="/">
     
        <!-- Homepage -->
        <xsl:variable name="homeNode" select="umbraco.library:NiceUrl($currentPage/ancestor-or-self::*[@level = $level])" />
       
       
        <!-- Create the link -->
              <a href='{$homeNode}'>link</a>
      </xsl:template>
    </xsl:stylesheet>

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Dec 14, 2011 @ 23:27
    Jan Skovgaard
    0

    Hi Mike

    Seems like you forget the @id here.

    <xsl:variable name="homeNode" select="umbraco.library:NiceUrl($currentPage/ancestor-or-self::*[@level = $level]/@id)" />

    That should do it.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft