Created
May 3, 2012 14:27
-
-
Save ogijun/2585979 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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