0

I have the following xpath that I need to run, but Jquery doesn't support the functions....so how can i actually make this work in jquery ?

$("//*[br]/text()[string-length(normalize-space()) != 0]").each( ....

3 Answers 3

1

Um - modern jQuery doesn't support XPath. jQuery isn't an Xpath parsing utility.

However, I would recommend you actually translate that into jQuery... perhaps something like

$('*[br]').filter(function() {
    var text = $(this).text(), normalized = $.trim( text );
    return normalized.length>0
});

Though you may need an additional regex replacement of multiple whitespace, I'm not quite sure how that xsl/xpath function works.

Sign up to request clarification or add additional context in comments.

2 Comments

Note - I assumed *[br] was any element with a 'br' attribute, I assumed you missed the @ before br. Let me know if you actually meant something else instead.
Another sidenote is that some browsers implement the w3 selectors API so if the browser supports that method it will rely on that instead of regular DOm methods. Xpath used to be supported in the old jQuery but I guess it was just too much trouble to maintain both versions and account for all the new functionality.
0

John Resig (the author of jQuery) wrote an Xpath Plugin.

1 Comment

I believe that just supports the basics, not specific functions like string-length of normalized-space.
0

Please check the new compatibility Plugin for JQuery:

http://docs.jquery.com/Release:jQuery_1.2#XPath_Compatibility_Plugin

But keep one thing in mind: "XPath is a language to traverse nodes in XML document during the transformation (look for XSLT)." :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.