No commit activity in last 3 years
No release in over 3 years
It's a rack middleware to add processing instructions on documents of response type XML.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 1.0
 Project Readme

Rack XML Stylesheet middleware

Rack::XMLStylesheet is a rack middleware that makes changes on response body when the content type of responses is XML. It uses the rendered template path and checks on your public path (where the assets are placed) for a corresponding XSL file. If this XSL exists, then a processing instruction is added before the root element of the XML. This instruction helps the client of the response to transform the XML.

What does it do?

Suppose that you had requested the following resource:

GET /blogs/1/comments HTTP/1.1
Accept: application/xml

And the view rendered by your application is the following:

app/views/comments/show.tokamak

The response given by your application would be a XML like this:

HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<comments>
  <comment>I liked this.</comment>
</comments>

The middleware uses the template path ('comments/show.tokamak') and try to find a corresponding XSL into public path, with the extension '.xsl'. If it's there, then the response body is modified:

HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/xsl/layouts/default/comments/show.xsl"?>
<comments>
  <comment>I liked this.</comment>
</comments>

Usage

Rails apps

In your Gemfile:

gem 'rack-xml_stylesheet', :require => 'rack/xml_stylesheet'

In your environment.rb:

require 'rack/xml_stylesheet'
config.middleware.use "Rack::XMLStylesheet"

Have in mind that the middleware has only Rails 2.3.x support for now.

Report bugs and suggestions

Authors

References