Coder Social home page Coder Social logo

glejeune / ruby-xslt Goto Github PK

View Code? Open in Web Editor NEW
24.0 4.0 8.0 58 KB

Ruby/XSLT is a simple XSLT class based on libxml <xmlsoft.org/> and libxslt <xmlsoft.org/XSLT/>

Home Page: http://algorithmique.net

License: GNU General Public License v2.0

C 45.23% Ruby 54.10% XSLT 0.67%

ruby-xslt's Introduction

Ruby/XSLT

About

Ruby/XSLT is a simple XSLT class based on libxml <xmlsoft.org/> and libxslt <xmlsoft.org/XSLT/>

Licence

Copyright © 2003-2012 Gregoire Lejeune <gregoire dot lejeune at free dot fr>

Ruby/XSLT is freely distributable according to the terms of the GNU General Public License (see the file ‘COPYING’).

This program is distributed without any warranty. See the file ‘COPYING’ for details.

INSTALLATION

sudo gem install ruby-xslt

or

ruby extconf.rb # see CONFIGURATION for more options
make
make test
make doc
sudo make install

CONFIGURATION

--help                   display this help and exit

--with-xslt-lib=PATH
--with-xslt-include=PATH
--with-xslt-dir=PATH     specify the directory name for the libxslt include 
                         files and/or library 

--disable-error-handler  disables the new error handler 

--disable-exslt          disables libexslt support <http://exslt.org/>

EXAMPLES

Simple example

require 'xml/xslt'

xslt = XML::XSLT.new()
xslt.xml = "text.xml"
xslt.xsl = "test.xsl"

out = xslt.serve()
print out;

REXML support

require 'rexml/document'
require 'xml/xslt'

xslt = XML::XSLT.new()

xslt.xml = REXML::Document.new File.read( "test.xml" )
xslt.xsl = REXML::Document.new File.read( "test.xsl" )

out = xslt.serve()
print out;

XML::Smart support

require 'xml/smart'
require 'xml/xslt'

xslt = XML::XSLT.new()

xslt.xml = XML::Smart.open( "test.xml" )
xslt.xsl = XML::Smart.open( "test.xsl" )

out = xslt.serve()
print out;

Parameters support

require "xml/xslt"

xslt = XML::XSLT.new()
xslt.xsl = "parameter.xsl"
xslt.xml = "test.xml"
xslt.parameters = { "p1" => "the first parameter ...",
                    "p2" => "'and the second one!'" }
xslt.save("test1.html")

xslt.parameters = { "p1" => "Ruby...",
                    "p2" => "'...is cool !'" }
xslt.save("test2.html")

External functions support

require "xml/xslt"

xslt = XML::XSLT.new()
xslt.xsl = "functions.xsl"
xslt.xml = "test.xml"

XML::XSLT.registerExtFunc("http://test.none", "round-trip") do |arg|
  arg
end

XML::XSLT.registerExtFunc("http://test.none", "type") do |arg|
  arg.class.to_s
end

print xslt.serve

Error handling

XML::XSLT.registerErrorHandler { |string| puts string }

xslt = XML::XSLT.new
xslt.xml = "not xml"

This fragment would print:

Entity: line 1: 
parser 
error : 
Start Tag expected, '<' not found
not xml
^

ruby-xslt's People

Contributors

camobap avatar glejeune avatar noonie2k avatar radar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ruby-xslt's Issues

Windows support

Questions

  1. Is this module expect to be compiled on windows machine?
  2. If so what are the steps?

Complier centric options are hardcoded.

The forcing of some compiler options can be bad. In the case of -Wall. This is GCC centric and would cause compilation on other platforms to fail (i.e. Solaris and Windows). The following patch might be a solution.


--- ext/xslt_lib/extconf.rb     2011-01-11 10:16:12.424617000 -0600
+++ ext/xslt_lib/extconf.rb.new 2011-01-11 10:07:10.048251000 -0600
@@ -54,7 +54,14 @@
   $CFLAGS += " -DUSE_EXSLT"
 end

-$CFLAGS = '-g -Wall ' + `xml2-config --cflags`.chomp + " " + `xslt-config --cflags`.chomp + " " + $CFLAGS
+# Allow for custom compiler to be specified.
+RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
+
+# NOTE: use GCC flags unless Visual C compiler is used
+$CFLAGS << '-Wall ' if (RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/ && RUBY_PLATFORM !~ /mswin/ )
+
+$CFLAGS << '-g ' + `xml2-config --cflags`.chomp + " " + `xslt-config --cflags`.chomp
+

 create_header()
 create_makefile("xml/xslt_lib")

Build failure with Clang 16 (`-Wincompatible-function-pointer-types`)

Clang 16 makes -Wincompatible-function-pointer-types an error by default.

ruby-xslt hits the following failure when building with Clang 16:

[...]
xslt_lib.c:437:46: error: incompatible function pointer types passing 'VALUE (VALUE, VALUE)' (aka 'unsigned long (unsigned long, unsigned long)') to parameter of type 'rb_block_call_func_t' (aka 'unsigned long (*)(unsigned long, unsigned long, int, const unsigned long *, unsigned long)') [-Werror,-Wincompatible-function-pointer-types]
    (void)rb_iterate( each_pair, parameters, process_pair, pRbTxslt->pxParams );
                                             ^~~~~~~~~~~~
/usr/include/ruby-2.7.0/ruby/ruby.h:1986:60: note: passing argument to parameter here
VALUE rb_iterate(VALUE(*)(VALUE),VALUE,rb_block_call_func_t,VALUE);
                                                           ^
1 warning and 1 error generated.
make: *** [Makefile:245: xslt_lib.o] Error 1

To reproduce this bug:

  • with Clang 16, just build normally
  • with Clang 15, pass -Werror=incompatible-function-pointer-types
  • with GCC, pass -Werror=incompatible-pointer-types (GCC lacks a more specific warning)

Reported downstream in Gentoo at https://bugs.gentoo.org/884407. Full log at https://bugs.gentoo.org/attachment.cgi?id=840185.

String is not a module

We're seeing this using ruby-xslt with Ruby 2.1.1.

/Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require': String is not a module (TypeError)
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:234:in `block in load_dependency'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:234:in `load_dependency'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/ruby-xslt-0.9.9/lib/xml/xslt.rb:19:in `<top (required)>'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:234:in `block in load_dependency'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:234:in `load_dependency'
    from /Users/mikep/src/theclymb/.bundle/ruby/2.1.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require'
    from /Users/mikep/src/theclymb/app/services/merch/email_xslt_interpolator.rb:1:in `<top (required)>'

Any way to use inline xml instead of file

say I have xml sorted in a variable can I pass that to

xslt = XML::XSLT.new()
xslt.xml =  myvariable

Instead of reading from a file. All the examples show file inputs

No longer compiles with libxslt 1.30

In this version the norm:Localtime function was removed, and thus XSLT_NORM_SAXON_NAMESPACE is no longer defined, leading to a compilation error.

x86_64-pc-linux-gnu-gcc -I. -I/usr/include/ruby-2.2.0/x86_64-linux -I/usr/include/ruby-2.2.0/ruby/backward -I/usr/include/ruby-2.2.0 -I. -DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -Wall -I/usr/include/libxml2 -I/usr/include/libxml2 -Wall -O2 -pipe -march=native -Wformat-security -ggdb -fno-strict-aliasing -fPIC -DUSE_ERROR_HANDLER -DUSE_EXSLT  -o extfunc.o -c extfunc.c
xslt_lib.c: In function ‘Init_xslt_lib’:
xslt_lib.c:564:99: error: ‘XSLT_NORM_SAXON_NAMESPACE’ undeclared (first use in this function)
   rb_define_const( cXSLT, "NAMESPACE_NORM_SAXON", rb_str_new2((char *)XSLT_NORM_SAXON_NAMESPACE) );
                                                                                                   ^
xslt_lib.c:564:99: note: each undeclared identifier is reported only once for each function it appears in
make: *** [Makefile:237: xslt_lib.o] Error 1

https://mail.gnome.org/archives/commits-list/2017-February/msg00373.html has the libxslt upstream patch.

Removing the line declaring the XSLT_NORM_SAXON_NAMESPACE appears to be sufficient because it does not seem to be used otherwise.

parameters bug

In my recent use of it, I have run across what seems to be a bug
involving memory corruption. I first saw this in a moderately complex
program which would crash due to an internal error some time after
exhibiting the corruption, but I was able to boil this down into a
surprisingly short test program which exhibits the corruption
(although not the subsequent crash which I assume is associated with
it, as this requires running for longer). Here it is:

#!/usr/bin/ruby

require 'rubygems'
require 'xml/smart'
require 'xml/xslt'

XsltDoc = %{\
  <?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <xsl:template match="text()"/>
    <xsl:template match="/">
      <record>
        <opacVendor><xsl:value-of select="$vendor"/></opacVendor>
      </record>
    </xsl:template>
  </xsl:stylesheet>
}

XmlDoc = %{\
  <?xml version="1.0" encoding="UTF-8"?>
  <emptyDocument/>
}

Vendor = "Some Specific Vendor"

def zoom2torus()
  xslt = XML::XSLT.new()
  xslt.xsl = XML::Smart.string(XsltDoc)
  xslt.xml = XML::Smart.string(XmlDoc)

  puts "before xslt.parameters assignment, Vendor=[#{Vendor}]"
  xslt.parameters = { "vendor" => Vendor }
  puts "after  xslt.parameters assignment, Vendor=[#{Vendor}]"

  xslt.serve
end

dummy1 = zoom2torus()
dummy2 = zoom2torus()

I am using version 0.96 of Ruby-XSLT, installed from the gem, on
Ubuntu GNU/Linux 9.10 (Karmic Koala) which provides ruby 1.8.7
(2009-06-12 patchlevel 174). Running the program yields:

$ ruby xslt-bug.rb
before xslt.parameters assignment, Vendor=[Some Specific Vendor]
after  xslt.parameters assignment, Vendor=[Some Specific Vendor']
before xslt.parameters assignment, Vendor=[Some Specific Vendor']
after  xslt.parameters assignment, Vendor=[Some Specific Vendor']
Invalid expression
runtime error
Evaluating user parameter vendor failed

You will note that the value of the global variable Vendor is
corrupted by the act of being passed into xslt.parameters=, and that
reassigning it the second time when using the corrupted value results
in an error (though not the same one I got in my longer-running
program). Similar corruption occurs if the value passed into the
parameters= call is an instance variable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.