You are not logged in.
This multipurpose plugin allows you to pick some data, transform it and display the result the way you like. It can query HTML/XML/JSON documents, databases or global variables, and can be useful for
It is in many points inspired by smd_xml and smd_query, but uses XPath to access the desired nodes.
The workflow is: import some data, query it for some nodes with XPath, do some replacements and display the result. For example,
<txp:etc_query data='<txp:body />' replace="//@style" />
in an article form will display the body of the article with all style attributes removed.
<txp:etc_query url="http://textpattern.com" query="//div[@id='accoladesBlock']//img" replace="@width=128">
{.} : {@alt?}
<txp:else />
<p>Nobody here.</p>
</txp:etc_query>
will display all img elements (scaled to width=128) with their alt text found in the div#accoladeBlock on http://textpattern.com.
<txp:etc_query data="SELECT * FROM txp_users WHERE 1" wraptag="ul" break="li">
{$strtoupper({RealName?})}
</txp:etc_query>
will display an uppercase list of all users of your site.
<txp:etc_query name="sqrt" globals="_GET" functions="sqrt" query="sqrt({?num|0|intval})" />
will merely calculate the square root of HTML GET num variable, sanitized as integer, and assign it to <txp:variable name="sqrt" />.
More help and examples in plugin’s help, on TXP Forum thread or plugin home.
Download the latest version.
Last edited by etc (2013-01-23 15:25:55)
Offline
Hi etc,
I’ve upgraded your status as plugin author and moved the topic to the Plugin Author Support forum.
neme.org | neme-imca.org | hblack.net | LABS
Offline
Thank you colak, nice to join the club!
Some snippets:
The article form
<txp:if_individual_article>
<txp:etc_query data="{?body}" query="//h2|//h3|//h4|//h5" label="Table of Contents" labeltag="h1" />
<txp:body />
<txp:else />
<txp:excerpt />
<txp:etc_query data="{?body}" query="//img">
<link rel="prefetch" href="{@src?}" />
</txp:etc_query>
</txp:if_individual_article>
will pre-load the images found in articles’ bodies while viewing the excerpts, and produce a table of contents in the individual article view.
<txp:etc_query data='<txp:comments_form />' query="//textarea[@id='message']" replace="@@required=required@placeholder=Drop us a word" />
will add HTML5 required and placeholder attributes to the message field of the comments form.
<txp:etc_query data="[1..9]" markup="json" break="tr" wraptag="table">
<txp:etc_query data="[1..9]" markup="json" break="td">
{{$*{?}}}
</txp:etc_query>
</txp:etc_query>
<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"
label="News from Textpattern Forum" labeltag="h4">
<dt><a href="{link?}">{title?}</a></dt>
<dd>{description?}</dd>
</txp:etc_query>
More examples: here or here or here.
Last edited by etc (2012-09-09 13:49:34)
Offline
Yes! Thank you very much for this plugin.
Offline
maruchan wrote:
Yes! Thank you very much for this plugin.
Nice to know you find it useful, thank you.
Version 0.4: added remove and separator attributes.
Last edited by etc (2012-04-24 11:25:34)
Offline
Not had a chance to try this yet, but it sounds very intriguing and you’ve given lots of examples in different threads of how it could be of use. Thanks for writing it – it looks like it could be a swiss-army-knife type of plugin.
One thing with the latest change, I’m not sure whether dropping “dom” from the name might lead to misunderstandings, though. There is already smd_query which builds mysql queries. Both plugins now have near identical names but do different things.
Last edited by jakob (2012-04-29 22:21:05)
TXP Builders – finely-crafted code, design and txp
Offline
Version 0.61: minor tweaks to improve usability.
jakob wrote:
Not had a chance to try this yet, but it sounds very intriguing and you’ve given lots of examples in different threads of how it could be of use. Thanks for writing it – it looks like it could be a swiss-army-knife type of plugin.
One thing with the latest change, I’m not sure whether dropping “dom” from the name might lead to misunderstandings, though. There is already smd_query which builds mysql queries. Both plugins now have near identical names but do different things.
Hi jakob, and thank you for the comment. I have hesitated before changing the name (and I don’t like doing it, really), but v0.6 was not fully compatible with v0.5 (still usable, but depreciated). I apologize if it hurts the users, but I don’t believe there are many, the plugin is brand new.
And, concerning smd_query, who knows if one day we couldn’t query a db with xml?
Offline