shadowplay Posted September 18, 2012 Share Posted September 18, 2012 I apologize if this is the wrong forum, just wasn't sure where to put this question. I'm trying to return the url from this onclick node: <a onclick=”javascript:getURLWin(‘http://some.web.url/some/path/index.html’); href=”javascript:void(0);”>; here is the block of text which describes the page </a> So far, I've tried td[2]/a/[@onclick=”javascript:getURLWin(‘”;] , and that hasn't worked. Can anyone offer suggestions? Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted September 18, 2012 Share Posted September 18, 2012 Remove the slash before the predicate, and remove the ";", i.e. instead of td[2]/a/[@onclick="javascript:getURLWin('";] make that td[2]/a[@onclick="javascript:getURLWin('"] However, it's important to note that, as written, this would not match "javascript:void(0)". It would only match an "a" element that looks like <a onclick="javascript:getURLWin('"> and that's probably not what you want.I'm guessing you want the attribute that starts with that, which you can do like: td[2]/a[starts-with(@onclick, "javascript:getURLWin('")]/@onclick 1 Link to comment Share on other sites More sharing options...
shadowplay Posted September 25, 2012 Author Share Posted September 25, 2012 I'm sorry for not getting back sooner. I appreciate your response. When I tried this, we seem to get the url, but we also get the 'javascript:getURLWin(', that precedes this. Is there a way to bascially cut the string to only return what comes after the parenthesis? Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted September 25, 2012 Share Posted September 25, 2012 Yes. Surround the whole expression with substring-after(). e.g. substring-after(td[2]/a[starts-with(@onclick, "javascript:getURLWin('")]/@onclick) I assume you'll also want to get rid of the trailing ")". That's a little difficult to get with just XPath 1.0. The best you can do is just remove the last N characters, assuming that they're always that many. For performance, you might want to store the full result before you cut it. If you're using this XPath in XSLT, you can use xsl:variable for that, e.g. <xsl:variable name="url" select="substring-after(td[2]/a[starts-with(@onclick, "javascript:getURLWin('")]/@onclick)" /><xsl:value-of select="substring($url, 0, string-length($url)-2)" /> Link to comment Share on other sites More sharing options...
shadowplay Posted October 11, 2012 Author Share Posted October 11, 2012 Hey, thanks for the help. We got it to work! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now