[chef] Re: Re: Re: Re: xslt templates


Chronological Thread 
  • From: gregoire a < >
  • To:
  • Subject: [chef] Re: Re: Re: Re: xslt templates
  • Date: Wed, 2 Jul 2014 10:36:29 +0200

if I understand correctly, the mappings are passed to the ghprb_config.xml.erb to generate the ghprb_config.xml file directly, or is there an xslt involved in the generation of the xml?
can you share your lwrp code? I am sure it would help me much :-)

to be precise, my current processing is as follow:
1/ I generate the conf.xslt file using attributes from a databag and a conf.xslt.erb file
2/ I generate the target conf.xml file using conf.xslt and conf_origin.xml
so the xslt is used on the xml to generate another xml.

Regards


Here is a simple example of my process:
*** databag:
{"debug": false}

*** conf.xslt.erb:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" />
    <xsl:template match="node()|@*">
      <xsl:copy>
         <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
    </xsl:template>
    <xsl:template match="/configuration/debug/"><%= @overrides['debug'] %></xsl:template>
</xsl:stylesheet>

*** conf_origin.xml
<configuration>
  <debug>true</debug>
</configuration>

that will generate the files:
*** conf.xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" />
    <xsl:template match="node()|@*">
      <xsl:copy>
         <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
    </xsl:template>
    <xsl:template match="/configuration/debug/">false</xsl:template>
</xsl:stylesheet>

*** conf.xml
<configuration>
  <debug>false</debug>
</configuration>


2014-07-01 18:35 GMT+02:00 Ranjib Dey < " target="_blank"> >:
i am using similar logic(xml & xslt) for creating jenkins configs using lwrp. the resource declaration looks like this:

xml_file '/var/lib/jenkins/config/org.jenkinsci.plugins.ghprb.GhprbTrigger.xml' do
  mappings('//adminlist' => @github_users.join("\n"))
  source 'ghprb_config.xml.erb'
  notifies :restart, 'service[jenkins]'                                    
end

internally it uses file resource for content/ownership etc and nokogiri for xml/xslt stuff. mappings is an array of key/value pairs  (selector -> expected value) used to pass xslt targets. this is idempotent and why_run compliant.

regards
ranjib


On Tue, Jul 1, 2014 at 9:13 AM, < " target="_blank"> > wrote:
You are right about the idempotent, and my example does not show that. I use
"action :nothing" and notifications to trigger the generation.
I am not so happy about it, it does not show a diff as "template" does and
xsltproc runs on the target.
I may eventually try to implement your LWRP suggestion

Thanks





Archive powered by MHonArc 2.6.16.

§