Copied to clipboard

Flag this post as spam?

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


  • Eran 292 posts 436 karma points
    Jun 14, 2010 @ 20:55
    Eran
    0

    NiceUrl Syntax error

    hello,

    i'm try to use in my sub-navigation xslt macro the following code, that cause error:

    <xsl:variable name="rootTextpageNode" select="$currentPage/ancestor-or-self::node [@level = 2]" />
    <a href="{umbraco.library:NiceUrl($rootTextpageNode[1]/@id)}">

    the second line cause: "System.OverflowException: Value was either too large or too small for an Int32."

    its just a matter of wrong syntax. what is the right syntax?

    Thanks!

  • Eran 292 posts 436 karma points
    Jun 15, 2010 @ 04:13
    Eran
    0

    guys anyone?.. i tried few options without resolts..

    thanks

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Jun 15, 2010 @ 09:20
    Chriztian Steinmeier
    1

    Hi Eran,

    Off the top of my head I'd say you're missing a "node" in the argument to NiceUrl, as your variable holds a set of nodes:

    <a href="{umbraco.library:NiceUrl($rootTextpageNode/node[1]/@id)}">...</a>

    /Chriztian

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Jun 15, 2010 @ 10:27
    Lee Kelleher
    0

    Hi Eran,

    Try dumping out the contents of "rootTextpageNode", see what's in there.

    <xsl:variable name="rootTextpageNode" select="$currentPage/ancestor-or-self::node[@level=2]" />
    
    "$rootTextpageNode" = 
    <xmp>
        <xsl:copy-of select="$rootTextpageNode" />
    </xmp>
    
    "$rootTextpageNode[1]" = 
    <xmp>
        <xsl:copy-of select="$rootTextpageNode[1]" />
    </xmp>
    
    "$rootTextpageNode[1]/@id" = 
    <xmp>
        <xsl:copy-of select="$rootTextpageNode[1]/@id" />
    </xmp>

    The exception from NiceUrl is due to the input value not being an integer ... so lets see what value you are passing to it.

    Cheers, Lee.

  • Mirela Budaes 44 posts 94 karma points
    Jun 15, 2010 @ 12:28
    Mirela Budaes
    0

    I tried you example and it works if you set the value of the variable with the first item and then use the variable.

    <xsl:variable name="rootTextpageNode" select="$currentPage/ancestor-or-self::node[1] [@level = 2]" />
    <a href="{umbraco.library:NiceUrl($rootTextpageNode/@id)}">

  • Eran 292 posts 436 karma points
    Jun 15, 2010 @ 16:14
    Eran
    0

    thanks for your help but still it's not working. i'm attaching the full XSLT:

    the problematic line thta generates error is bolded:

    by the way, the logic is to display a sub-menu that includes also the root parent. for example, is my content tree is look like:

    Home
     -- About
         -- Our Team
         -- Our Philosophy

    and a user click on about, he will a sub-menu that looks like:

    About
    Our Team
    Our Philosophy

    <?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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:call-template name="buildMenu">
    <xsl:with-param name="parentNodeSet" select="$currentPage/ancestor-or-self::node [@level=2 and string(data [@alias='umbracoNaviHide']) != '1']"/>
    <xsl:with-param name="parentNode" select="$currentPage/ancestor-or-self::node[1] [@level=2 and string(data [@alias='umbracoNaviHide']) != '1']" />
    <xsl:with-param name="selectedPage" select="$currentPage"/>
    </xsl:call-template>
    </xsl:template>

    <xsl:template name="buildMenu">
    <xsl:param name="parentNodeSet"/>
    <xsl:param name="parentNode"/>
    <xsl:param name="selectedPage"/>
    <ul id="sidebar-nav" class="clearfix">
    <li id="top">
    <xsl:if test="$selectedPage/@id = $parentNodeSet[1]/@id">
    <xsl:attribute name="class">
    <xsl:text>current</xsl:text>
    </xsl:attribute>
    </xsl:if>


    <a href="{umbraco.library:NiceUrl($parentNode/@id)}">
    <span>
    <xsl:value-of select="$parentNodeSet/data[@alias='contentPageTitle']/text()"/>
    <xsl:if test="string($parentNodeSet/data[@alias='contentPageTitle']/text()) = ''">
    <xsl:value-of select="$parentNodeSet/@nodeName"/>
    </xsl:if>

    </span>
    </a>

    </li>

    <xsl:for-each select="$parentNodeSet/node">
    <li>
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <xsl:attribute name="class">
    <xsl:text>current</xsl:text>
    </xsl:attribute>
    </xsl:if>
    <a>
    <xsl:choose>
    <xsl:when test="string(./@nodeTypeAlias) = 'umbracoRedirect'">
    <xsl:attribute name="href">
    <xsl:value-of select="umbraco.library:NiceUrl(./data[@alias='umbracoRedirect'])" />
    </xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
    <xsl:attribute name="href">
    <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
    </xsl:attribute>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="contains($selectedPage/@path,@id)">
    <xsl:attribute name="class">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName" />
    </a>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

    </xsl:stylesheet>

     

    Thanks!

  • Thomas.R 39 posts 62 karma points
    Jun 15, 2010 @ 17:01
    Thomas.R
    0

    What does it displays If you change to ? An integer, an empty string ?

    <a href="{$parentNode/@id}">

  • Eran 292 posts 436 karma points
    Jun 15, 2010 @ 17:43
    Eran
    0

    when i change it to:

    <a href="{$parentNode/@id}">

    it outpu the nodeid

  • Mirela Budaes 44 posts 94 karma points
    Jun 15, 2010 @ 17:48
    Mirela Budaes
    0

     

    I used you code and the error appears when the parentNode is null.

    So, if you put an if before the link, it works fine:

     

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

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

              <span>

                <xsl:value-of select="$parentNodeSet/data[@alias='contentPageTitle']/text()"/>

                <xsl:if test="string($parentNodeSet/data[@alias='contentPageTitle']/text()) = ''">

                  <xsl:value-of select="$parentNodeSet/@nodeName"/>

                </xsl:if>

              </span>

            </a>

            </xsl:if>

     

     

  • Eran 292 posts 436 karma points
    Jun 15, 2010 @ 17:58
    Eran
    0

    the problem is not null, the problem that :

    when i write:

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

    it generate error, and when i write:

    <a href="{$parentNode/@id}">

    it only output the node id  (instead of the url of the node id).

    thanks.

  • Mirela Budaes 44 posts 94 karma points
    Jun 15, 2010 @ 18:31
    Mirela Budaes
    0

    <a
    href="{$parentNode/@id}">

    should generate the node id. I don't understand why you wrote "(instead of the url of the node id)."

    I tried your xslt code and for me it works if the current node has level 2.

    If level is 1 or 3, the id is empty and the NiceUrl function is called with an empty parameter, which causes the error.

    I'm sorry I can't help you more.

     

     

  • Eran 292 posts 436 karma points
    Jun 15, 2010 @ 19:06
    Eran
    0

    i wrote "instead of the url of the node id" because i mean that i dont need the nodeID - i need the url -->

    because that i try to use the NiceUrl function --> that cause the error --> and because that i wrote this post..

    appreciate your help.

    Eran


  • Gerty Engrie 120 posts 470 karma points c-trib
    Jun 16, 2010 @ 01:06
    Gerty Engrie
    0

    does it also error in the frontend when you hit the checkbox to ignore errors and save?

  • Eran 292 posts 436 karma points
    Jun 16, 2010 @ 01:17
    Eran
    0

    o.k, thanks to Gerty Engrie, the problem is solved: the trick is to mark the ignore errors at the edit xsl pabel (in backend).

    i will be happy to understand why this line cousing parsing error, but for now, this is full xslt that working in frontend:

    the problematic line is bolded.

    <?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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
    <xsl:output method="xml" omit-xml-declaration="yes" />

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:call-template name="buildMenu">
    <xsl:with-param name="parentNodeSet" select="$currentPage/ancestor-or-self::node [@level=2 and string(data [@alias='umbracoNaviHide']) != '1']"/>
    <xsl:with-param name="selectedPage" select="$currentPage"/>
    </xsl:call-template>
    </xsl:template>

    <xsl:template name="buildMenu">
    <xsl:param name="parentNodeSet"/>
    <xsl:param name="selectedPage"/>

    <ul id="sidebar-nav" class="clearfix">
    <li id="top">
    <xsl:if test="$selectedPage/@id = $parentNodeSet[1]/@id">
    <xsl:attribute name="class">
    <xsl:text>current</xsl:text>
    </xsl:attribute>
    </xsl:if>

    <a href="{umbraco.library:NiceUrl($parentNodeSet[1]/@id)}">
    <span>
    <xsl:value-of select="$parentNodeSet/data[@alias='contentPageTitle']/text()"/>
    <xsl:if test="string($parentNodeSet/data[@alias='contentPageTitle']/text()) = ''">
    <xsl:value-of select="$parentNodeSet/@nodeName"/>
    </xsl:if>

    </span>
    </a>

    </li>

    <xsl:for-each select="$parentNodeSet/node">
    <li>
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <xsl:attribute name="class">
    <xsl:text>current</xsl:text>
    </xsl:attribute>
    </xsl:if>
    <a>
    <xsl:choose>
    <xsl:when test="string(./@nodeTypeAlias) = 'umbracoRedirect'">
    <xsl:attribute name="href"><xsl:value-of select="umbraco.library:NiceUrl(./data[@alias='umbracoRedirect'])" /></xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
    <xsl:attribute name="href"><xsl:value-of select="umbraco.library:NiceUrl(@id)" /></xsl:attribute>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="contains($selectedPage/@path,@id)">
    <xsl:attribute name="class">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName" />
    </a>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

    </xsl:stylesheet>

    thanks for all the help.

    Eran.

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Jun 16, 2010 @ 09:13
    Lee Kelleher
    0

    The reason for the error in the back-office XSLT editor is down to NiceUrl is expecting an integer value ... but due to the way "$parentNodeSet" is set, the parser can not be sure what type the value is - and assumes that it is a string value.

    There are 2 ways around it.

    1. Put the value in a number() function - to cast/convert it to an integer:

    <a href="{umbraco.library:NiceUrl(number($parentNodeSet[1]/@id))}">

    2. Wrap an <xsl:if> condition around the link, so if the value is empty it wont render.  The parser then ignores the error.

    <xsl:if test="string($parentNodeSet[1]/@id) != ''>
        <li id="top">
            <xsl:if test="$selectedPage/@id = $parentNodeSet[1]/@id">
                <xsl:attribute name="class">
                    <xsl:text>current</xsl:text>
                </xsl:attribute>
            </xsl:if>
            <a href="{umbraco.library:NiceUrl($parentNodeSet[1]/@id)}">
                <span>
                    <xsl:choose>
                        <xsl:when test="string($parentNodeSet/data[@alias='contentPageTitle']) = ''">
                            <xsl:value-of select="$parentNodeSet/data[@alias='contentPageTitle']"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="$parentNodeSet/@nodeName"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </span>
            </a>
        </li>
    </xsl:if>

    Cheers, Lee.

  • Eran 292 posts 436 karma points
    Jun 16, 2010 @ 12:40
    Eran
    0

    Lee: Thanks for the info. i tried both solution:

    1. the first didn't work (with the number wrap function) - stil generates parsing error.

    2. the second (with the if wrapper) - works like a charm - without parsing error.

     

    thanks.

    Eran.

  • 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