Skip to content

Instantly share code, notes, and snippets.

@ogijun
Created May 3, 2012 14:27
Show Gist options
  • Save ogijun/2585979 to your computer and use it in GitHub Desktop.
Save ogijun/2585979 to your computer and use it in GitHub Desktop.
require 'nokogiri'
xml = <<EOS
<html>
<body>
<h1><a href="#">This is title</a></h1>
<p>
Hello <i>world</i>!
This is <em>another</em> line.
<p><h3>And a paragraph <em>with</em> a heading.</h3></p>
<b>Third line.</b>
<a href="#">Link in p is disabled.</a>
</p>
</body>
</html>
EOS
xslt = <<EOS
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
<output method="html" indent="yes"/>
<template match="node() | @*">
<copy>
<apply-templates select="node() | @*"/>
</copy>
</template>
<template match="p//*[not(self::i or self::b)]">
<apply-templates/>
</template>
</stylesheet>
EOS
xml = Nokogiri::XML(xml)
xslt = Nokogiri::XSLT(xslt)
puts xslt.transform(xml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment