Nokogiri : XSLT Transform passing parameters

Discussion in 'Ruby' started by Une Bévue, Jan 29, 2012.

  1. Une Bévue

    Une Bévue Guest

    I'm trying to pass one parameter to XSLT Transform, like that :
    doc = Nokogiri::XML(File.read(find_latest_xml))
    xslt = Nokogiri::XSLT(File.read("#{@sites_xml_fo}/#{@xsl_fbn}"))
    puts xslt.transform(doc, ["lang", "fr"])

    with the following styyle sheet :
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    ....
    <xsl:param name="lang"/>
    ....
    <h2>$lang = <xsl:value-of select="$lang"/></h2>

    resulting in :
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    <h2>My Family Address Book</h2>
    <h2>$lang = </h2>

    that's to say the parameter is seen as empty, why ???

    also, i'd like to pas more parameters, is it like that :

    puts xslt.transform(doc, ["param-1", "value-1", ..., "param-n",
    "value-n"])

    ???
     
    Une Bévue, Jan 29, 2012
    #1
    1. Advertisements

  2. Une Bévue

    Une Bévue Guest

    Le 29/01/12 15:59, Une Bévue a écrit :
    put single quotes around string parameters :

    ["param-1", "'value-1'" ...
     
    Une Bévue, Jan 29, 2012
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.