views:

866

answers:

2

I want to attach an xslt stylesheet to an XML document that I build with XMLBuilder. This is done with a Processing Instruction that looks like

<?xml-stylesheet type='text/xsl' href='/stylesheets/style.xslt' ?>

Normally, I'd use the instruct! method, but :xml-stylesheet is not a valid Ruby symbol.

XMLBuilder has a solution for this case for elements using tag! method, but I don't see the equivalent for Processing Instructions.

Any ideas?

+2  A: 

I'm not sure this will solve your problem since I don't know the instruct! method of that object, but :'xml-stylesheet' is a valid ruby symbol.

JasonTrue
duh that was easy :) Thank you!
ykaganovich
+1  A: 

You do it like this:

xm.instruct! 'xml-stylesheet', {:href=>'/stylesheets/style.xslt', :type=>'text/xsl'}

Just add that line right after

xm.instruct! :xml, {:encoding=>"your_encoding_type"}

and before the rest of your document output code and you should be good to go.

Mike Berrow