views:

38

answers:

1

One common thing to want to do in the Yahoo Pipes YQL element is pass in a Pipes value to the YQL query. For example:

select * from html.tostring where url='<someurl>' and xpath='//div[@id="foo"]'

and you want to pass in a dynamic value for <someurl>. Let's say that it's an RSS feed item's URL called item.link. Attempting to simply replace the quoted someurl with item.link gives you this error:

Invalid identifier item.link. me is the only supported identifier in this context

How can I pass this value in?

+2  A: 

You'll need to create a separate Pipe that takes the item URL as user input, passes it into a string builder which substitues the actual URL value into the YQL query string, and pass that as input to the YQL widget. Then in your main pipe, pass the item.link value as the input to your subpipe.

Specifically:

  1. Create a User inputs -> URL Input item. You can give it any name and prompt. It's helpful to set the "Debug" value for testing.

  2. Create a String builder, with 3 fields. In the first field, put the string up to where the value should be substituted. In the example in the question, select * from html.tostring where url='. In the second field, connect the output from the URL input element to here. In the third field, add the rest of the output: ' and xpath='//div[@id="foo"]'. When the string is built, it will be a complete YQL query string, with the provided URL substituted in.

  3. Create a YQL element, and connect the output from the string builder to the query field.

  4. Connect the YQL elements output to the Pipe Output element.

Save your new pipe.

In your main pipe, create an element of your new pipe (My Pipes -> whatever-you-named-it). Typically you'll be dragging it into a Loop element. Set the input to be item.link and you'll get the proper output.

Joe Shaw