Introducing the xml_to_xsl gem

require 'xml_to_xsl'

xml = "<doc>
  <klass name='SimpleNumber'>
    <def name='initialize' scope='private'></def>
    <def name='add' scope='public'></def>
    <def name='multiply' scope='public'></def>
    <def name='divide' scope='private'></def>
    <def name='square' scope='protected'></def>
  </klass>
</doc>"

puts XMLToXSL.new(xml).to_xsl

output:

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

  <xsl:template match='doc'>

    <xsl:element name='doc'>
  
      <xsl:apply-templates select='klass' />
    </xsl:element>

  </xsl:template>

  <xsl:template match='klass'>

    <xsl:element name='klass'>
      <xsl:attribute name='name'>
        <xsl:value-of select='@name'/>
      </xsl:attribute>
      <xsl:apply-templates select='def' />
    </xsl:element>

  </xsl:template>

  <xsl:template match='def'>

    <xsl:element name='def'>
      <xsl:attribute name='name'>
        <xsl:value-of select='@name'/>
      </xsl:attribute>
      <xsl:attribute name='scope'>
        <xsl:value-of select='@scope'/>
      </xsl:attribute>
      <xsl:value-of select='.' />
    </xsl:element>

  </xsl:template>

</xsl:stylesheet>

Resources

Tags:
Source:
2133hrs.txt
Published:
17-09-2014 21:33