Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#121 2012-10-02 21:45:27

etc
Developer
Registered: 2010-11-11
Posts: 5,194
Website GitHub

Re: etc_query: all things Textpattern

mrtunes wrote:

hello! how do i filter out a string from items? let’s say the word HELLO DOLLY appeared in each item and I don’t want it there.

There are many solutions, the optimal way depends on your query. In this example

<txp:etc_query
  url="http://forum.textpattern.com/extern.php?type=RSS&action=new&fid=79"
  markup="xml"
  query="//channel/item[position()<6]"
  wraptag="dl"
  replace=".//text()?={$str_replace(wet|smd|{?})}"
  label="News from Textpattern Forum" labeltag="h4">
    <dt><a href="{link?}">{$str_replace(write|read|{title?})}</a></dt>
    <dd>{description?}</dd>
</txp:etc_query>

we globally replace wet by smd inside each item, and display title with write replaced by read.

Offline

#122 2012-10-08 18:02:24

feragnoli
Member
From: the hague
Registered: 2005-02-10
Posts: 150

Re: etc_query: all things Textpattern

hello,
would it be possible to use etc_query to paginate through articles sorted by category?
(output link_to_prev and link_to_next links according to position of viewed article)


what was that again…?

Offline

#123 2012-10-08 18:12:45

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: etc_query: all things Textpattern

feragnoli, while we wait to see if it’s possible with etc_query, you could give a try to smd_horizon.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#124 2012-10-08 18:17:22

etc
Developer
Registered: 2010-11-11
Posts: 5,194
Website GitHub

Re: etc_query: all things Textpattern

Hello,

I think yes, but do not v.4.5 link_to_prev and link_to_next respect the sort order? Otherwise you could adapt this tip.

Offline

#125 2012-10-20 16:22:36

etc
Developer
Registered: 2010-11-11
Posts: 5,194
Website GitHub

Re: etc_query: all things Textpattern

Version 1.2: if enabled, XSL transforms can be used as replace or content to format the output.

Offline

#126 2012-10-24 20:22:04

Bryon
Member
From: St. Louis, USA
Registered: 2012-10-24
Posts: 11

Re: etc_query: all things Textpattern

Great plugin etc! I have a question though.

I am trying to display images from within atom feeds but having trouble with locally addressed tags. For example, this feed http://earthquake.usgs.gov/earthquakes/feed/atom/4.5/week is fetched and parsed ok with the following:

<txp:etc_query url="http://earthquake.usgs.gov/earthquakes/feed/atom/4.5/week"
 markup="xml:"
 query="feed/entry[position()<21]"
 wraptag="dl">
<dt><a href="{.//link[1]/@href?}" target="_blank">{title?}</a></dt>
<dd>{summary?}</dd>
</txp:etc_query> 

However, I believe that since the entry is enclosed within a <![CDATA[ ]]> tag I am unable to use concat as described here to append the base url of the feed to the locally addressed img’s. I have tried every combination I can think of and nothing seems to work (I have also been referencing this thread, the help, your site and txtptips.com for clues and examples) Any idea’s?

Offline

#127 2012-10-25 08:18:37

etc
Developer
Registered: 2010-11-11
Posts: 5,194
Website GitHub

Re: etc_query: all things Textpattern

Thank you, Bryon. You are right, CDATA is just plain text for XML, so it is not parsed. Actually, etc_query has an undocumented option to jailbreak CDATA, but I have commented it out in v.1.2.1, since nobody ever needed it. If markup ends with *, etc_query will simply replace <![CDATA[ and ]]> patterns with <!---->.

Now it’s enabled again, so, if you download v.1.2.2, and call etc_query with markup="xml*:", you should be able to access nodes even within CDATA sections as usually. But {summary?} will then become just plain text, replace it with {summary/node()} or {summary/p} if you want to keep tags inside ex-CDATA.

Edit: if someone knows a better way to access “tags” inside CDATA (seems impossible with XPath), (s)he is more than welcome to share.

Reedit: another option is to replace summary CDATA by its (parsed) content, by adding replace="summary={?}" attribute:

<txp:etc_query url="http://earthquake.usgs.gov/earthquakes/feed/atom/4.5/week"
 markup="xml:"
 query="feed/entry[position()<21]"
 replace="summary={?}"
 wraptag="dl">
...
</txp:etc_query>

Last edited by etc (2012-10-25 13:22:46)

Offline

#128 2012-10-25 09:35:57

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: etc_query: all things Textpattern

Oleg, could you give an example with JSON? Trying to parse this feed http://www.bom.gov.au/fwo/IDN60901/IDN60901.95766.json

Offline

#129 2012-10-25 09:57:52

etc
Developer
Registered: 2010-11-11
Posts: 5,194
Website GitHub

Re: etc_query: all things Textpattern

nardo, something like this?

<txp:etc_query url="http://www.bom.gov.au/fwo/IDN60901/IDN60901.95766.json"
 markup="json"
 query="observations/data/*"
 wraptag="ol" break="li">
    Lat: {lat?}, Lon: {lon?}
</txp:etc_query>

Edit: lat and lon are all equal, though, rather replace them with wind_spd_kmh and wind_spd_kt.

Last edited by etc (2012-10-25 10:14:52)

Offline

#130 2012-10-25 17:14:16

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: etc_query: all things Textpattern

Thanks – fantastic plugin
Now having a bash at parsing a HTML page …

Offline

#131 2012-10-25 17:25:33

etc
Developer
Registered: 2010-11-11
Posts: 5,194
Website GitHub

Re: etc_query: all things Textpattern

Glad it helps, and feel free to query/feedback me if necessary.

Offline

#132 2012-10-25 21:04:14

Bryon
Member
From: St. Louis, USA
Registered: 2012-10-24
Posts: 11

Re: etc_query: all things Textpattern

Thank you very much etc! You are the man! For posterity here is the final working feed (using concat):

<txp:etc_query url="http://earthquake.usgs.gov/earthquakes/feed/atom/4.5/week"
  markup="xml:"
  query="feed/entry[position()<21]"
  replace="summary={?}"
  wraptag="dl">

<dt><a href="{.//link[1]/@href?}" target="_blank">{title?}</a></dt>
<dd>
<div class="m5-wrap">
<div class="m5-img"><img src="{concat('http://earthquake.usgs.gov',.//summary//img/@src)}" /></div>
<div class="m5-summary">{summary/p}</div>
</div>
</dd>

</txp:etc_query>

Last edited by Bryon (2012-10-25 21:12:56)

Offline

Board footer

Powered by FluxBB