Chryzo's Notepad

April 18, 2009

WordPress Xslt Processor plugin – follow up

Filed under: PHP — Tags: , , — Chryzo @ 08:05

So, a user of the plugin asked me on how to make the plugin also have parameters for the xsl file. And I ended up coding it because it seemed simpler that way.

This this post servers as much as a test bed as a presentation of the different kind of options one can use:

So lets start with the most basic way to use this plugin:

Use:

[XmlProcessor wp-content/plugins/CPT_XslProcessor/example]

Result

[XmlProcessor wp-content/plugins/CPT_XslProcessor/example]

or:

[XmlProcessor xml=”wp-content/plugins/CPT_XslProcessor/example.xml” xslt=”wp-content/plugins/CPT_XslProcessor/example.xsl”]

Result:

[XmlProcessor xml="wp-content/plugins/CPT_XslProcessor/example.xml" xslt="wp-content/plugins/CPT_XslProcessor/example.xsl"]

Now, lets say you want to add options to the xsl file:

Use:

[XmlProcessor wp-content/plugins/CPT_XslProcessor/example params=”default_param=this is the replaced default parameter”]

Result:

[XmlProcessor wp-content/plugins/CPT_XslProcessor/example params="default_param=this is the replaced default parameter"]

or:

[XmlProcessor xml=”xml_filepath” xslt=”xslt_filepath” params=”default_param=this is the replaced default parameter”]

Result:

[XmlProcessor xml="wp-content/plugins/CPT_XslProcessor/example.xml" xslt="wp-content/plugins/CPT_XslProcessor/example.xsl" params="default_param=this is the replaced default parameter"]

And that should actually be working now :)

5 Comments »

  1. Great plugin! One question – is there any way of passing in XML files that do not reside on the same server? eg: http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml

    Comment by jdbrew — August 9, 2010 @ 12:07

  2. Hello,
    Sorry for the late reply, was out of the net for a while :)

    Yes it is possible if you modify the code of the processor. At the moment the path is hardcoded on line 126, it can be made so that if the http:// string is present in the xml / xsl file path then said path is not modified.
    It would go something like this:
    If http:// is present in $xml then do nothing, otherwise, $xml = $path.$xml
    if http:// is present in $xsl then do nothing, otherwise, $xsl = $path.$xsl

    The modification necessary should be around line 126/127

    Hope it helps,

    Comment by Chryzo — August 15, 2010 @ 09:07

  3. Great plugin!!! Thank’s!
    Problem in ABSPATH.
    Replace [$xml = $path . $xml;] to [$xml = $xml;] or delete this string if XML located in external source and
    replace [$xslt = $path.$xslt;] to [$xslt = $xslt;] or delete this string if XSL located in external source.
    Don’t forget [http://] before filepath.

    Comment by Debrain — October 6, 2010 @ 14:38

  4. How would I write that code if I wanted to change the XML web address for different posts? What I’m looking to do is take an already published XML url and parse it into a HTML table in a post. Will this plugin work for me? I’m not a php guy, so if you could help me with any edits, I’d really appreciate it.

    Comment by calboy69 — October 9, 2010 @ 07:59

  5. hello, Happy New Year

    I am French and my PHP knowledge is limited …

    I have the same concern that jdbrew,

    you could write code in php by example in your answer jdbrew.

    cordially

    Comment by hypo — January 10, 2011 @ 17:13

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress