Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Passing parameters through a Nokogiri XSLT Transform (See related posts)

To pass a parameter to Nokogiri#transform supply an array containing the variable name, and the value.

Example:
require 'nokogiri'

doc = Nokogiri::XML(File.open('edinburgh_category_summary.xml','r').read)
xslt  = Nokogiri::XSLT(open('edinburgh_categories.xsl','r'))
a = ['fun', '456']
out =  xslt.transform(doc, a)
puts out.to_xml.to_s


Resources:
- Class: Nokogiri::XSLT::Stylesheet [rubyforge.org]
- Transform an XML file using XSLT with Nokogiri [dzone.com]
- Supplying parameters to Ruby XSLT [dzone.com]

*update: 10-Nov-09 @ 11:06pm*

I've just discovered that Nokogiri#transform params need to be declared as a special type if the value is alphanumeric. e.g.
a = Nokogiri::XSLT.quote_params(['fun', 'aaa456'])


Resources:
- XSLT transform with params - nokogiri-talk | Google Groups [google.com]

You need to create an account or log in to post comments to this site.


Click here to browse all 7207 code snippets

Related Posts