# Problems passing parameters into XSLT

**URL:** <https://www.ruby-forum.com/t/problems-passing-parameters-into-xslt/153449>\
**Category:** Ruby\
**Created:** [November 17, 2008, 11:49am UTC](https://www.ruby-forum.com/t/problems-passing-parameters-into-xslt/153449 "2008-11-17T11:49:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [November 17, 2008, 11:49am UTC](https://www.ruby-forum.com/t/problems-passing-parameters-into-xslt/153449/1 "2008-11-17T11:49:42Z")

</div>

I’m having some problems passing parameters into XSLT with ruby. The  
following script, based on the example in the docs

----- run.rb

#!/usr/bin/ruby

require ‘rubygems’

require ‘xml’  
require ‘xslt’

# Create a new XSL Transform

stylesheet\_doc = LibXML::XML::Document.file(‘browse.xsl’)  
stylesheet = LibXSLT::XSLT::Stylesheet.new(stylesheet\_doc)

# Transform a xml document

xml\_doc = LibXML::XML::Document.file(‘page.xml’)  
result = stylesheet.apply(xml\_doc, {:root =\> “ROOT”, :back =\> “BACK”})

puts result

Processes these two files

----- page.xml

\<?xml version="1.0" encoding="UTF-8"?\>

----- browse.xsl

\<?xml version="1.0"?\>

\<xsl:stylesheet xmlns:xsl=“[XSLT Namespace](http://www.w3.org/1999/XSL/Transform)”  
version=“1.0”\>  
\<xsl:output method=“xml” indent=“yes” /\>

\<xsl:param name=“root” /\>  
\<xsl:param name=“back” /\>

\<xsl:template match=“/”\>

This is the value of root is \<xsl:value-of select=“$root”  
/\>

  

This is the value of back is \<xsl:value-of select=“$back”  
/\>

  
  
\</xsl:template\>  
\</xsl:stylesheet\>

When run produces the following output:

$ ./run.rb

\<?xml version="1.0"?\> 

This is the value of root is

This is the value of back is

$

As you can see the parameters ‘root’ and ‘back’ have not been filled in.  
When I run the data with xsltproc it works ok which would suggest that  
it is not a problem with the data or the stylesheet.

$ xsltproc --stringparam root ‘ROOT’ --stringparam back ‘BACK’  
browse.xsl page.xml

\<?xml version="1.0"?\> 

This is the value of root is ROOT

This is the value of back is BACK

$

Here is what I have:

$ ruby -v  
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]  
$ gem list

\*\*\* LOCAL GEMS \*\*\*

actionmailer (2.1.2)  
actionpack (2.1.2, 1.13.6)  
actionwebservice (1.2.6)  
activerecord (2.1.2, 1.15.6)  
activesupport (2.1.2, 1.4.4)  
acts\_as\_ferret (0.4.3)  
capistrano (2.0.0)  
cgi\_multipart\_eof\_fix (2.5.0)  
daemons (1.0.10)  
dnssd (0.7.0)  
fastthread (1.0.1)  
fcgi (0.8.7)  
ferret (0.11.6)  
gem\_plugin (0.2.3)  
highline (1.5.0)  
hpricot (0.6.164)  
json (1.1.3)  
libxml-ruby (0.8.3)  
libxslt-ruby (0.8.2)  
mongrel (1.1.5)  
needle (1.3.0)  
net-sftp (2.0.1)  
net-ssh (2.0.4)  
rails (2.1.2)  
rake (0.8.3)  
RedCloth (3.0.4)  
ruby-openid (2.1.2)  
ruby-yadis (0.3.4)  
rubynode (0.1.5)  
sqlite3-ruby (1.2.4)  
termios (0.9.4)

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [November 19, 2008, 10:11am UTC](https://www.ruby-forum.com/t/problems-passing-parameters-into-xslt/153449/2 "2008-11-19T10:11:31Z")

</div>

Answering myself here. This is the problem line:

result = stylesheet.apply(xml\_doc, {:root =\> “ROOT”, :back =\> “BACK”})

and this is the corrected line.

result = stylesheet.apply(xml\_doc, {:root =\> “‘ROOT’”, :back =\>  
“‘BACK’”})

Note that “ROOT” has become “‘ROOT’”. That is the word ROOT wrapped in  
's and  
then wrapped in "s

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [January 15, 2009, 5:30am UTC](https://www.ruby-forum.com/t/problems-passing-parameters-into-xslt/153449/3 "2009-01-15T05:30:03Z")

</div>

I just spent an inordinate amount of time trying to figure out why my  
params were empty. Thank god you posted this. The RDoc just shows simple  
quotes, not quotes in quotes.
