Anybody got any experience using this ( http://greg.rubyfr.net/pub/packages/ruby-xslt/files/README.html ) ? I asked my hosting company (a2hosting.com) about XSLT processors for Rails and mentioned this one. Four hours later I get email that they've installed it. Thing is, the documentation didn't generate, and when I execute 'gem list --local' it's not listed as an installed gem.
Hello Bill, Well, from the completely cursory glance given to it, it appears to be a front end to libxslt. Basically, when I did this in perl (don't hate ;), it was pretty much the same. Have your ruby program 'open' the xml source file, open the xslt, apply the xslt (using the serve function here) and then print out the output.
What more info do you need ? (Honestly asked btw) Regards Stef (ps. as with anything XSLT related, your going to spend about 4 days getting your stylesheet correct, and 1 minute on the transformation itself ;)
Bill Walton wrote: > Anybody got any experience using this ( > http://greg.rubyfr.net/pub/packages/ruby-xslt/files/README.html ) ? I > asked my hosting company (a2hosting.com) about XSLT processors for > Rails and mentioned this one. Four hours later I get email that > they've installed it. Thing is, the documentation didn't generate, > and when I execute 'gem list --local' it's not listed as an installed gem.
[mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Stef T Sent: Sunday, August 20, 2006 8:53 AM To: rubyonrails-talk@googlegroups.com Cc: ra...@lists.rubyonrails.org; bill.wal...@charter.net Subject: [Rails] Re: Ruby/XSLT
Hello Bill, Well, from the completely cursory glance given to it, it appears to be a front end to libxslt. Basically, when I did this in perl (don't hate ;), it was pretty much the same. Have your ruby program 'open' the xml source file, open the xslt, apply the xslt (using the serve function here) and then print out the output.
What more info do you need ? (Honestly asked btw) Regards Stef (ps. as with anything XSLT related, your going to spend about 4 days getting your stylesheet correct, and 1 minute on the transformation itself ;)
Bill Walton wrote: > Anybody got any experience using this ( > http://greg.rubyfr.net/pub/packages/ruby-xslt/files/README.html ) ? I > asked my hosting company (a2hosting.com) about XSLT processors for > Rails and mentioned this one. Four hours later I get email that > they've installed it. Thing is, the documentation didn't generate, > and when I execute 'gem list --local' it's not listed as an installed gem.
Thanks for your response! I'm going to change-up the order below a little to make my reply read more easily.
Stef T wrote: > What more info do you need ? (Honestly asked btw)
I always presume goodwill ;-)
> Well, from the completely cursory glance given to it, it appears to be > a front end to libxslt.
And on libxml. Are either / both of these included in Ruby or Rails? If so, which one?
> Have your ruby program 'open' the xml source file, open the xslt, apply > the xslt (using the serve function here) and then print out the output.
I'm already wondering about the 'print out the output' part. As a test, I took a sample XML file and embedded the reference to the XSL file in it ( adding <?xml-stylesheet type="text/xsl" href="stylesheets\ccr_xslt\ccr_20060328.xsl"?> as the second line of the file). Both FF and IE6 support this level of XSLT natively and opening the XML file with either browser renders a correctly styled HTML page.
OTOH, when I do a 'render :file => "same XML file"' via my Rails controller, the page renders but does not have the XSL applied. If I do the render :file on the translated HTML file, it renders that OK. I don't understand this and it worries me a little. Based on the browsers' behavior when I open the file through the File menu, it seems like this ought to work via the render :file if Rails just passed the XML file through to the browser. Any thoughts / ideas on what might be going on here and/or how to fix it would be greatly appreciated!
Clayton Cottingham wrote: > Making the xslt's will be the longest process, > especially if you are new to it.
'Luckily', the XSLT's been furnished. All I have to do is make it work ;-)
> Some books: > I would suggest picking up XSLT by WROX > And of course the pocket reference by orielly
I picked up the 'XSLT Quickly' from Manning a few weeks ago to get me started. Thanks for the suggestions, though, as (assuming I can get this working) I'll be adding to that shorthly.
> If you need some help I wouldn't mind helping as I > would like to look into how ruby handles xml/xslt
Excellent!!! Please consider yourself asked. I've got a feeling I'm definitely going to need some help on this. The biggest potential problem I'm looking at at the moment is that I'm using InstantRails on WinXP for development. I was able to get my host (a2hosting.com) to install the Ruby/XSLT gem for me, but the documentation didn't gen. In fact, when I run 'gem list --local' I don't even see it.
Bill Walton wrote: >> What more info do you need ? (Honestly asked btw)
> I always presume goodwill ;-)
good way to be, a very good way, sometimes painful, but, *smiles* good show :)
>> Well, from the completely cursory glance given to it, it appears >> to be a front end to libxslt.
> And on libxml. Are either / both of these included in Ruby or Rails? > If so, which one?
If you mean are 'libxml' or 'libxslt' included in RoR, then no. These are linux libraries. If you mean the 'ruby wrappers' (ruby-xml) come as 'standard', then no, however, there is a way to have rails generate out xml by using a .rxml file. Have a look around http://wiki.rubyonrails.org/rails/pages/HowtoGenerateXml ;)
>> Have your ruby program 'open' the xml source file, open the xslt, >> apply the xslt (using the serve function here) and then print out the >> output.
> I'm already wondering about the 'print out the output' part. As a > test, I took a sample XML file and embedded the reference to the XSL > file in it ( adding <?xml-stylesheet type="text/xsl" > href="stylesheets\ccr_xslt\ccr_20060328.xsl"?> as the second line of > the file). Both FF and IE6 support this level of XSLT natively and > opening the XML file with either browser renders a correctly styled > HTML page.
> OTOH, when I do a 'render :file => "same XML file"' via my Rails > controller, the page renders but does not have the XSL applied. If I > do the render :file on the translated HTML file, it renders that OK. > I don't understand this and it worries me a little. Based on the > browsers' behavior when I open the file through the File menu, it > seems like this ought to work via the render :file if Rails just > passed the XML file through to the browser. Any thoughts / ideas on > what might be going on here and/or how to fix it would be greatly > appreciated!
Well, now, this is the interesting part :) Ideally, there should be a sort of ':after_filter' on the method that you use to generate the XML. Inside the :after_filter, you would load the stylesheet in much the same way that the ruby-xsl shows. This way, your still using rails and you have set the 'filter' to perform after the generation (so in the future, if someone needs the un-translated XML, then can get it). The header content-type would be different, but, you could probably change that without too much trouble in the :after_filter ..
Thats my thinking. I am unsure if IE/FF include libxslt in there by default, but, leaving this to the individual browser to deal with is dangerous at best. Mean to say, your assuming that all XSLT engines will follow 'the standard', whereas if you do the transformation yourself, at least you know that the -exact- -same- structure of results is sent to all clients.
Hopefully this makes sense, and I am interested in the solution you go with. If its sufficiently 'weird', this could be a great problem to distrac... urm.. occupy my work time tomorrow ;)
Stef T wrote: > If you mean are 'libxml' or 'libxslt' included in RoR, then no. These are > linux libraries. If you mean the 'ruby wrappers' (ruby-xml) come as > 'standard', then no, however, there is a way to have rails generate out > xml by ....
I'm using Builder to generate the XML file.
> Well, now, this is the interesting part :) Ideally, there should be a sort > of ':after_filter' on the method that you use to generate the XML. Inside > the :after_filter, you would load the stylesheet in much the same way that > the ruby-xsl shows.
I'm not understanding the processing you describe in the :after_filter. Load the stylesheet into what for use how? Are you saying I can just reference it with a stylesheet_tag or something and that somehow Rails would then be able to handle it without an XSLT processor?
> leaving this to the individual browser to deal with is dangerous at best. > Mean to say, your assuming that all XSLT engines will follow 'the > standard', whereas if you do the transformation yourself, at least you > know that the -exact- -same- structure of results is sent to all clients.
Agreed. That's why I'm trying to get an XSLT processor working on my hosted site. In the meantime, I thought I'd see if I could just get Rails to pass everything to the browser so I could at least get the results I get from the browser's File menu. No joy. Let me know if you're interested and I'll be more than happy to send you the XML and XSL files so you can see where I'm having trouble understanding what Rails is doing.
Oh. you say that now, jst wait until you hear my solution :P (joking, I hope ;)
>> Well, now, this is the interesting part :) Ideally, there should be a >> sort of ':after_filter' on the method that you use to generate the >> XML. Inside the :after_filter, you would load the stylesheet in much >> the same way that the ruby-xsl shows.
> I'm not understanding the processing you describe in the > :after_filter. Load the stylesheet into what for use how? Are you > saying I can just reference it with a stylesheet_tag or something and > that somehow Rails would then be able to handle it without an XSLT > processor?
Okay, well, in actioncontroller there is a way to 'hook in' processing -after- a method has been called, jst before it returns the information to the user (or the webpage to the browser if you prefer). This is done by using the :after_filter. So, if you include the XSLT transformation in there, then it will be called after everything else but before the page is returned :)
I would -assume- something like
class blah < ActionController::Base
require 'xml/xslt'
after_filter :transformXMLUsingXSLT
def myFunkyXMLGeneration # generate the XML page here end
private def transformXMLUsingXSLT # Should probably check the content header for XML ;P xslt = XML::XSLT.new() xslt.xml = @content xslt.xsl = "mytest.xsl" response.content = xslt.serve() end end
This is by NO means -definitive- but, you should get an idea of what I am driving at here ;>
>> leaving this to the individual browser to deal with is dangerous at >> best. Mean to say, your assuming that all XSLT engines will follow >> 'the standard', whereas if you do the transformation yourself, at >> least you know that the -exact- -same- structure of results is sent >> to all clients.
> Agreed. That's why I'm trying to get an XSLT processor working on my > hosted site. In the meantime, I thought I'd see if I could just get > Rails to pass everything to the browser so I could at least get the > results I get from the browser's File menu. No joy. Let me know if > you're interested and I'll be more than happy to send you the XML and > XSL files so you can see where I'm having trouble understanding what > Rails is doing.
Understandable, truly. The amount of times I have to try and thunk my head around why something is designed the way it is, is normally the part that takes 'time' :)
This is also in best interest's to fix, as even though I don't need this right at this moment, I can see the need arising rather shortly where I work ;)
Bill Walton wrote: > Four hours later I get email that they've > installed it. Thing is, the documentation didn't generate, and when I > execute 'gem list --local' it's not listed as an installed gem.
It hasn't been gemified. I just started using this too and really wish there was a gem for deployment purposes.
Last month Chad Fowler gave a talk on making gems at our local Ruby Users Group. Maybe I'll try my hand at gemifying it.