Skip to content
Browse files

added example of manipulating query results in an execute block

  • Loading branch information...
1 parent 9626019 commit 533d383c1f9885d631fcafabe58b0d9c6451547d @salathe salathe committed Jul 27, 2010
Showing with 33 additions and 0 deletions.
  1. +33 −0 tmdb/jp.xml
View
33 tmdb/jp.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <sampleQuery>select * from {table} where movieid="27205"</sampleQuery>
+ <description>Retrieve movie title and year from TMDB. See http://stackoverflow.com/questions/3292899/tailoring-the-output-of-yql</description>
+ <author>Peter Cowburn</author>
+ </meta>
+ <bindings>
+ <select itemPath="movie" produces="XML">
+ <inputs>
+ <key id="movieid" type="xs:string" paramType="variable" required="true"/>
+ </inputs>
+ <execute><![CDATA[
+var query = 'select content from html where url="http://www.themoviedb.org/movie/'
+ + movieid + '" and xpath=\\'//h3[@id="year"]|//h2[@id="title"]/a\\'';
+
+var result = y.query(query).results;
+var movie = <movie/>;
+
+// The title can span multiple lines, lets remove breaks.
+var title = result.a.text().toString().replace(/\\s+/g, ' ');
+
+// The year has parentheses around it, let's remove those.
+var year = result.h3.text().toString().replace(/^\\(|\\)$/g, '');
+
+movie.node += <title>{title}</title>;
+movie.node += <year>{year}</year>;
+
+response.object = movie;
+]]></execute>
+ </select>
+ </bindings>
+</table>

0 comments on commit 533d383

Please sign in to comment.
Something went wrong with that request. Please try again.