Join 3,363 readers in helping fund MetaFilter (Hide)

Transforming XML with XSL
March 7, 2005 5:01 PM   Subscribe

I need a new way of transforming XML with XSL. Till date I've used PHP's Sablotron, which I absolutely love and is simple to use, but my host keeps forgetting to enable and include it each time they recompile Apache, so I was wondering if someone here knows of a way to do the same with either Perl or JSP/Tomcat or even PHP as long as it is without Sablotron's xslt_create().

The PHP code I use is beautifully simple.

$tivonp = xslt_create();
$result = xslt_process($tivonp, 'nowplaying.xml', 'nowplaying.xsl');
echo $result;

I'm hoping there is a similar simple way to transform XML using XSL in other languages.
posted by riffola to Computers & Internet (10 answers total)
if you have java available, the saxon package will do what you want, i think.
for example, i have saxon aliased to java -jar c:\Archive\Saxon\saxonb8-3\saxon8.jar and then the transform above would be saxon nowplaying.xml nowplaying.xsl > $result (in a command-line-ish syntax). you want the free saxon-b (not saxon-sa).

personally, i use xsltproc. i think it comes from libxsl/gnome or something. it might also be available on your machine and is another stand-alone processor.
posted by andrew cooke at 5:14 PM on March 7, 2005

(you can also call saxon from java if you want, so it could go inside jsp)
posted by andrew cooke at 5:14 PM on March 7, 2005

(and there are other java xslt processors, including one from apache - that might be already installed (xerces, iirc)).
posted by andrew cooke at 5:15 PM on March 7, 2005

Well, so long as you are working with PHP5, XSL support is compiled in by default. You can use this class. I used to use sablotron, and I couldn't imagine going back to it.
posted by chrisroberts at 7:18 PM on March 7, 2005

You can do it client-side, by just specifying the stylesheet at the top of the xml file.

This only works on modern browsers, but it works well.
posted by smackfu at 8:10 PM on March 7, 2005

andrew, thanks for the info about saxon, I don't know Java, but I wanted to learn it, so this is as good a reason as any to start doing so. I'll start reading up on it and hopefully will be able to find a way to use that.

chrisroberts, I can't use libxslt because it's not installed by my host and the server still has PHP 4.3.x

smackfu, I don't generate the XML, so I don't have control over what is in there, and I'd rather just do it server side.

Thanks for tips, I'll look into having my host add libxslt and read more about JSP and Saxon.
posted by riffola at 9:03 PM on March 7, 2005

This may work for you as an alternative to Sablotron. Or, also look into the PEAR library XML_XSLT_Wrapper.
posted by misterioso at 10:25 PM on March 7, 2005

if you're calling these things (xsl transformers that implement the standard api) from within java the hardest part to understand is how you get the transformer in the first place. i can't remember the details (i think part of the problem is there's a "properties" argument to define implementation dependent details, so you need to look at the implementation docs, rather than the standard java api docs), but don't get disheartened by that part. once that bit is working, the rest is as simple as your php example.
posted by andrew cooke at 4:31 AM on March 8, 2005

Apache Ant has tasks for XML transformation with XSLT by using the style task.

Ant is very easy to use and useful, it's definitely the new make and although written in java, can be used for just about anything you need to build/automate.

Personally I use the style task for generating code using xml formatted table metadata.

On preview: i think it's funny that the mefi spell check tries to replace matadata with retardate.
posted by furtive at 10:57 AM on March 8, 2005

Thanks for the suggestions, sadly for now with the host I have, I can't use libxslt, or Ant. I am still trying to get a grasp on how Java uses it's parsers and what parsers are installed, so for now I am back to using Sablotron, and hopefully I'll get a hang of using Java soon.

Thanks again!
posted by riffola at 11:00 AM on March 9, 2005

« Older Why aren't the pedals in my tr...   |  This is a long shot: I'm look... Newer »
This thread is closed to new comments.