saxon-xslt 0.8.1-java → 0.8.2-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78d51bc1d1ad929a2a3a9fdfd306d393a071b79f
4
- data.tar.gz: f617460d59c5c03e8dea14b09a0b7feee40fb04b
3
+ metadata.gz: 30d7250ed416d25ff3453a50b044a4c9fb5f9616
4
+ data.tar.gz: 8510336f672dfa823ac396c433b7427c2b234bc8
5
5
  SHA512:
6
- metadata.gz: 9c7936845c41ddf3bd624fcb807e552a4b5c593cb29d98fcdde11088661d976be956e2aef5d2dbc14a662ff032333f02e331daaeeef7c36cb13f791f1e592806
7
- data.tar.gz: de3633e9baf0ce519f6c1888a6eb7e136d971066c1e7e8fa08481452d7ac3ad0eea469184babf28512a7730ac7bc5f12941ee3133604a49100d67e731c945a75
6
+ metadata.gz: e2cf95510646c2b98f558ee08f134e7069a9c6e9362f62fa0cc2c27e0ccedeb58f1c6ff70ac8a698700b441b3f71560ef676362472f9305afae84d52011a1d37
7
+ data.tar.gz: 4c01b6dceb736867f58ac4498e8ad7f6afdedf3b8e55979c41bbe2fcb5a794d504f747731676a2cac0818f7278da2fa881d8667ee0c013e8311e69e8bfd84f36
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Saxon::Xslt
2
2
 
3
- Wraps the Saxon 9 HE XSLT processor Java API so it's easy to use from your JRuby project, with an API modelled on Nokogiri's.
3
+ Wraps the Saxon 9 XSLT processor Java API so it's easy to use from your JRuby project, with an API modelled on Nokogiri's.
4
4
 
5
- Saxon HE is a Java library, so saxon-xslt only runs under JRuby.
5
+ Saxon is a Java library, so saxon-xslt only runs under JRuby.
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/saxon-xslt.svg)](http://badge.fury.io/rb/saxon-xslt)
8
8
  [![Build Status](https://travis-ci.org/fidothe/saxon-xslt.png)](https://travis-ci.org/fidothe/saxon-xslt)
@@ -54,16 +54,13 @@ For those familiar with the Saxon API, names are passed directly to the QName co
54
54
  Values are evaluated as XPath expressions in context of the document being transformed; this means
55
55
  that, to pass a string, you must pass an XPath that resolves to a string, i.e. "'You must wrap strings in quotes'"
56
56
 
57
- ## Saxon version
58
- `saxon-xslt` 0.7 includes Saxon HE 9.5.1.7
59
-
60
57
  ## Differences between Saxon and Nokogiri
61
58
 
62
59
  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:
63
60
 
64
61
  ```ruby
65
62
  require 'saxon-xslt'
66
- processor = Saxon::Processor.new(File.open('/path/to/config.xml'))
63
+ processor = Saxon::Processor.create(File.open('/path/to/config.xml'))
67
64
  transformer = processor.XSLT(File.open('/path/to/your.xsl'))
68
65
  input = processor.XML(File.open('/path/to/your.xml'))
69
66
  output = transformer.transform(input)
@@ -88,6 +85,24 @@ xslt = Saxon.XSLT("<xsl:stylesheet>...</xsl:stylesheet>",
88
85
 
89
86
  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"/>`.
90
87
 
88
+ ## Saxon versions (HE, PE, EE)
89
+ `saxon-xslt` 0.8.2 includes Saxon HE 9.8.0.6 - you don't need to download Saxon yourself. Saxon PE and EE are paid-for versions with more features.
90
+
91
+ If you have a license for Saxon PE or EE, then you can use them by passing their location and the location of your `.lic` license file in as follows:
92
+
93
+ ```ruby
94
+ require 'saxon-xslt'
95
+
96
+ # Tell us where your Saxon Jars are.
97
+ Saxon::Loader.load!('/path/to/dir/containing/saxon-jars')
98
+ # Create a licensed Configuration object
99
+ config = Saxon::Configuration.create_licensed('/path/to/saxon-license.lic')
100
+ # Create a Processor from your licensed Configuration
101
+ processor = Saxon::Processor.create(config)
102
+ # Go!
103
+ transformer = processor.XSLT(File.open('/path/to/your.xsl'))
104
+ ```
105
+
91
106
  ## Contributing
92
107
 
93
108
  1. Fork it
@@ -9,6 +9,8 @@ module Saxon
9
9
  module Loader
10
10
  LOAD_SEMAPHORE = Mutex.new
11
11
 
12
+ # Error raised if Saxon::Loader.load! is called but the path handed
13
+ # in does not exist or is not a directory
12
14
  class NoJarsError < StandardError
13
15
  def initialize(path)
14
16
  @path = path
@@ -19,6 +21,8 @@ module Saxon
19
21
  end
20
22
  end
21
23
 
24
+ # Error raised if Saxon::Loader.load! is called but the path handed
25
+ # in does not contain the Saxon .jars
22
26
  class MissingJarError < StandardError
23
27
  def initialize(path)
24
28
  @path = path
@@ -29,25 +33,10 @@ module Saxon
29
33
  end
30
34
  end
31
35
 
32
- def self.main_jar(path)
33
- ['saxon9he.jar', 'saxon9pe.jar', 'saxon9ee.jar'].map { |jar| path.join(jar) }.find { |jar| jar.file? }
34
- end
35
-
36
- def self.extra_jars(path)
37
- optional = ['saxon9-unpack.jar', 'saxon9-sql.jar'].map { |jar| path.join(jar) }.select { |jar| jar.file? }
38
- icu = path.children.find { |jar| jar.extname == '.jar' && !jar.basename.to_s.match(/^saxon-icu|^icu4j/).nil? }
39
- ([icu] + optional).compact
40
- end
41
-
42
- def self.jars_not_on_classpath?
43
- begin
44
- Java::net.sf.saxon.s9api.Processor
45
- false
46
- rescue
47
- true
48
- end
49
- end
50
-
36
+ # @param saxon_home [String, Pathname] the path to the dir containing
37
+ # Saxon's .jars. Defaults to the vendored Saxon HE
38
+ # @return [true, false] Returns true if Saxon had not been loaded and
39
+ # is now, and false if Saxon was already loaded
51
40
  def self.load!(saxon_home = File.expand_path('../../../vendor/saxonica', __FILE__))
52
41
  return false if @saxon_loaded
53
42
  LOAD_SEMAPHORE.synchronize do
@@ -73,6 +62,25 @@ module Saxon
73
62
 
74
63
  private
75
64
 
65
+ def self.main_jar(path)
66
+ ['saxon9he.jar', 'saxon9pe.jar', 'saxon9ee.jar'].map { |jar| path.join(jar) }.find { |jar| jar.file? }
67
+ end
68
+
69
+ def self.extra_jars(path)
70
+ optional = ['saxon9-unpack.jar', 'saxon9-sql.jar'].map { |jar| path.join(jar) }.select { |jar| jar.file? }
71
+ icu = path.children.find { |jar| jar.extname == '.jar' && !jar.basename.to_s.match(/^saxon-icu|^icu4j/).nil? }
72
+ ([icu] + optional).compact
73
+ end
74
+
75
+ def self.jars_not_on_classpath?
76
+ begin
77
+ Java::net.sf.saxon.s9api.Processor
78
+ false
79
+ rescue
80
+ true
81
+ end
82
+ end
83
+
76
84
  def self.add_jars_to_classpath!(saxon_home, jars)
77
85
  jars.each do |jar|
78
86
  $CLASSPATH << jar.to_s
@@ -91,17 +91,30 @@ module Saxon
91
91
 
92
92
  private
93
93
 
94
- def set_params(transformer, document, params)
94
+ def resolve_q_name(q_name_or_string)
95
+ case q_name_or_string
96
+ when S9API::QName
97
+ q_name_or_string
98
+ else
99
+ S9API::QName.new(q_name_or_string.to_s)
100
+ end
101
+ end
102
+
103
+ def params_as_kv_pairs(params)
95
104
  case params
96
105
  when Hash
97
- params.each do |k,v|
98
- transformer.setParameter(S9API::QName.new(k.to_s), document.xpath(v))
99
- end
106
+ params
100
107
  when Array
101
- params.each_slice(2) do |k,v|
108
+ params.each_slice(2).map { |k,v|
102
109
  raise ArgumentError.new("Odd number of values passed as params: #{params}") if v.nil?
103
- transformer.setParameter(S9API::QName.new(k.to_s), document.xpath(v))
104
- end
110
+ [k, v]
111
+ }
112
+ end
113
+ end
114
+
115
+ def set_params(transformer, document, params)
116
+ params_as_kv_pairs(params).each do |k,v|
117
+ transformer.setParameter(resolve_q_name(k), document.xpath(v))
105
118
  end
106
119
  end
107
120
  end
@@ -1,5 +1,5 @@
1
1
  module Saxon
2
2
  module XSLT
3
- VERSION = "0.8.1"
3
+ VERSION = "0.8.2"
4
4
  end
5
5
  end
@@ -1,6 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eg="http://example.org/ns" version="2.0" exclude-result-prefixes="eg">
3
3
  <xsl:param name="testparam">default</xsl:param>
4
+ <xsl:param name="eg:qname-param" select="false()"/>
4
5
  <xsl:template match="input">
5
6
  <xsl:choose>
6
7
  <xsl:when test="$testparam = 'default'">
@@ -17,5 +18,8 @@
17
18
  </output>
18
19
  </xsl:otherwise>
19
20
  </xsl:choose>
21
+ <xsl:if test="$eg:qname-param">
22
+ <qname-param/>
23
+ </xsl:if>
20
24
  </xsl:template>
21
25
  </xsl:stylesheet>
@@ -101,7 +101,20 @@ describe Saxon::XSLT do
101
101
  let(:result) { xsl.transform(xml, ["testparam", "local-name(/input)"]) }
102
102
 
103
103
  it "should contain the name of the tag" do
104
- expect(result.to_s.strip).to include('Select works')
104
+ expect(result.to_s.strip).to include('Select works')
105
+ end
106
+ end
107
+
108
+ context "passing a QName-using param" do
109
+ let(:result) { xsl.transform(xml, {Saxon::S9API::QName.fromClarkName('{http://example.org/ns}qname-param') => "true()"}) }
110
+
111
+ it "should not contain the qname-related output when the param isn't passed" do
112
+ result = xsl.transform(xml)
113
+ expect(result.to_s.strip).to_not include('<qname-param/>')
114
+ end
115
+
116
+ it "should contain the qname-related outputtag" do
117
+ expect(result.to_s.strip).to include('<qname-param/>')
105
118
  end
106
119
  end
107
120
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saxon-xslt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: java
6
6
  authors:
7
7
  - Matt Patterson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-01 00:00:00.000000000 Z
11
+ date: 2018-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement