Skip to content

Instantly share code, notes, and snippets.

@salathe
Created March 8, 2013 22:42
Show Gist options
  • Save salathe/5120512 to your computer and use it in GitHub Desktop.
Save salathe/5120512 to your computer and use it in GitHub Desktop.
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Peter Cowburn</author>
<documentationURL>http://stackoverflow.com/questions/15249380/is-it-possible-to-filter-the-descendant-elements-returned-from-an-xpath-query</documentationURL>
<sampleQuery>select * from {table} where url="http://www.yahoo.com"</sampleQuery>
</meta>
<bindings>
<select itemPath="" produces="XML">
<urls>
<url></url>
</urls>
<inputs>
<key id="url" type="xs:string" paramType="variable" required="true" />
<key id="xpath" type="xs:string" paramType="variable" default="//form[@action]" />
<key id="filter" type="xs:string" paramType="variable" default="descendant::label|descendant::input|descendant::select|descendant::textarea" />
</inputs>
<execute>
<![CDATA[
var elements = y.query("select * from html where url=@u and xpath=@x", {u: url, x: xpath}).results.elements();
var results = <url url={url}></url>;
for each (element in elements) {
var result = element.copy();
result.setChildren("");
result.normalize();
for each (descendant in y.xpath(element, filter)) {
result.node += descendant;
}
results.node += result;
}
response.object = results;
]]>
</execute>
</select>
</bindings>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment