Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Aug 16, 2011 @ 19:14
    Claushingebjerg
    0

    How to use GetNodeIdByUrl(String)?

    Im trying to get a page id from a url on my site. The reason is i need to know the id of the referring page, so combining 

    umbraco.library:RequestServerVariables('http_referer')

    With

    <xsl:value-of select="ucomponents.urls:GetNodeIdByUrl('url')"/>

    Would enable me to do this...

    But whatever i pass to GetNodeIdByUrl(String) returns this error

    System.Xml.XPath.XPathException: Expression must evaluate to a node-set. 
    at MS.Internal.Xml.XPath.XPathParser.ParseNodeTest(AstNode qyInput, AxisType axisType, XPathNodeType nodeType) 
    at MS.Internal.Xml.XPath.XPathParser.ParseStep(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseLocationPath(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParsePathExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseUnionExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseUnaryExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseMultiplicativeExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseAdditiveExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseRelationalExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseEqualityExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseAndExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseOrExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParsePredicate(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseStep(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseLocationPath(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParsePathExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseUnionExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseUnaryExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseMultiplicativeExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseAdditiveExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseRelationalExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseEqualityExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseAndExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseOrExpr(AstNode qyInput) 
    at MS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(String xpathExpresion) 
    at System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver) 
    at System.Xml.XPath.XPathNavigator.Select(String xpath) 
    at System.Xml.XmlNode.SelectNodes(String xpath) 
    at System.Xml.XmlNode.SelectSingleNode(String xpath) 
    at uComponents.Core.XsltExtensions.Nodes.GetNodeIdByUrl(String url) 
    at uComponents.Core.XsltExtensions.Urls.GetNodeIdByUrl(String url)
  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Aug 16, 2011 @ 19:38
    Lee Kelleher
    0

    Hi Claushingebjerg,

    The "GetNodeIdByUrl" extension doesn't work with absolute URLs (ones that start with "http://") ... it was intended to work with the URL's path - anything after the TLD (e.g. ".com") from the forward-slash onwards.

    I've tested a few variations, but didn't get any errors/exceptions.  For the URLs that it couldn't find, it just returned a "-1".

    What values are you getting for "http_referer"?  I'd like to replicate this error - so we can fix it. :-)

    Cheers, Lee

  • Claushingebjerg 939 posts 2574 karma points
    Aug 16, 2011 @ 20:19
    Claushingebjerg
    0

    Well actually im not even using the 'http_referer' yet

    Heres what i have

     <xsl:value-of select="ucomponents.urls:GetNodeIdByUrl('gaver.aspx')"/>

    where gaver.aspx is a page with the id of 1061. But i get the above error

    Ive tried with

    gaver.aspx

    '/gaver.aspx'

    /gaver.aspx

    But the all return the same error. 

    What throws me, is the error about a node-set?!?! why would it need a node-set

     

    could i have included the extension wrong??? i have:

     xmlns:ucomponents.urls="urn:ucomponents.urls"
     exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ucomponents.urls ">
     
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Aug 16, 2011 @ 21:54
    Chriztian Steinmeier
    0

    Hi Claus,

    I just tried it and got the error on the first run, but subsequently couldn't reproduce it...

    I *think* the error might have something to do with returning just a number where the XSLT processor expects to output an XML document - do you get the error when assigning the value to a variable as well? E.g.:

    <xsl:variable name="nodeId" select="ucom:GetNodeIdByUrl('gaver.aspx')" />

    (For working URLs I found that all versions with or without leading/trailing slashes; with or without '.aspx' reliably returned the right Id)

    /Chriztian

  • Claushingebjerg 939 posts 2574 karma points
    Aug 17, 2011 @ 08:34
    Claushingebjerg
    0

    Hmmmm maybe it needed an app pool recycle.

    It Worked this morning without changing at thing?!?!?

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Aug 17, 2011 @ 09:25
    Lee Kelleher
    0

    Glad that it's working now. Strange that you both got errors with it - I couldn't reproduce the error with my tests.

    Best to keep an eye on it and let me know if anything strange happens again - we'll try to get a fix in place.

    Cheers, Lee.

  • 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