saxon-xslt 0.2.0.1-java → 0.5.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -1
- data/README.md +35 -1
- data/lib/saxon/processor.rb +48 -6
- data/lib/saxon/s9api.rb +1 -2
- data/lib/saxon/source_helper.rb +44 -0
- data/lib/saxon/xml.rb +39 -9
- data/lib/saxon/xslt.rb +28 -10
- data/lib/saxon/xslt/version.rb +1 -1
- data/saxon-xslt.gemspec +7 -4
- data/spec/fixtures/cassettes/Saxon_SourceHelper/returning_a_StreamSource/StreamSource_systemId/for_inputs_where_we_can_infer_the_path_or_URI/is_set_to_an_open-uri_d_URI_s_URI.yml +63 -0
- data/spec/fixtures/cassettes/Saxon_SourceHelper/returning_a_StreamSource/StreamSource_systemId/for_inputs_where_we_can_infer_the_path_or_URI/overrides_the_inferred_system_ID_if_set_explicitly.yml +63 -0
- data/spec/fixtures/cassettes/Saxon_SourceHelper/returning_a_StreamSource/for_input_backed_by_an_InputStream/converts_an_open-uri_d_Uri_correctly.yml +123 -0
- data/spec/fixtures/config.xml +70 -0
- data/spec/fixtures/simple-xsl-import.xsl +7 -0
- data/spec/saxon/processor_spec.rb +22 -5
- data/spec/saxon/source_helper_spec.rb +117 -0
- data/spec/saxon/xml_spec.rb +38 -3
- data/spec/saxon/xslt_spec.rb +24 -6
- data/spec/spec_helper.rb +8 -0
- data/vendor/saxonica/saxon9-unpack.jar +0 -0
- data/vendor/saxonica/saxon9-xqj.jar +0 -0
- data/vendor/saxonica/saxon9he.jar +0 -0
- metadata +70 -19
- data/lib/saxon/source_helpers.rb +0 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cfa11992486ed13c2359031da17082e29520754e
|
4
|
+
data.tar.gz: ca8e42087c7b82f890e8caff64dadb42d7e46f0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0246341e380043c327f6de92383073213efdbf018abee0b0a39af92845d0f7462df6fedc1fd7f43fe2cae50234377aeb422315ea0861b6310631745c2a199b78
|
7
|
+
data.tar.gz: f7fd284b2d4a162173dd854000e35b00e245d42c1eecc1ebfef4a2d1c713a307960c9ce7fbb792e9d7f04efe40ad7195efe82ca0909d049e7bd54f160d390851
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
jruby-1.7.
|
1
|
+
jruby-1.7.13
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
$ gem install saxon-xslt
|
28
28
|
|
29
|
-
##
|
29
|
+
## Simple usage
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
require 'saxon-xslt'
|
@@ -35,6 +35,40 @@ input = Saxon.XML(File.open('/path/to/your.xml'))
|
|
35
35
|
output = transformer.transform(input)
|
36
36
|
```
|
37
37
|
|
38
|
+
## Saxon version
|
39
|
+
`saxon-xslt` 0.5 includes Saxon HE 9.5.1.7
|
40
|
+
|
41
|
+
## Differences between Saxon and Nokogiri
|
42
|
+
|
43
|
+
Saxon uses a `Processor` class as its central object: it holds configuration information and acts as a Factory for creating documents or XSLT stylesheet compilers. Unless you need to tweak the config you don't need to worry about this – `saxon-xslt` creates a shared instance behind the scenes when you call `Saxon.XSLT` or `Saxon.XML`. If you need to change the configuration you can create your own instance of `Saxon::Processor` and pass it an open `File` pointing at a Saxon configuration file. (See http://www.saxonica.com/documentation/index.html#!configuration/configuration-file for details of the configuration file.) Once you have a `Saxon::Processor` instance you can call the `XML` and `XSLT` methods on it directly:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'saxon-xslt'
|
47
|
+
processor = Saxon::Processor.new(File.open('/path/to/config.xml'))
|
48
|
+
transformer = processor.XSLT(File.open('/path/to/your.xsl'))
|
49
|
+
input = processor.XML(File.open('/path/to/your.xml'))
|
50
|
+
output = transformer.transform(input)
|
51
|
+
```
|
52
|
+
|
53
|
+
### System IDs
|
54
|
+
XML has this idea of 'Public' and 'System' identifiers for documents. The public ID is a kind of abstract name and the system ID is a URI, for example:
|
55
|
+
|
56
|
+
```xml
|
57
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
58
|
+
"http://www.w3.org/TR/html4/loose.dtd">
|
59
|
+
```
|
60
|
+
|
61
|
+
There the Public ID is `-//W3C//DTD HTML 4.01 Transitional//EN` and the System ID is `http://www.w3.org/TR/html4/loose.dtd`. An XML or XSLT processor uses the System ID as a base URI for resolving linked objects, e.g. `<xsl:import>` or `<xsl:include>` calls with relative URIs.
|
62
|
+
|
63
|
+
With Nokogiri the System ID for a document is inferred from its file path, if you hand in a `File` object to `Nokogiri::XML`. With `saxon-xslt` you can also explicitly set the System ID:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
xslt = Saxon.XSLT("<xsl:stylesheet>...</xsl:stylesheet>",
|
67
|
+
system_id: "/path/to/resources/file.xsl")
|
68
|
+
```
|
69
|
+
|
70
|
+
So, if you have other XSLT stylesheets in `/path/to/resources/` then your dynamically generated XSLT can refer to them with import statements like `<xsl:import href="other_stylesheet.xsl"/>`.
|
71
|
+
|
38
72
|
## Contributing
|
39
73
|
|
40
74
|
1. Fork it
|
data/lib/saxon/processor.rb
CHANGED
@@ -1,23 +1,65 @@
|
|
1
1
|
require 'saxon/s9api'
|
2
|
+
require 'saxon/source_helper'
|
2
3
|
require 'saxon/xslt'
|
3
4
|
require 'saxon/xml'
|
4
5
|
|
5
6
|
module Saxon
|
7
|
+
# Saxon::Processor wraps the S9API::Processor object. This is the object
|
8
|
+
# responsible for creating an XSLT compiler or an XML Document object.
|
9
|
+
#
|
10
|
+
# The Processor is threadsafe, and can be shared between threads. But, most
|
11
|
+
# importantly XSLT or XML objects created by a Processor can only be used
|
12
|
+
# with other XSLT or XML objects created by the same Processor instance.
|
6
13
|
class Processor
|
14
|
+
# Provides a processor with default configuration. Essentially a singleton
|
15
|
+
# instance
|
16
|
+
# @return [Saxon::Processor]
|
7
17
|
def self.default
|
8
18
|
@processor ||= new
|
9
19
|
end
|
10
20
|
|
11
|
-
|
12
|
-
|
21
|
+
# @param config [File, String, IO] an open File, or string,
|
22
|
+
# containing a Saxon configuration file
|
23
|
+
# @return [Saxon::Processor]
|
24
|
+
def self.create(config = nil)
|
25
|
+
licensed_or_config_source = false
|
26
|
+
if config
|
27
|
+
licensed_or_config_source = Saxon::SourceHelper.to_stream_source(config)
|
28
|
+
end
|
29
|
+
s9_processor = S9API::Processor.new(licensed_or_config_source)
|
30
|
+
new(s9_processor)
|
13
31
|
end
|
14
32
|
|
15
|
-
|
16
|
-
|
33
|
+
# @param [net.sf.saxon.s9api.Processor] s9_processor The Saxon Processor
|
34
|
+
# instance to wrap
|
35
|
+
def initialize(s9_processor)
|
36
|
+
@s9_processor = s9_processor
|
17
37
|
end
|
18
38
|
|
19
|
-
|
20
|
-
|
39
|
+
# @param input [File, IO, String] the input XSLT file
|
40
|
+
# @param opts [Hash] options for the XSLT
|
41
|
+
# @return [Saxon::XSLT::Stylesheet] the new XSLT Stylesheet
|
42
|
+
def XSLT(input, opts = {})
|
43
|
+
Saxon::XSLT::Stylesheet.parse(self, input, opts)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @param input [File, IO, String] the input XML file
|
47
|
+
# @param opts [Hash] options for the XML file
|
48
|
+
# @return [Saxon::XML::Document] the new XML Document
|
49
|
+
def XML(input, opts = {})
|
50
|
+
Saxon::XML::Document.parse(self, input, opts)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [net.sf.saxon.s9api.Processor] The underlying Saxon processor
|
54
|
+
def to_java
|
55
|
+
@s9_processor
|
56
|
+
end
|
57
|
+
|
58
|
+
# compare equal if the underlying java processor is the same instance for
|
59
|
+
# self and other
|
60
|
+
# @param other object to compare against
|
61
|
+
def ==(other)
|
62
|
+
other.to_java === to_java
|
21
63
|
end
|
22
64
|
end
|
23
65
|
end
|
data/lib/saxon/s9api.rb
CHANGED
@@ -2,9 +2,8 @@ require 'java'
|
|
2
2
|
$CLASSPATH << File.expand_path('../../../vendor/saxonica/saxon9he.jar', __FILE__)
|
3
3
|
$CLASSPATH << File.expand_path('../../../vendor/saxonica/saxon9-unpack.jar', __FILE__)
|
4
4
|
|
5
|
-
java_import javax.xml.transform.stream.StreamSource
|
6
|
-
|
7
5
|
module Saxon
|
6
|
+
# Puts the Saxon Java classes into a sensible namespace
|
8
7
|
module S9API
|
9
8
|
java_import 'net.sf.saxon.s9api.Processor'
|
10
9
|
java_import 'net.sf.saxon.s9api.XdmDestination'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
java_import javax.xml.transform.stream.StreamSource
|
2
|
+
|
3
|
+
module Saxon
|
4
|
+
# Helper methods for converting Ruby File, IO, Path, or String objects into a
|
5
|
+
# Javax StreamSource object for Saxon's Document parser or XSLT compiler to
|
6
|
+
# consume
|
7
|
+
class SourceHelper
|
8
|
+
# Creates a StreamSource from its input
|
9
|
+
# @param [File, IO, String] path_io_or_string A File, or IO
|
10
|
+
# object representing the input XML file or data, or a String containing
|
11
|
+
# the XML
|
12
|
+
# @param [Hash] opts
|
13
|
+
# @option opts [String] :system_id The System ID of the source - an
|
14
|
+
# absolute URI or relative path pointing to the location of the source
|
15
|
+
# @return [java.xml.transform.stream.StreamSource] a StreamSource for
|
16
|
+
# consuming the input
|
17
|
+
def self.to_stream_source(path_io_or_string, opts = {})
|
18
|
+
system_id = opts.fetch(:system_id) { to_system_id(path_io_or_string) }
|
19
|
+
StreamSource.new(to_inputstream(path_io_or_string), system_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Given a File, or IO object which will return either #path or
|
23
|
+
# #base_uri, return the #base_uri, if present, or the #path, if present, or
|
24
|
+
# nil
|
25
|
+
# @param [File, IO, String] path_io_or_string A Path, File, or IO
|
26
|
+
# object representing the input XML file or data, or a String containing
|
27
|
+
# the XML
|
28
|
+
def self.to_system_id(path_io_or_string)
|
29
|
+
if path_io_or_string.respond_to?(:base_uri)
|
30
|
+
return path_io_or_string.base_uri.to_s
|
31
|
+
end
|
32
|
+
return path_io_or_string.path if path_io_or_string.respond_to?(:path)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Given a File, IO, or String return a Java InputStream or StringReader
|
36
|
+
# @param [File, IO, String] path_io_or_string input to be converted to an
|
37
|
+
# input stream
|
38
|
+
# @return [java.io.InputStream, java.io.StringReader] the wrapped input
|
39
|
+
def self.to_inputstream(path_io_or_string)
|
40
|
+
return path_io_or_string.to_inputstream if path_io_or_string.respond_to?(:read)
|
41
|
+
return java.io.StringReader.new(path_io_or_string)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/saxon/xml.rb
CHANGED
@@ -1,21 +1,51 @@
|
|
1
1
|
require 'saxon/s9api'
|
2
|
-
require 'saxon/
|
2
|
+
require 'saxon/source_helper'
|
3
3
|
require 'saxon/processor'
|
4
4
|
|
5
5
|
module Saxon
|
6
|
-
|
7
|
-
|
6
|
+
# Create an XML Document object using the default processor
|
7
|
+
# @param input [File, IO, String] the input XML file
|
8
|
+
# @param opts [Hash] options for the XML
|
9
|
+
# @return [Saxon::XML::Document]
|
10
|
+
def self.XML(input, opts = {})
|
11
|
+
Saxon::Processor.default.XML(input, opts)
|
8
12
|
end
|
9
13
|
|
10
14
|
module XML
|
15
|
+
# Parse an XML File or String into a Document object
|
11
16
|
class Document
|
12
|
-
|
13
|
-
|
17
|
+
# @param [Saxon::Processor] processor The processor object which should
|
18
|
+
# be used to build the document
|
19
|
+
# @param [String, File, IO] string_or_io The input XML
|
20
|
+
# @param [Hash] opts (see Saxon::SourceHelper#to_stream_source)
|
21
|
+
# @return [Saxon::XML::Document]
|
22
|
+
def self.parse(processor, string_or_io, opts = {})
|
23
|
+
builder = processor.to_java.newDocumentBuilder()
|
24
|
+
source = SourceHelper.to_stream_source(string_or_io, opts)
|
25
|
+
xdm_document = builder.build(source)
|
26
|
+
new(xdm_document)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @api private
|
30
|
+
def initialize(xdm_document)
|
31
|
+
@xdm_document = xdm_document
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [net.sf.saxon.s9api.XdmNode] return the underlying Saxon
|
35
|
+
# document object
|
36
|
+
def to_java
|
37
|
+
@xdm_document
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [String] return a simple serialisation of the document
|
41
|
+
def to_s
|
42
|
+
@xdm_document.to_s
|
43
|
+
end
|
14
44
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
45
|
+
# @return [Saxon::Processor] return the processor used to create this
|
46
|
+
# document
|
47
|
+
def processor
|
48
|
+
Saxon::Processor.new(@xdm_document.processor)
|
19
49
|
end
|
20
50
|
end
|
21
51
|
end
|
data/lib/saxon/xslt.rb
CHANGED
@@ -1,29 +1,47 @@
|
|
1
1
|
require 'saxon/s9api'
|
2
|
-
require 'saxon/
|
2
|
+
require 'saxon/source_helper'
|
3
3
|
require 'saxon/processor'
|
4
4
|
require 'saxon/xml'
|
5
5
|
|
6
6
|
module Saxon
|
7
|
-
|
8
|
-
|
7
|
+
# Create an XSLT Stylesheet object using the default processor
|
8
|
+
# @param input [File, IO, String] the input XSLT file
|
9
|
+
# @param opts [Hash] options for the XSLT
|
10
|
+
# @return [Saxon::XSLT::Stylesheet]
|
11
|
+
def self.XSLT(input, opts = {})
|
12
|
+
Saxon::Processor.default.XSLT(input, opts)
|
9
13
|
end
|
10
14
|
|
11
15
|
module XSLT
|
16
|
+
# a Stylesheet transforms input (XML) into output
|
12
17
|
class Stylesheet
|
13
|
-
|
18
|
+
# @param processor [Saxon::Processor] the Saxon processor object
|
19
|
+
# @param string_or_io [File, IO, String] the input XSLT
|
20
|
+
# @param opts [Hash] Stylesheet and input options
|
21
|
+
# @return [Saxon::XSLT::Stylesheet] the compiled XSLT stylesheet
|
22
|
+
def self.parse(processor, string_or_io, opts = {})
|
23
|
+
source = processor.XML(string_or_io, opts)
|
24
|
+
new(source)
|
25
|
+
end
|
14
26
|
|
15
|
-
|
16
|
-
|
17
|
-
|
27
|
+
# @param [Saxon::XML::Document] source the input XSLT as an XML document
|
28
|
+
def initialize(source)
|
29
|
+
processor = source.processor
|
30
|
+
compiler = processor.to_java.new_xslt_compiler()
|
31
|
+
@xslt = compiler.compile(source.to_java.as_source)
|
18
32
|
end
|
19
33
|
|
20
|
-
|
34
|
+
# Transform an input document
|
35
|
+
# @param [Saxon::XML::Document] document the XML Document object to
|
36
|
+
# transform
|
37
|
+
# @return a Saxon::XML::Document object
|
38
|
+
def transform(document)
|
21
39
|
output = S9API::XdmDestination.new
|
22
40
|
transformer = @xslt.load
|
23
|
-
transformer.setInitialContextNode(
|
41
|
+
transformer.setInitialContextNode(document.to_java)
|
24
42
|
transformer.setDestination(output)
|
25
43
|
transformer.transform
|
26
|
-
output.getXdmNode
|
44
|
+
Saxon::XML::Document.new(output.getXdmNode)
|
27
45
|
end
|
28
46
|
end
|
29
47
|
end
|
data/lib/saxon/xslt/version.rb
CHANGED
data/saxon-xslt.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Saxon::XSLT::VERSION
|
9
9
|
gem.authors = ["Matt Patterson"]
|
10
10
|
gem.email = ["matt@reprocessed.org"]
|
11
|
-
gem.description = %q{Wraps the Saxon 9.
|
12
|
-
gem.summary = %q{Saxon 9.
|
11
|
+
gem.description = %q{Wraps the Saxon 9.5 HE XSLT 2.0 processor so that you can transform XSLT 2 stylesheets in JRuby. Sticks closely to the Nokogiri API}
|
12
|
+
gem.summary = %q{Saxon 9.5 HE XSLT 2.0 for JRuby with Nokogiri's API}
|
13
13
|
gem.homepage = "https://github.com/fidothe/saxon-xslt"
|
14
14
|
gem.licenses = ["MIT", "MPL-1.0"]
|
15
15
|
gem.platform = 'java'
|
@@ -19,6 +19,9 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
20
|
gem.require_paths = ["lib"]
|
21
21
|
|
22
|
-
gem.add_development_dependency('rake', '~> 10.1
|
23
|
-
gem.add_development_dependency('rspec', '~>
|
22
|
+
gem.add_development_dependency('rake', '~> 10.1')
|
23
|
+
gem.add_development_dependency('rspec', '~> 3.0')
|
24
|
+
gem.add_development_dependency('vcr', '~> 2.9.2')
|
25
|
+
gem.add_development_dependency('webmock', '~> 1.18.0')
|
26
|
+
gem.add_development_dependency('yard', '~> 0.8.7')
|
24
27
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://example.org/
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- '*/*'
|
12
|
+
User-Agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Accept-Ranges:
|
20
|
+
- bytes
|
21
|
+
Cache-Control:
|
22
|
+
- max-age=604800
|
23
|
+
Content-Type:
|
24
|
+
- text/html
|
25
|
+
Date:
|
26
|
+
- Sun, 10 Aug 2014 09:37:13 GMT
|
27
|
+
Etag:
|
28
|
+
- '"359670651"'
|
29
|
+
Expires:
|
30
|
+
- Sun, 17 Aug 2014 09:37:13 GMT
|
31
|
+
Last-Modified:
|
32
|
+
- Fri, 09 Aug 2013 23:54:35 GMT
|
33
|
+
Server:
|
34
|
+
- ECS (iad/182A)
|
35
|
+
X-Cache:
|
36
|
+
- HIT
|
37
|
+
X-Ec-Custom-Error:
|
38
|
+
- '1'
|
39
|
+
Content-Length:
|
40
|
+
- '1270'
|
41
|
+
body:
|
42
|
+
encoding: US-ASCII
|
43
|
+
string: "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\
|
44
|
+
\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"\
|
45
|
+
text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width,\
|
46
|
+
\ initial-scale=1\" />\n <style type=\"text/css\">\n body {\n \
|
47
|
+
\ background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n \
|
48
|
+
\ font-family: \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial,\
|
49
|
+
\ sans-serif;\n \n }\n div {\n width: 600px;\n \
|
50
|
+
\ margin: 5em auto;\n padding: 50px;\n background-color: #fff;\n\
|
51
|
+
\ border-radius: 1em;\n }\n a:link, a:visited {\n color:\
|
52
|
+
\ #38488f;\n text-decoration: none;\n }\n @media (max-width:\
|
53
|
+
\ 700px) {\n body {\n background-color: #fff;\n }\n\
|
54
|
+
\ div {\n width: auto;\n margin: 0 auto;\n \
|
55
|
+
\ border-radius: 0;\n padding: 1em;\n }\n }\n\
|
56
|
+
\ </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n\
|
57
|
+
\ <p>This domain is established to be used for illustrative examples in\
|
58
|
+
\ documents. You may use this\n domain in examples without prior coordination\
|
59
|
+
\ or asking for permission.</p>\n <p><a href=\"http://www.iana.org/domains/example\"\
|
60
|
+
>More information...</a></p>\n</div>\n</body>\n</html>\n"
|
61
|
+
http_version:
|
62
|
+
recorded_at: Sun, 10 Aug 2014 09:37:13 GMT
|
63
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://example.org/
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- '*/*'
|
12
|
+
User-Agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Accept-Ranges:
|
20
|
+
- bytes
|
21
|
+
Cache-Control:
|
22
|
+
- max-age=604800
|
23
|
+
Content-Type:
|
24
|
+
- text/html
|
25
|
+
Date:
|
26
|
+
- Sun, 10 Aug 2014 09:52:49 GMT
|
27
|
+
Etag:
|
28
|
+
- '"359670651"'
|
29
|
+
Expires:
|
30
|
+
- Sun, 17 Aug 2014 09:52:49 GMT
|
31
|
+
Last-Modified:
|
32
|
+
- Fri, 09 Aug 2013 23:54:35 GMT
|
33
|
+
Server:
|
34
|
+
- ECS (iad/182A)
|
35
|
+
X-Cache:
|
36
|
+
- HIT
|
37
|
+
X-Ec-Custom-Error:
|
38
|
+
- '1'
|
39
|
+
Content-Length:
|
40
|
+
- '1270'
|
41
|
+
body:
|
42
|
+
encoding: US-ASCII
|
43
|
+
string: "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\
|
44
|
+
\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"\
|
45
|
+
text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width,\
|
46
|
+
\ initial-scale=1\" />\n <style type=\"text/css\">\n body {\n \
|
47
|
+
\ background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n \
|
48
|
+
\ font-family: \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial,\
|
49
|
+
\ sans-serif;\n \n }\n div {\n width: 600px;\n \
|
50
|
+
\ margin: 5em auto;\n padding: 50px;\n background-color: #fff;\n\
|
51
|
+
\ border-radius: 1em;\n }\n a:link, a:visited {\n color:\
|
52
|
+
\ #38488f;\n text-decoration: none;\n }\n @media (max-width:\
|
53
|
+
\ 700px) {\n body {\n background-color: #fff;\n }\n\
|
54
|
+
\ div {\n width: auto;\n margin: 0 auto;\n \
|
55
|
+
\ border-radius: 0;\n padding: 1em;\n }\n }\n\
|
56
|
+
\ </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n\
|
57
|
+
\ <p>This domain is established to be used for illustrative examples in\
|
58
|
+
\ documents. You may use this\n domain in examples without prior coordination\
|
59
|
+
\ or asking for permission.</p>\n <p><a href=\"http://www.iana.org/domains/example\"\
|
60
|
+
>More information...</a></p>\n</div>\n</body>\n</html>\n"
|
61
|
+
http_version:
|
62
|
+
recorded_at: Sun, 10 Aug 2014 09:52:49 GMT
|
63
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,123 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://example.org/
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- '*/*'
|
12
|
+
User-Agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Accept-Ranges:
|
20
|
+
- bytes
|
21
|
+
Cache-Control:
|
22
|
+
- max-age=604800
|
23
|
+
Content-Type:
|
24
|
+
- text/html
|
25
|
+
Date:
|
26
|
+
- Sun, 10 Aug 2014 09:34:50 GMT
|
27
|
+
Etag:
|
28
|
+
- '"359670651"'
|
29
|
+
Expires:
|
30
|
+
- Sun, 17 Aug 2014 09:34:50 GMT
|
31
|
+
Last-Modified:
|
32
|
+
- Fri, 09 Aug 2013 23:54:35 GMT
|
33
|
+
Server:
|
34
|
+
- ECS (iad/182A)
|
35
|
+
X-Cache:
|
36
|
+
- HIT
|
37
|
+
X-Ec-Custom-Error:
|
38
|
+
- '1'
|
39
|
+
Content-Length:
|
40
|
+
- '1270'
|
41
|
+
body:
|
42
|
+
encoding: US-ASCII
|
43
|
+
string: "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\
|
44
|
+
\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"\
|
45
|
+
text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width,\
|
46
|
+
\ initial-scale=1\" />\n <style type=\"text/css\">\n body {\n \
|
47
|
+
\ background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n \
|
48
|
+
\ font-family: \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial,\
|
49
|
+
\ sans-serif;\n \n }\n div {\n width: 600px;\n \
|
50
|
+
\ margin: 5em auto;\n padding: 50px;\n background-color: #fff;\n\
|
51
|
+
\ border-radius: 1em;\n }\n a:link, a:visited {\n color:\
|
52
|
+
\ #38488f;\n text-decoration: none;\n }\n @media (max-width:\
|
53
|
+
\ 700px) {\n body {\n background-color: #fff;\n }\n\
|
54
|
+
\ div {\n width: auto;\n margin: 0 auto;\n \
|
55
|
+
\ border-radius: 0;\n padding: 1em;\n }\n }\n\
|
56
|
+
\ </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n\
|
57
|
+
\ <p>This domain is established to be used for illustrative examples in\
|
58
|
+
\ documents. You may use this\n domain in examples without prior coordination\
|
59
|
+
\ or asking for permission.</p>\n <p><a href=\"http://www.iana.org/domains/example\"\
|
60
|
+
>More information...</a></p>\n</div>\n</body>\n</html>\n"
|
61
|
+
http_version:
|
62
|
+
recorded_at: Sun, 10 Aug 2014 09:34:50 GMT
|
63
|
+
- request:
|
64
|
+
method: get
|
65
|
+
uri: http://example.org/
|
66
|
+
body:
|
67
|
+
encoding: US-ASCII
|
68
|
+
string: ''
|
69
|
+
headers:
|
70
|
+
Accept:
|
71
|
+
- '*/*'
|
72
|
+
User-Agent:
|
73
|
+
- Ruby
|
74
|
+
response:
|
75
|
+
status:
|
76
|
+
code: 200
|
77
|
+
message: OK
|
78
|
+
headers:
|
79
|
+
Accept-Ranges:
|
80
|
+
- bytes
|
81
|
+
Cache-Control:
|
82
|
+
- max-age=604800
|
83
|
+
Content-Type:
|
84
|
+
- text/html
|
85
|
+
Date:
|
86
|
+
- Sun, 10 Aug 2014 09:34:50 GMT
|
87
|
+
Etag:
|
88
|
+
- '"359670651"'
|
89
|
+
Expires:
|
90
|
+
- Sun, 17 Aug 2014 09:34:50 GMT
|
91
|
+
Last-Modified:
|
92
|
+
- Fri, 09 Aug 2013 23:54:35 GMT
|
93
|
+
Server:
|
94
|
+
- ECS (iad/182A)
|
95
|
+
X-Cache:
|
96
|
+
- HIT
|
97
|
+
X-Ec-Custom-Error:
|
98
|
+
- '1'
|
99
|
+
Content-Length:
|
100
|
+
- '1270'
|
101
|
+
body:
|
102
|
+
encoding: US-ASCII
|
103
|
+
string: "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\
|
104
|
+
\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"\
|
105
|
+
text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width,\
|
106
|
+
\ initial-scale=1\" />\n <style type=\"text/css\">\n body {\n \
|
107
|
+
\ background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n \
|
108
|
+
\ font-family: \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial,\
|
109
|
+
\ sans-serif;\n \n }\n div {\n width: 600px;\n \
|
110
|
+
\ margin: 5em auto;\n padding: 50px;\n background-color: #fff;\n\
|
111
|
+
\ border-radius: 1em;\n }\n a:link, a:visited {\n color:\
|
112
|
+
\ #38488f;\n text-decoration: none;\n }\n @media (max-width:\
|
113
|
+
\ 700px) {\n body {\n background-color: #fff;\n }\n\
|
114
|
+
\ div {\n width: auto;\n margin: 0 auto;\n \
|
115
|
+
\ border-radius: 0;\n padding: 1em;\n }\n }\n\
|
116
|
+
\ </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n\
|
117
|
+
\ <p>This domain is established to be used for illustrative examples in\
|
118
|
+
\ documents. You may use this\n domain in examples without prior coordination\
|
119
|
+
\ or asking for permission.</p>\n <p><a href=\"http://www.iana.org/domains/example\"\
|
120
|
+
>More information...</a></p>\n</div>\n</body>\n</html>\n"
|
121
|
+
http_version:
|
122
|
+
recorded_at: Sun, 10 Aug 2014 09:34:50 GMT
|
123
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,70 @@
|
|
1
|
+
<?xml version="1.0"?><!-- This is an example configuration file. Many of the options included here are defaults,
|
2
|
+
and do not need to be specified in a real configuration file. They are provided for
|
3
|
+
convenience of editing, so it is easy to set up a configuration file with non-default options.
|
4
|
+
|
5
|
+
For documentation on the contents of a Saxon configuration file, see
|
6
|
+
http://www.saxonica.com/documentation/index/configuration-file.html
|
7
|
+
-->
|
8
|
+
<configuration edition="HE" xmlns="http://saxon.sf.net/ns/configuration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://saxon.sf.net/ns/configuration config.xsd">
|
9
|
+
<global dtdValidation="false"
|
10
|
+
dtdValidationRecoverable="true"
|
11
|
+
xInclude="false"
|
12
|
+
lineNumbering="true"
|
13
|
+
treeModel="tinyTree"
|
14
|
+
stripSpace="all"
|
15
|
+
expandAttributeDefaults="true"
|
16
|
+
versionOfXml="1.1"
|
17
|
+
preferJaxpParser="true"
|
18
|
+
sourceResolver=""
|
19
|
+
uriResolver="net.sf.saxon.lib.StandardURIResolver"
|
20
|
+
collectionUriResolver="net.sf.saxon.lib.StandardCollectionURIResolver"
|
21
|
+
defaultCollection="file:///tmp"
|
22
|
+
recognizeUriQueryParameters="true"
|
23
|
+
useTypedValueCache="false"
|
24
|
+
parser=""
|
25
|
+
timing="false"
|
26
|
+
traceInstructions="false"
|
27
|
+
allowExternalFunctions="true"
|
28
|
+
traceExternalFunctions="false"
|
29
|
+
optimizationLevel="10"
|
30
|
+
traceOptimizerDecisions="false"
|
31
|
+
collationUriResolver="net.sf.saxon.lib.StandardCollationURIResolver"
|
32
|
+
lazyConstructionMode="false"
|
33
|
+
preEvaluateDoc="false"
|
34
|
+
serializerFactory=""
|
35
|
+
errorListener="net.sf.saxon.lib.StandardErrorListener"
|
36
|
+
errorListenerFile=""
|
37
|
+
traceListener="net.sf.saxon.trace.XSLTTraceListener"
|
38
|
+
traceListenerFile=""
|
39
|
+
usePiDisableOutputEscaping="false"
|
40
|
+
validationWarnings="true"/>
|
41
|
+
<serialization method="xml"
|
42
|
+
indent="yes"/>
|
43
|
+
<collations>
|
44
|
+
<collation uri="http://codepoint/" class="net.sf.saxon.expr.sort.CodepointCollator"/>
|
45
|
+
<collation uri="http://www.microsoft.com/collation/caseblind" lang="en" ignore-case="yes"/>
|
46
|
+
</collations>
|
47
|
+
<localizations defaultLanguage="en" defaultCountry="US">
|
48
|
+
<localization lang="de" class="net.sf.saxon.option.local.Numberer_de"/>
|
49
|
+
<localization lang="en" class="net.sf.saxon.expr.number.Numberer_en"/>
|
50
|
+
</localizations>
|
51
|
+
<xslt recoveryPolicy="recoverWithWarnings"
|
52
|
+
version="2.0"
|
53
|
+
versionWarning="false"
|
54
|
+
schemaAware="false"
|
55
|
+
errorListener="net.sf.saxon.StandardErrorListener">
|
56
|
+
</xslt>
|
57
|
+
<xquery version="1.1"
|
58
|
+
allowUpdate="false"
|
59
|
+
errorListener="net.sf.saxon.StandardErrorListener"
|
60
|
+
errorListenerFile=""
|
61
|
+
moduleUriResolver="net.sf.saxon.lib.StandardModuleURIResolver"
|
62
|
+
inheritNamespaces="true"
|
63
|
+
preserveNamespaces="true"
|
64
|
+
constructionMode="preserve"
|
65
|
+
defaultFunctionNamespace="http://www.w3.org/2005/xpath-functions"
|
66
|
+
defaultElementNamespace=""
|
67
|
+
preserveBoundarySpace="false"
|
68
|
+
requiredContextItemType="document-node()"
|
69
|
+
emptyLeast="true"/>
|
70
|
+
</configuration>
|
@@ -2,14 +2,31 @@ require 'spec_helper'
|
|
2
2
|
require 'saxon/processor'
|
3
3
|
|
4
4
|
describe Saxon::Processor do
|
5
|
-
let(:processor) { Saxon::Processor.new }
|
6
5
|
let(:xsl_file) { File.open(fixture_path('eg.xsl')) }
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
context "without configuration" do
|
8
|
+
let(:processor) { Saxon::Processor.create }
|
9
|
+
|
10
|
+
it "can make a new XSLT instance" do
|
11
|
+
expect(processor.XSLT(xsl_file)).to respond_to(:transform)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can make a new XML instance" do
|
15
|
+
expect(processor.XML(xsl_file)).to be_a(Saxon::XML::Document)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can return the underlying Saxon Processor" do
|
19
|
+
expect(processor.to_java).to respond_to(:new_xslt_compiler)
|
20
|
+
end
|
10
21
|
end
|
11
22
|
|
12
|
-
|
13
|
-
|
23
|
+
context "with a configuration file" do
|
24
|
+
it "works, given a valid config XML file" do
|
25
|
+
processor = Saxon::Processor.create(File.open(fixture_path('config.xml')))
|
26
|
+
|
27
|
+
saxon_processor = processor.to_java
|
28
|
+
configuration = saxon_processor.underlying_configuration
|
29
|
+
expect(configuration.xml_version).to eq(11)
|
30
|
+
end
|
14
31
|
end
|
15
32
|
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'saxon/source_helper'
|
5
|
+
|
6
|
+
java_import org.jruby.embed.io.ReaderInputStream
|
7
|
+
|
8
|
+
describe Saxon::SourceHelper do
|
9
|
+
describe "returning a StreamSource" do
|
10
|
+
context "for input backed by a StringReader" do
|
11
|
+
it "converts a String correctly" do
|
12
|
+
input = "Hello mum"
|
13
|
+
source = Saxon::SourceHelper.to_stream_source(input)
|
14
|
+
stream = ReaderInputStream.new(source.reader)
|
15
|
+
|
16
|
+
expect(source).to respond_to(:system_id)
|
17
|
+
expect(stream.to_io.read).to eq(input)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "for input backed by an InputStream" do
|
22
|
+
it "converts a File correctly" do
|
23
|
+
path = fixture_path('eg.xml')
|
24
|
+
source = Saxon::SourceHelper.to_stream_source(File.open(path))
|
25
|
+
|
26
|
+
expect(source).to respond_to(:system_id)
|
27
|
+
expect(source.input_stream.to_io.read).to eq(File.read(path))
|
28
|
+
end
|
29
|
+
|
30
|
+
it "converts a StringIO correctly" do
|
31
|
+
input = "Hello mum"
|
32
|
+
source = Saxon::SourceHelper.to_stream_source(StringIO.new(input))
|
33
|
+
|
34
|
+
expect(source).to respond_to(:system_id)
|
35
|
+
expect(source.input_stream.to_io.read).to eq(input)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "converts an open-uri'd File correctly" do
|
39
|
+
path = fixture_path('eg.xml')
|
40
|
+
uri = "file://#{path}"
|
41
|
+
source = Saxon::SourceHelper.to_stream_source(open(uri))
|
42
|
+
|
43
|
+
expect(source).to respond_to(:system_id)
|
44
|
+
expect(source.input_stream.to_io.read).to eq(File.read(path))
|
45
|
+
end
|
46
|
+
|
47
|
+
it "converts an open-uri'd Uri correctly", :vcr do
|
48
|
+
uri = "http://example.org/"
|
49
|
+
expected = open(uri).read
|
50
|
+
source = Saxon::SourceHelper.to_stream_source(open(uri))
|
51
|
+
|
52
|
+
expect(source).to respond_to(:system_id)
|
53
|
+
expect(source.input_stream.to_io.read).to eq(expected)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "StreamSource systemId" do
|
58
|
+
context "for inputs where we can't infer the path or URI" do
|
59
|
+
it "is set to nil for Strings" do
|
60
|
+
input = "Hello mum"
|
61
|
+
source = Saxon::SourceHelper.to_stream_source(input)
|
62
|
+
|
63
|
+
expect(source.system_id).to be(nil)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "is set to nil for StringIOs" do
|
67
|
+
input = "Hello mum"
|
68
|
+
source = Saxon::SourceHelper.to_stream_source(StringIO.new(input))
|
69
|
+
|
70
|
+
expect(source.system_id).to be(nil)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "can be set explicitly" do
|
74
|
+
input = "Hello mum"
|
75
|
+
source = Saxon::SourceHelper.to_stream_source(input,
|
76
|
+
system_id: '/path/to/src'
|
77
|
+
)
|
78
|
+
|
79
|
+
expect(source.system_id).to eq('/path/to/src')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "for inputs where we can infer the path or URI" do
|
84
|
+
it "is set to a File's path" do
|
85
|
+
path = fixture_path('eg.xml')
|
86
|
+
source = Saxon::SourceHelper.to_stream_source(File.open(path))
|
87
|
+
|
88
|
+
expect(source.system_id).to eq(path)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "is set to an open-uri'd File's URI" do
|
92
|
+
path = fixture_path('eg.xml')
|
93
|
+
uri = "file://#{path}"
|
94
|
+
source = Saxon::SourceHelper.to_stream_source(open(uri))
|
95
|
+
|
96
|
+
expect(source.system_id).to eq(uri)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "is set to an open-uri'd URI's URI", :vcr do
|
100
|
+
uri = "http://example.org/"
|
101
|
+
source = Saxon::SourceHelper.to_stream_source(open(uri))
|
102
|
+
|
103
|
+
expect(source.system_id).to eq(uri)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "overrides the inferred system ID if set explicitly", :vcr do
|
107
|
+
uri = "http://example.org/"
|
108
|
+
source = Saxon::SourceHelper.to_stream_source(open(uri),
|
109
|
+
system_id: '/path/to/src'
|
110
|
+
)
|
111
|
+
|
112
|
+
expect(source.system_id).to eq('/path/to/src')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/spec/saxon/xml_spec.rb
CHANGED
@@ -1,21 +1,56 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'saxon/xml'
|
3
3
|
|
4
|
+
java_import 'net.sf.saxon.s9api.XdmNodeKind'
|
5
|
+
java_import 'net.sf.saxon.s9api.XdmNode'
|
6
|
+
|
4
7
|
describe Saxon::XML do
|
8
|
+
let(:processor) { Saxon::Processor.create }
|
9
|
+
|
5
10
|
context "parsing a document" do
|
11
|
+
it "returns a Document (wrapper) object" do
|
12
|
+
doc = processor.XML('<input/>')
|
13
|
+
expect(doc.class).to be(Saxon::XML::Document)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "makes the underlying Saxon XDM document available" do
|
17
|
+
doc = processor.XML('<input/>')
|
18
|
+
expect(doc.to_java.class).to be(XdmNode)
|
19
|
+
end
|
20
|
+
|
6
21
|
it "can parse a document from a File object" do
|
7
|
-
|
22
|
+
doc = processor.XML(File.open(fixture_path('eg.xml')))
|
23
|
+
expect(doc.to_java.node_kind).to eq(XdmNodeKind::DOCUMENT)
|
8
24
|
end
|
9
25
|
|
10
26
|
it "can parse a document from a string" do
|
11
27
|
xml = File.read(fixture_path('eg.xml'))
|
12
|
-
|
28
|
+
doc = processor.XML(xml)
|
29
|
+
expect(doc.to_java.node_kind).to eq(XdmNodeKind::DOCUMENT)
|
13
30
|
end
|
14
31
|
|
15
32
|
it "can parse a document from an IO object" do
|
16
33
|
xml = File.read(fixture_path('eg.xml'))
|
17
34
|
io = StringIO.new(xml)
|
18
|
-
|
35
|
+
doc = processor.XML(io)
|
36
|
+
expect(doc.to_java.node_kind).to eq(XdmNodeKind::DOCUMENT)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can set the system ID of a parsed document" do
|
40
|
+
xml = File.read(fixture_path('eg.xml'))
|
41
|
+
doc = processor.XML(xml, system_id: 'http://example.org/')
|
42
|
+
|
43
|
+
expect(doc.to_java.document_uri.to_s).to eq('http://example.org/')
|
19
44
|
end
|
20
45
|
end
|
46
|
+
|
47
|
+
it "can produce a simple serialisation of its content" do
|
48
|
+
doc = processor.XML('<input/>')
|
49
|
+
expect(doc.to_s.strip).to eq('<input/>')
|
50
|
+
end
|
51
|
+
|
52
|
+
it "can return the Saxon::Processor it was created with" do
|
53
|
+
doc = processor.XML('<input/>')
|
54
|
+
expect(doc.processor).to eq(processor)
|
55
|
+
end
|
21
56
|
end
|
data/spec/saxon/xslt_spec.rb
CHANGED
@@ -3,30 +3,47 @@ require 'saxon-xslt'
|
|
3
3
|
require 'stringio'
|
4
4
|
|
5
5
|
describe Saxon::XSLT do
|
6
|
+
let(:processor) { Saxon::Processor.create }
|
7
|
+
|
6
8
|
context "compiling the stylesheet" do
|
7
9
|
it "can compile a stylesheet from a File object" do
|
8
|
-
expect(
|
10
|
+
expect(processor.XSLT(File.open(fixture_path('eg.xsl')))).to respond_to(:transform)
|
9
11
|
end
|
10
12
|
|
11
13
|
it "can compile a stylesheet from a string" do
|
12
14
|
xsl = File.read(fixture_path('eg.xsl'))
|
13
|
-
expect(
|
15
|
+
expect(processor.XSLT(xsl)).to respond_to(:transform)
|
14
16
|
end
|
15
17
|
|
16
18
|
it "can compile a stylesheet from an IO object" do
|
17
19
|
xsl = File.read(fixture_path('eg.xsl'))
|
18
20
|
io = StringIO.new(xsl)
|
19
|
-
expect(
|
21
|
+
expect(processor.XSLT(io)).to respond_to(:transform)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can set the system ID of the Stylesheet correctly" do
|
25
|
+
xml = File.read(fixture_path('simple-xsl-import.xsl'))
|
26
|
+
xslt = processor.XSLT(xml, system_id: fixture_path('samedir.xsl'))
|
27
|
+
|
28
|
+
# We test this by using an XSL which calls xsl:import with a relative path
|
29
|
+
# The relative path breaks unless the system ID is correctly set
|
30
|
+
expect(xslt).to respond_to(:transform)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "can compile a stylesheet from a Saxon::XML::Document" do
|
34
|
+
input = processor.XML(File.open(fixture_path('eg.xsl')))
|
35
|
+
xslt = Saxon::XSLT::Stylesheet.new(input)
|
36
|
+
expect(xslt).to respond_to(:transform)
|
20
37
|
end
|
21
38
|
end
|
22
39
|
|
23
40
|
context "transforming a document" do
|
24
41
|
context "emitting a Document object as the result" do
|
25
|
-
let(:xsl) {
|
26
|
-
let(:xml) {
|
42
|
+
let(:xsl) { processor.XSLT(File.open(fixture_path('eg.xsl'))) }
|
43
|
+
let(:xml) { processor.XML(File.open(fixture_path('eg.xml'))) }
|
27
44
|
|
28
45
|
it "takes a Document object as input for a transformation" do
|
29
|
-
expect
|
46
|
+
expect { xsl.transform(xml) }.not_to raise_error
|
30
47
|
end
|
31
48
|
|
32
49
|
context "the transform result" do
|
@@ -43,3 +60,4 @@ describe Saxon::XSLT do
|
|
43
60
|
end
|
44
61
|
end
|
45
62
|
end
|
63
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
|
1
3
|
module FixtureHelpers
|
2
4
|
def fixture_path(path)
|
3
5
|
File.expand_path(File.join('../fixtures', path), __FILE__)
|
4
6
|
end
|
5
7
|
end
|
6
8
|
|
9
|
+
VCR.configure do |c|
|
10
|
+
c.cassette_library_dir = 'spec/fixtures/cassettes'
|
11
|
+
c.hook_into :webmock
|
12
|
+
c.configure_rspec_metadata!
|
13
|
+
end
|
14
|
+
|
7
15
|
RSpec.configure do |c|
|
8
16
|
c.include FixtureHelpers
|
9
17
|
end
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,49 +1,86 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saxon-xslt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.2.0.1
|
4
|
+
version: 0.5.0
|
6
5
|
platform: java
|
7
6
|
authors:
|
8
7
|
- Matt Patterson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ~>
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '10.1'
|
15
19
|
name: rake
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
16
22
|
version_requirements: !ruby/object:Gem::Requirement
|
17
23
|
requirements:
|
18
24
|
- - ~>
|
19
25
|
- !ruby/object:Gem::Version
|
20
|
-
version: 10.1
|
21
|
-
|
26
|
+
version: '10.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
22
28
|
requirement: !ruby/object:Gem::Requirement
|
23
29
|
requirements:
|
24
30
|
- - ~>
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
|
32
|
+
version: '3.0'
|
33
|
+
name: rspec
|
28
34
|
prerelease: false
|
29
35
|
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
30
41
|
- !ruby/object:Gem::Dependency
|
31
|
-
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.9.2
|
47
|
+
name: vcr
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
32
50
|
version_requirements: !ruby/object:Gem::Requirement
|
33
51
|
requirements:
|
34
52
|
- - ~>
|
35
53
|
- !ruby/object:Gem::Version
|
36
|
-
version: 2.
|
37
|
-
|
54
|
+
version: 2.9.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
38
56
|
requirement: !ruby/object:Gem::Requirement
|
39
57
|
requirements:
|
40
58
|
- - ~>
|
41
59
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
43
|
-
|
60
|
+
version: 1.18.0
|
61
|
+
name: webmock
|
44
62
|
prerelease: false
|
45
63
|
type: :development
|
46
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.18.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.8.7
|
75
|
+
name: yard
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.7
|
83
|
+
description: Wraps the Saxon 9.5 HE XSLT 2.0 processor so that you can transform XSLT 2 stylesheets in JRuby. Sticks closely to the Nokogiri API
|
47
84
|
email:
|
48
85
|
- matt@reprocessed.org
|
49
86
|
executables: []
|
@@ -51,6 +88,7 @@ extensions: []
|
|
51
88
|
extra_rdoc_files: []
|
52
89
|
files:
|
53
90
|
- .gitignore
|
91
|
+
- .rspec
|
54
92
|
- .ruby-version
|
55
93
|
- .travis.yml
|
56
94
|
- Gemfile
|
@@ -60,23 +98,31 @@ files:
|
|
60
98
|
- lib/saxon-xslt.rb
|
61
99
|
- lib/saxon/processor.rb
|
62
100
|
- lib/saxon/s9api.rb
|
63
|
-
- lib/saxon/
|
101
|
+
- lib/saxon/source_helper.rb
|
64
102
|
- lib/saxon/xml.rb
|
65
103
|
- lib/saxon/xslt.rb
|
66
104
|
- lib/saxon/xslt/version.rb
|
67
105
|
- saxon-xslt.gemspec
|
106
|
+
- spec/fixtures/cassettes/Saxon_SourceHelper/returning_a_StreamSource/StreamSource_systemId/for_inputs_where_we_can_infer_the_path_or_URI/is_set_to_an_open-uri_d_URI_s_URI.yml
|
107
|
+
- spec/fixtures/cassettes/Saxon_SourceHelper/returning_a_StreamSource/StreamSource_systemId/for_inputs_where_we_can_infer_the_path_or_URI/overrides_the_inferred_system_ID_if_set_explicitly.yml
|
108
|
+
- spec/fixtures/cassettes/Saxon_SourceHelper/returning_a_StreamSource/for_input_backed_by_an_InputStream/converts_an_open-uri_d_Uri_correctly.yml
|
109
|
+
- spec/fixtures/config.xml
|
68
110
|
- spec/fixtures/eg.xml
|
69
111
|
- spec/fixtures/eg.xsl
|
112
|
+
- spec/fixtures/simple-xsl-import.xsl
|
70
113
|
- spec/saxon/processor_spec.rb
|
114
|
+
- spec/saxon/source_helper_spec.rb
|
71
115
|
- spec/saxon/xml_spec.rb
|
72
116
|
- spec/saxon/xslt_spec.rb
|
73
117
|
- spec/spec_helper.rb
|
74
118
|
- vendor/saxonica/saxon9-unpack.jar
|
119
|
+
- vendor/saxonica/saxon9-xqj.jar
|
75
120
|
- vendor/saxonica/saxon9he.jar
|
76
121
|
homepage: https://github.com/fidothe/saxon-xslt
|
77
122
|
licenses:
|
78
123
|
- MIT
|
79
124
|
- MPL-1.0
|
125
|
+
metadata: {}
|
80
126
|
post_install_message:
|
81
127
|
rdoc_options: []
|
82
128
|
require_paths:
|
@@ -86,23 +132,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
132
|
- - '>='
|
87
133
|
- !ruby/object:Gem::Version
|
88
134
|
version: '0'
|
89
|
-
none: false
|
90
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
136
|
requirements:
|
92
137
|
- - '>='
|
93
138
|
- !ruby/object:Gem::Version
|
94
139
|
version: '0'
|
95
|
-
none: false
|
96
140
|
requirements: []
|
97
141
|
rubyforge_project:
|
98
|
-
rubygems_version: 1.
|
142
|
+
rubygems_version: 2.1.9
|
99
143
|
signing_key:
|
100
|
-
specification_version:
|
101
|
-
summary: Saxon 9.
|
144
|
+
specification_version: 4
|
145
|
+
summary: Saxon 9.5 HE XSLT 2.0 for JRuby with Nokogiri's API
|
102
146
|
test_files:
|
147
|
+
- spec/fixtures/cassettes/Saxon_SourceHelper/returning_a_StreamSource/StreamSource_systemId/for_inputs_where_we_can_infer_the_path_or_URI/is_set_to_an_open-uri_d_URI_s_URI.yml
|
148
|
+
- spec/fixtures/cassettes/Saxon_SourceHelper/returning_a_StreamSource/StreamSource_systemId/for_inputs_where_we_can_infer_the_path_or_URI/overrides_the_inferred_system_ID_if_set_explicitly.yml
|
149
|
+
- spec/fixtures/cassettes/Saxon_SourceHelper/returning_a_StreamSource/for_input_backed_by_an_InputStream/converts_an_open-uri_d_Uri_correctly.yml
|
150
|
+
- spec/fixtures/config.xml
|
103
151
|
- spec/fixtures/eg.xml
|
104
152
|
- spec/fixtures/eg.xsl
|
153
|
+
- spec/fixtures/simple-xsl-import.xsl
|
105
154
|
- spec/saxon/processor_spec.rb
|
155
|
+
- spec/saxon/source_helper_spec.rb
|
106
156
|
- spec/saxon/xml_spec.rb
|
107
157
|
- spec/saxon/xslt_spec.rb
|
108
158
|
- spec/spec_helper.rb
|
159
|
+
has_rdoc:
|
data/lib/saxon/source_helpers.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Saxon
|
2
|
-
module SourceHelpers
|
3
|
-
private
|
4
|
-
|
5
|
-
def to_stream_source(path_io_or_string)
|
6
|
-
StreamSource.new(to_inputstream(path_io_or_string))
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_inputstream(path_io_or_string)
|
10
|
-
return path_io_or_string.to_inputstream if path_io_or_string.respond_to?(:read)
|
11
|
-
return java.io.StringReader.new(path_io_or_string)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|