| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|---|
| 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|---|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml">
|
|---|
| 4 | <head>
|
|---|
| 5 | <script src="http://code.jquery.com/jquery-1.2.1.js" type="text/javascript">
|
|---|
| 6 | </script>
|
|---|
| 7 | <title></title>
|
|---|
| 8 | </head>
|
|---|
| 9 | <body>
|
|---|
| 10 | <pre id="output">
|
|---|
| 11 | Here's the XML:
|
|---|
| 12 |
|
|---|
| 13 | <translation>
|
|---|
| 14 | <sentence>
|
|---|
| 15 | <key>test</key>
|
|---|
| 16 | <value>Hi, I am a test sentence</value>
|
|---|
| 17 | </sentence>
|
|---|
| 18 | <sentence>
|
|---|
| 19 | <key>test_explanation</key>
|
|---|
| 20 | <value>Hi, I am the test explanation</value>
|
|---|
| 21 | </sentence>
|
|---|
| 22 | <sentence>
|
|---|
| 23 | <key>contestable</key>
|
|---|
| 24 | <value>Hi, I am a totally extraneus text</value>
|
|---|
| 25 | </sentence>
|
|---|
| 26 | </translation>
|
|---|
| 27 | </pre>
|
|---|
| 28 | <script type="text/javascript">
|
|---|
| 29 | //<![CDATA[
|
|---|
| 30 | xml_test = '<translation>';
|
|---|
| 31 | xml_test += '<sentence><key>test<\/key><value>Hi, I am a test sentence<\/value><\/sentence>';
|
|---|
| 32 | xml_test += '<sentence><key>test_explanation<\/key><value>Hi, I am the test explanation<\/value><\/sentence>';
|
|---|
| 33 | xml_test += '<sentence><key>contestable<\/key><value>Hi, I am a totally extraneus text<\/value><\/sentence>';
|
|---|
| 34 | xml_test += '<\/translation>';
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | $('#output').append(
|
|---|
| 38 | '<br />jQuery string <b>' + 'sentence key:contains(test)' + '<\/b> returns ' +
|
|---|
| 39 | $('sentence key:contains(test)',xml_test).size()
|
|---|
| 40 | + ' nodes'
|
|---|
| 41 | );
|
|---|
| 42 |
|
|---|
| 43 | jQuery.extend(jQuery.expr[":"], {
|
|---|
| 44 | equals: "(a.textContent||a.innerText||jQuery(a).text()||'')==m[3]"
|
|---|
| 45 | });
|
|---|
| 46 | $('#output').append('<br /><br />Added new exact-match selector:<br />equals: "(a.textContent||a.innerText||jQuery(a).text()||\'\')==m[3]"<br />');
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | $('#output').append(
|
|---|
| 50 | '<br />jQuery string <b>' + 'sentence key:equals(test)' + '<\/b> returns ' +
|
|---|
| 51 | $('sentence key:equals(test)',xml_test).size()
|
|---|
| 52 | + ' nodes<br />'
|
|---|
| 53 | );
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | $('#output').append(
|
|---|
| 57 | '<br />jQuery string <b>' + 'sentence:has(key:equals(test))>value' + '<\/b> returns: ' +
|
|---|
| 58 | $('sentence:has(key:equals(test))>value',xml_test).text()
|
|---|
| 59 |
|
|---|
| 60 | );
|
|---|
| 61 |
|
|---|
| 62 | //]]>
|
|---|
| 63 | </script>
|
|---|
| 64 | </body>
|
|---|
| 65 | </html>
|
|---|