Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Jim Giffin
RE: xsl parameters? [ reply ]  
2008-10-30 20:34
Sorry, hit enter too soon - the result I get on the view is:

before test
worked
P1 10
P2
P3

after

If I pass in a date in the parameter hash, it fails and gives me the following error and doesn't parse the xsl:

Invalid type
runtime error
Evaluating user parameter p2 failed

Am I defining the hash incorrectly or is this a bug with params?

By: Jim Giffin
xsl parameters? [ reply ]  
2008-10-30 20:31
I am not sure this is the correct forum, but I have been working with libxslt-ruby and trying to get xsl paramters to render. It looks like only integer params get sent to the xsl page...

Here is the relevant code I have been using
controller code:
def simple_test
require 'xml/libxml'
require 'libxslt'

# test the parameter passing of libxslt-ruby with a simple xml and xsl
my_xsl_file = XML::Document.file(RAILS_ROOT + '/public/stylesheets/' + 'test.xsl')
my_stylesheet = LibXSLT::XSLT::Stylesheet.new(my_xsl_file)

my_xml_file = XML::Document.file(RAILS_ROOT + '/documents/' + 'test.xml')
#testparams =
#puts testparams
@test = my_stylesheet.apply(my_xml_file, { "p1" => "00010", "p2" => "data", "p3" => "p3data"})

end

View:
before test<br/>
<% simple_test %>
<%= @test %>
<br/>
after<br/>

test.xml file
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>

</catalog>

test.xsl file:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:param name="p1"/>
<xsl:param name="p2" as="xs:string"/>
<xsl:param name="p3" select="none"/>

<xsl:output method="html"/>

<xsl:template name="test" match="/">
worked<br />
P1 <xsl:value-of select="$p1"/><br />
P2 <xsl:value-of select="$p2"/><br />
P3 <xsl:value-of select="$p3"/><br />
</xsl:template>

</xsl:stylesheet>




test.xml