htmltoword 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +66 -0
- data/lib/htmltoword.rb +19 -12
- data/lib/htmltoword/action_controller.rb +53 -0
- data/lib/htmltoword/configuration.rb +12 -0
- data/lib/htmltoword/document.rb +22 -12
- data/lib/htmltoword/htmltoword_helper.rb +4 -4
- data/lib/htmltoword/version.rb +1 -1
- metadata +4 -5
- data/templates/default.docx +0 -0
- data/xslt/html_to_wordml.xslt +0 -347
- data/xslt/style2.xslt +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 178429bd95194be8c7bd4a48da1b31546ddd2300
|
4
|
+
data.tar.gz: eff915bf0e37d4d5c18061b7bd1fbc982631d944
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d3f0be653044fd40681221f1f17f5e4fa8f27750cb0bf097ccffe7b014e4cf9e19fa139e1fddbc4b247cf6f938887d6d54d63004e3e4ac93404810e43c3ab60
|
7
|
+
data.tar.gz: 99f5b1b6050c53416ba7a91a4ca4c04402db7173235ed1ec050c055c1b09266d7099f894516002f3c1895655b08b36dcfd47f325165ab7a7cc72fa9f77939523
|
data/README.md
CHANGED
@@ -18,6 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
### Standalone
|
20
20
|
|
21
|
+
Using the default word file as template
|
21
22
|
```ruby
|
22
23
|
require 'htmltoword'
|
23
24
|
|
@@ -25,8 +26,57 @@ my_html = '<html><head></head><body><p>Hello</p></body></html>'
|
|
25
26
|
file = Htmltoword::Document.create my_html, file_name
|
26
27
|
```
|
27
28
|
|
29
|
+
Using your custom word file as a template, where you can setup your own style for normal text, h1,h2, etc.
|
30
|
+
```ruby
|
31
|
+
require 'htmltoword'
|
32
|
+
|
33
|
+
# Configure the location of your custom templates
|
34
|
+
Htmltoword.config.custom_templates_path = 'some_path'
|
35
|
+
|
36
|
+
my_html = '<html><head></head><body><p>Hello</p></body></html>'
|
37
|
+
file = Htmltoword::Document.create my_html, file_name, word_template_file_name
|
38
|
+
```
|
39
|
+
|
28
40
|
### With Rails
|
41
|
+
**For htmltoword version >= 0.2**
|
42
|
+
An action controller renderer has been defined, so there's no need to declare the mime-type and you can just respond to .docx format. It will look then for views with the extension ```.docx.erb``` which will provide the HTML that will be rendered in the Word file.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# On your controller.
|
46
|
+
respond_to :docx
|
47
|
+
|
48
|
+
# filename and word_template are optional. By default it will name the file as your action and use the default template provided by the gem. The use of the .docx in the filename and word_template is optional.
|
49
|
+
def my_action
|
50
|
+
# ...
|
51
|
+
respond_with(@object, filename: 'my_file.docx', word_template: 'my_template.docx')
|
52
|
+
# Alternatively, if you don't want to create the .docx.erb template you could
|
53
|
+
respond_with(@object, content: '<html><body>some html</body></html>', filename: 'my_file.docx')
|
54
|
+
end
|
55
|
+
|
56
|
+
def my_action2
|
57
|
+
# ...
|
58
|
+
respond_to do |format|
|
59
|
+
format.docx do
|
60
|
+
render docx: 'my_view', filename: 'my_file.docx'
|
61
|
+
# Alternatively, if you don't want to create the .docx.erb template you could
|
62
|
+
render docx: 'my_file.docx', content: '<html><body>some html</body></html>'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
Example of my_view.docx.erb
|
69
|
+
```
|
70
|
+
<h1> My custom template </h1>
|
71
|
+
<%= render partial: 'my_partial', collection: @objects, as: :item %>
|
72
|
+
```
|
73
|
+
Example of _my_partial.docx.erb
|
74
|
+
```
|
75
|
+
<h3><%= item.title %></h3>
|
76
|
+
<p> My html for item <%= item.id %> goes here </p>
|
77
|
+
```
|
29
78
|
|
79
|
+
**For htmltoword version <= 0.1.8**
|
30
80
|
```ruby
|
31
81
|
# Add mime-type in /config/initializers/mime_types.rb:
|
32
82
|
Mime::Type.register "application/vnd.openxmlformats-officedocument.wordprocessingml.document", :docx
|
@@ -51,6 +101,22 @@ end
|
|
51
101
|
});
|
52
102
|
```
|
53
103
|
|
104
|
+
### Configure templates and xslt paths
|
105
|
+
|
106
|
+
From version 2.0 you can configure the location of default and custom templates and xslt files. By default templates are defined under ```lib/htmltoword/templates``` and xslt under ```lib/htmltoword/xslt```
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
Htmltoword.configure do |config|
|
110
|
+
config.custom_templates_path = 'path_for_custom_templates'
|
111
|
+
# If you modify this path, there should be a 'default.docx' file in there
|
112
|
+
config.default_templates_path = 'path_for_default_template'
|
113
|
+
# If you modify this path, there should be a 'html_to_wordml.xslt' file in there
|
114
|
+
config.default_xslt_path = 'some_path'
|
115
|
+
# The use of additional custom xslt will come soon
|
116
|
+
config.custom_xslt_path = 'some_path'
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
54
120
|
## Features
|
55
121
|
|
56
122
|
All standard html elements are supported and will create the closest equivalent in wordml. For example spans will create inline elements and divs will create block like elements.
|
data/lib/htmltoword.rb
CHANGED
@@ -1,19 +1,26 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
2
|
+
require 'action_controller'
|
3
|
+
require 'action_view'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'zip'
|
6
|
+
require 'htmltoword/configuration'
|
6
7
|
|
7
8
|
module Htmltoword
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
class << self
|
10
|
+
def configure
|
11
|
+
yield configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def configuration
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
end
|
11
17
|
|
12
|
-
|
13
|
-
File.join root, "templates"
|
18
|
+
alias :config :configuration
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
|
-
|
18
|
-
require
|
19
|
-
require
|
22
|
+
|
23
|
+
require 'htmltoword/version'
|
24
|
+
require 'htmltoword/htmltoword_helper'
|
25
|
+
require 'htmltoword/document'
|
26
|
+
require 'htmltoword/action_controller'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
unless defined? Mime::DOCX
|
3
|
+
Mime::Type.register "application/vnd.openxmlformats-officedocument.wordprocessingml.document", :docx
|
4
|
+
end
|
5
|
+
|
6
|
+
ActionController::Renderers.add :docx do |filename, options|
|
7
|
+
unless formats.include?(:docx) || Rails.version < '3.2'
|
8
|
+
formats[0] = :docx
|
9
|
+
end
|
10
|
+
|
11
|
+
if options[:template] == action_name
|
12
|
+
if filename =~ /^([^\/]+)\/(.+)$/
|
13
|
+
options[:prefixes] ||= []
|
14
|
+
options[:prefixes].unshift $1
|
15
|
+
options[:template] = $2
|
16
|
+
else
|
17
|
+
options[:template] = filename
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# disposition / filename
|
22
|
+
disposition = options.delete(:disposition) || 'attachment'
|
23
|
+
if file_name = options.delete(:filename)
|
24
|
+
file_name += ".docx" unless file_name =~ /\.docx$/
|
25
|
+
else
|
26
|
+
file_name = "#{filename.gsub(/^.*\//,'')}.docx"
|
27
|
+
end
|
28
|
+
|
29
|
+
# other properties
|
30
|
+
word_template = options.delete(:word_template) || nil
|
31
|
+
# content will come from property content unless not specified
|
32
|
+
# then it will look for a template.
|
33
|
+
content = options.delete(:content) || render_to_string(options)
|
34
|
+
|
35
|
+
doc = Htmltoword::Document.create content, file_name, word_template
|
36
|
+
send_data File.read(doc.path), :filename => file_name, :type => Mime::DOCX, :disposition => disposition
|
37
|
+
end
|
38
|
+
|
39
|
+
# For respond_with default
|
40
|
+
begin
|
41
|
+
ActionController::Responder
|
42
|
+
rescue LoadError
|
43
|
+
else
|
44
|
+
class ActionController::Responder
|
45
|
+
def to_docx
|
46
|
+
if @default_response
|
47
|
+
@default_response.call(options)
|
48
|
+
else
|
49
|
+
controller.render({:docx => controller.action_name}.merge(options))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Htmltoword
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :default_templates_path, :custom_templates_path, :default_xslt_path, :custom_xslt_path
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@default_templates_path = File.join(File.expand_path('../', __FILE__), 'templates')
|
7
|
+
@custom_templates_path = File.join(File.expand_path('../', __FILE__), 'templates')
|
8
|
+
@default_xslt_path = File.join(File.expand_path('../', __FILE__), 'xslt')
|
9
|
+
@custom_xslt_path = File.join(File.expand_path('../', __FILE__), 'xslt')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/htmltoword/document.rb
CHANGED
@@ -1,26 +1,35 @@
|
|
1
1
|
module Htmltoword
|
2
2
|
class Document
|
3
|
-
|
4
|
-
DOC_XML_FILE = "word/document.xml"
|
5
|
-
BASIC_PATH = ::Htmltoword.root
|
6
|
-
FILE_EXTENSION = ".docx"
|
7
|
-
XSLT_TEMPLATE = File.join(BASIC_PATH, 'xslt', 'html_to_wordml.xslt')
|
8
|
-
|
9
3
|
class << self
|
10
4
|
include HtmltowordHelper
|
11
5
|
|
12
|
-
def create content, file_name
|
13
|
-
|
6
|
+
def create content, file_name, template_name=nil
|
7
|
+
file_name += extension unless file_name =~ /\.docx$/
|
8
|
+
template_name += extension if template_name && !(template_name =~ /\.docx$/)
|
9
|
+
word_file = new(template_file(template_name), file_name)
|
14
10
|
word_file.replace_file content
|
15
11
|
word_file.save
|
16
12
|
end
|
17
13
|
|
18
14
|
def create_with_content template, file_name, content, set=nil
|
19
|
-
|
15
|
+
template += extension unless template =~ /\.docx$/
|
16
|
+
word_file = new(template_file(template), file_name)
|
20
17
|
content = replace_values(content, set) if set
|
21
18
|
word_file.replace_file content
|
22
19
|
word_file.save
|
23
20
|
end
|
21
|
+
|
22
|
+
def extension
|
23
|
+
'.docx'
|
24
|
+
end
|
25
|
+
|
26
|
+
def doc_xml_file
|
27
|
+
'word/document.xml'
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_xslt_template
|
31
|
+
File.join(Htmltoword.config.default_xslt_path, 'html_to_wordml.xslt')
|
32
|
+
end
|
24
33
|
end
|
25
34
|
|
26
35
|
def initialize(template_path, file_name)
|
@@ -42,7 +51,7 @@ module Htmltoword
|
|
42
51
|
#
|
43
52
|
#
|
44
53
|
def save
|
45
|
-
Tempfile.open([file_name,
|
54
|
+
Tempfile.open([file_name, Document.extension], type: 'application/zip') do |output_file|
|
46
55
|
Zip::File.open(@template_path) do |template_zip|
|
47
56
|
Zip::OutputStream.open(output_file.path) do |out|
|
48
57
|
template_zip.each do |entry|
|
@@ -59,9 +68,10 @@ module Htmltoword
|
|
59
68
|
end
|
60
69
|
end
|
61
70
|
|
62
|
-
def replace_file html, file_name=
|
71
|
+
def replace_file html, file_name=Document.doc_xml_file
|
72
|
+
html = html.presence || '<body></body>'
|
63
73
|
source = Nokogiri::HTML(html.gsub(/>\s+</, "><"))
|
64
|
-
xslt = Nokogiri::XSLT( File.read(
|
74
|
+
xslt = Nokogiri::XSLT( File.read(Document.default_xslt_template) )
|
65
75
|
source = xslt.transform( source ) unless (source/"/html").blank?
|
66
76
|
@replaceable_files[file_name] = source.to_s
|
67
77
|
end
|
@@ -2,8 +2,8 @@ module Htmltoword
|
|
2
2
|
module HtmltowordHelper
|
3
3
|
|
4
4
|
def template_file template_file_name=nil
|
5
|
-
default_path = File.join(::Htmltoword.
|
6
|
-
template_path = template_file_name.present? ? File.join(::Htmltoword.
|
5
|
+
default_path = File.join(::Htmltoword.config.default_templates_path, 'default.docx')
|
6
|
+
template_path = template_file_name.present? ? File.join(::Htmltoword.config.custom_templates_path, template_file_name) : ''
|
7
7
|
File.exist?(template_path) ? template_path : default_path
|
8
8
|
end
|
9
9
|
|
@@ -16,13 +16,13 @@ module Htmltoword
|
|
16
16
|
data_transform = f.attr("data-transform")
|
17
17
|
if value.is_a? Hash
|
18
18
|
view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
19
|
-
final_value = view.render
|
19
|
+
final_value = view.render 'partials/answer_table', answer: value
|
20
20
|
fragment = doc.root.parse(final_value).first
|
21
21
|
new_node = doc.root.add_child(fragment)
|
22
22
|
f.parent.replace new_node
|
23
23
|
elsif value.is_a? Time
|
24
24
|
f.content = I18n.l(value.to_date, format: date_format.to_sym)
|
25
|
-
elsif data_transform ==
|
25
|
+
elsif data_transform == 'capitalized'
|
26
26
|
f.content = value.mb_chars.capitalize rescue value
|
27
27
|
else
|
28
28
|
f.content = value
|
data/lib/htmltoword/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htmltoword
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Frandsen, Cristina Matonte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -104,12 +104,11 @@ files:
|
|
104
104
|
- README.md
|
105
105
|
- Rakefile
|
106
106
|
- lib/htmltoword.rb
|
107
|
+
- lib/htmltoword/action_controller.rb
|
108
|
+
- lib/htmltoword/configuration.rb
|
107
109
|
- lib/htmltoword/document.rb
|
108
110
|
- lib/htmltoword/htmltoword_helper.rb
|
109
111
|
- lib/htmltoword/version.rb
|
110
|
-
- templates/default.docx
|
111
|
-
- xslt/html_to_wordml.xslt
|
112
|
-
- xslt/style2.xslt
|
113
112
|
homepage: http://github.com/nickfrandsen/htmltoword
|
114
113
|
licenses:
|
115
114
|
- MIT
|
data/templates/default.docx
DELETED
Binary file
|
data/xslt/html_to_wordml.xslt
DELETED
@@ -1,347 +0,0 @@
|
|
1
|
-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
2
|
-
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
|
3
|
-
xmlns:o="urn:schemas-microsoft-com:office:office"
|
4
|
-
xmlns:v="urn:schemas-microsoft-com:vml"
|
5
|
-
xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
|
6
|
-
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
|
7
|
-
xmlns:w10="urn:schemas-microsoft-com:office:word"
|
8
|
-
xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
|
9
|
-
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
|
10
|
-
xmlns:ext="http://www.xmllab.net/wordml2html/ext"
|
11
|
-
xmlns:java="http://xml.apache.org/xalan/java"
|
12
|
-
xmlns:str="http://exslt.org/common"
|
13
|
-
xmlns:fn="http://www.w3.org/2005/xpath-functions"
|
14
|
-
version="1.0"
|
15
|
-
exclude-result-prefixes="java msxsl ext w o v WX aml w10">
|
16
|
-
|
17
|
-
|
18
|
-
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" />
|
19
|
-
|
20
|
-
<xsl:template match="/">
|
21
|
-
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14">
|
22
|
-
<xsl:apply-templates />
|
23
|
-
</w:document>
|
24
|
-
</xsl:template>
|
25
|
-
|
26
|
-
<xsl:template match="head" />
|
27
|
-
|
28
|
-
<xsl:template match="body">
|
29
|
-
<xsl:comment>
|
30
|
-
KNOWN BUGS:
|
31
|
-
div
|
32
|
-
h2
|
33
|
-
div
|
34
|
-
textnode (WONT BE WRAPPED IN A W:P)
|
35
|
-
div
|
36
|
-
table
|
37
|
-
span
|
38
|
-
text
|
39
|
-
</xsl:comment>
|
40
|
-
<w:body>
|
41
|
-
<xsl:apply-templates/>
|
42
|
-
<w:sectPr>
|
43
|
-
<w:pgSz w:w="11906" w:h="16838"/>
|
44
|
-
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
|
45
|
-
<w:cols w:space="708"/>
|
46
|
-
<w:docGrid w:linePitch="360"/>
|
47
|
-
</w:sectPr>
|
48
|
-
</w:body>
|
49
|
-
</xsl:template>
|
50
|
-
|
51
|
-
<xsl:template match="body/*[not(*)]">
|
52
|
-
<w:p>
|
53
|
-
<xsl:call-template name="text-alignment" />
|
54
|
-
<w:r>
|
55
|
-
<w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
|
56
|
-
</w:r>
|
57
|
-
</w:p>
|
58
|
-
</xsl:template>
|
59
|
-
|
60
|
-
<xsl:template match="div[not(ancestor::td) and not(ancestor::th) and not(ancestor::p) and not(descendant::div) and not(descendant::p) and not(descendant::h1) and not(descendant::h2) and not(descendant::h3) and not(descendant::h4) and not(descendant::h5) and not(descendant::h6) and not(descendant::table) and not(descendant::li)]">
|
61
|
-
<xsl:comment>Divs should create a p if nothing above them has and nothing below them will</xsl:comment>
|
62
|
-
<w:p>
|
63
|
-
<xsl:call-template name="text-alignment" />
|
64
|
-
<xsl:apply-templates />
|
65
|
-
</w:p>
|
66
|
-
</xsl:template>
|
67
|
-
|
68
|
-
<xsl:template match="div">
|
69
|
-
<xsl:apply-templates />
|
70
|
-
</xsl:template>
|
71
|
-
|
72
|
-
<!-- TODO: make this prettier. Headings shouldn't enter in template from L51 -->
|
73
|
-
<xsl:template match="body/h1|body/h2|body/h3|body/h4|body/h5|body/h6|h1|h2|h3|h4|h5|h6">
|
74
|
-
<w:p>
|
75
|
-
<w:r>
|
76
|
-
<w:rPr>
|
77
|
-
<w:rStyle w:val="{name(.)}"/>
|
78
|
-
</w:rPr>
|
79
|
-
<w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
|
80
|
-
</w:r>
|
81
|
-
</w:p>
|
82
|
-
</xsl:template>
|
83
|
-
|
84
|
-
<xsl:template match="p">
|
85
|
-
<w:p>
|
86
|
-
<xsl:call-template name="text-alignment" />
|
87
|
-
<xsl:apply-templates />
|
88
|
-
</w:p>
|
89
|
-
</xsl:template>
|
90
|
-
|
91
|
-
<xsl:template match="li">
|
92
|
-
<w:p>
|
93
|
-
<w:r>
|
94
|
-
<w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
|
95
|
-
</w:r>
|
96
|
-
</w:p>
|
97
|
-
</xsl:template>
|
98
|
-
|
99
|
-
<xsl:template match="span[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
100
|
-
|a[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
101
|
-
|small[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
102
|
-
|strong[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
103
|
-
|em[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
104
|
-
|i[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
105
|
-
|b[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]">
|
106
|
-
<xsl:comment>
|
107
|
-
In the following situation:
|
108
|
-
|
109
|
-
div
|
110
|
-
h2
|
111
|
-
span
|
112
|
-
textnode
|
113
|
-
span
|
114
|
-
textnode
|
115
|
-
p
|
116
|
-
|
117
|
-
The div template will not create a w:p because the div contains a h2. Therefore we need to wrap the inline elements span|a|small in a p here.
|
118
|
-
</xsl:comment>
|
119
|
-
<w:p>
|
120
|
-
<xsl:apply-templates />
|
121
|
-
</w:p>
|
122
|
-
</xsl:template>
|
123
|
-
|
124
|
-
<xsl:template match="text()[not(parent::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]">
|
125
|
-
<xsl:comment>
|
126
|
-
In the following situation:
|
127
|
-
|
128
|
-
div
|
129
|
-
h2
|
130
|
-
textnode
|
131
|
-
p
|
132
|
-
|
133
|
-
The div template will not create a w:p because the div contains a h2. Therefore we need to wrap the textnode in a p here.
|
134
|
-
</xsl:comment>
|
135
|
-
<w:p>
|
136
|
-
<w:r>
|
137
|
-
<w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
|
138
|
-
</w:r>
|
139
|
-
</w:p>
|
140
|
-
</xsl:template>
|
141
|
-
|
142
|
-
<xsl:template match="span[contains(concat(' ', @class, ' '), ' h ')]">
|
143
|
-
<xsl:comment>
|
144
|
-
This template adds MS Word highlighting ability.
|
145
|
-
</xsl:comment>
|
146
|
-
<xsl:variable name="color">
|
147
|
-
<xsl:choose>
|
148
|
-
<xsl:when test="./@data-style='pink'">magenta</xsl:when>
|
149
|
-
<xsl:when test="./@data-style='blue'">cyan</xsl:when>
|
150
|
-
<xsl:when test="./@data-style='orange'">darkYellow</xsl:when>
|
151
|
-
<xsl:otherwise><xsl:value-of select="./@data-style"/></xsl:otherwise>
|
152
|
-
</xsl:choose>
|
153
|
-
</xsl:variable>
|
154
|
-
<xsl:choose>
|
155
|
-
<xsl:when test="preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div">
|
156
|
-
<w:p>
|
157
|
-
<w:r>
|
158
|
-
<w:rPr>
|
159
|
-
<w:highlight w:val="{$color}"/>
|
160
|
-
</w:rPr>
|
161
|
-
<w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
|
162
|
-
</w:r>
|
163
|
-
</w:p>
|
164
|
-
</xsl:when>
|
165
|
-
<xsl:otherwise>
|
166
|
-
<w:r>
|
167
|
-
<w:rPr>
|
168
|
-
<w:highlight w:val="{$color}"/>
|
169
|
-
</w:rPr>
|
170
|
-
<w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
|
171
|
-
</w:r>
|
172
|
-
</xsl:otherwise>
|
173
|
-
</xsl:choose>
|
174
|
-
</xsl:template>
|
175
|
-
|
176
|
-
<xsl:template match="div[contains(concat(' ', @class, ' '), ' -page-break ')]">
|
177
|
-
<w:p>
|
178
|
-
<w:r>
|
179
|
-
<w:br w:type="page" />
|
180
|
-
</w:r>
|
181
|
-
</w:p>
|
182
|
-
<xsl:apply-templates />
|
183
|
-
</xsl:template>
|
184
|
-
|
185
|
-
<xsl:template match="details" />
|
186
|
-
|
187
|
-
<xsl:template name="tableborders">
|
188
|
-
<xsl:variable name="border">
|
189
|
-
<xsl:choose>
|
190
|
-
<xsl:when test="contains(concat(' ', @class, ' '), ' table-bordered ')">6</xsl:when>
|
191
|
-
<xsl:when test="not(@border)">0</xsl:when>
|
192
|
-
<xsl:otherwise><xsl:value-of select="./@border * 6"/></xsl:otherwise>
|
193
|
-
</xsl:choose>
|
194
|
-
</xsl:variable>
|
195
|
-
<xsl:variable name="bordertype">
|
196
|
-
<xsl:choose>
|
197
|
-
<xsl:when test="$border=0">none</xsl:when>
|
198
|
-
<xsl:otherwise>single</xsl:otherwise>
|
199
|
-
</xsl:choose>
|
200
|
-
</xsl:variable>
|
201
|
-
<w:tblBorders>
|
202
|
-
<w:top w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
|
203
|
-
<w:left w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
|
204
|
-
<w:bottom w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
|
205
|
-
<w:right w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
|
206
|
-
<w:insideH w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
|
207
|
-
<w:insideV w:val="{$bordertype}" w:sz="{$border}" w:space="0" w:color="auto"/>
|
208
|
-
</w:tblBorders>
|
209
|
-
</xsl:template>
|
210
|
-
|
211
|
-
<xsl:template match="table">
|
212
|
-
<w:tbl>
|
213
|
-
<w:tblPr>
|
214
|
-
<w:tblStyle w:val="TableGrid"/>
|
215
|
-
<w:tblW w:w="0" w:type="auto"/>
|
216
|
-
<xsl:call-template name="tableborders"/>
|
217
|
-
<w:tblLook w:val="0600" w:firstRow="0" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:noHBand="1" w:noVBand="1"/>
|
218
|
-
</w:tblPr>
|
219
|
-
<w:tblGrid>
|
220
|
-
<w:gridCol w:w="2310"/>
|
221
|
-
<w:gridCol w:w="2310"/>
|
222
|
-
</w:tblGrid>
|
223
|
-
<xsl:apply-templates />
|
224
|
-
</w:tbl>
|
225
|
-
</xsl:template>
|
226
|
-
|
227
|
-
<xsl:template match="tbody">
|
228
|
-
<xsl:apply-templates />
|
229
|
-
</xsl:template>
|
230
|
-
|
231
|
-
<xsl:template match="thead">
|
232
|
-
<xsl:choose>
|
233
|
-
<xsl:when test="count(./tr) = 0">
|
234
|
-
<w:tr><xsl:apply-templates /></w:tr>
|
235
|
-
</xsl:when>
|
236
|
-
<xsl:otherwise>
|
237
|
-
<xsl:apply-templates />
|
238
|
-
</xsl:otherwise>
|
239
|
-
</xsl:choose>
|
240
|
-
</xsl:template>
|
241
|
-
|
242
|
-
<xsl:template match="tr">
|
243
|
-
<xsl:if test="string-length(.) > 0">
|
244
|
-
<w:tr>
|
245
|
-
<xsl:apply-templates />
|
246
|
-
</w:tr>
|
247
|
-
</xsl:if>
|
248
|
-
</xsl:template>
|
249
|
-
|
250
|
-
<xsl:template match="th">
|
251
|
-
<w:tc>
|
252
|
-
<w:p>
|
253
|
-
<w:r>
|
254
|
-
<w:rPr>
|
255
|
-
<w:b />
|
256
|
-
</w:rPr>
|
257
|
-
<w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
|
258
|
-
</w:r>
|
259
|
-
</w:p>
|
260
|
-
</w:tc>
|
261
|
-
</xsl:template>
|
262
|
-
|
263
|
-
<xsl:template match="td">
|
264
|
-
<w:tc>
|
265
|
-
<xsl:call-template name="block">
|
266
|
-
<xsl:with-param name="current" select="." />
|
267
|
-
<xsl:with-param name="class" select="@class" />
|
268
|
-
<xsl:with-param name="style" select="@style" />
|
269
|
-
</xsl:call-template>
|
270
|
-
</w:tc>
|
271
|
-
</xsl:template>
|
272
|
-
|
273
|
-
<xsl:template name="block">
|
274
|
-
<xsl:param name="current" />
|
275
|
-
<xsl:param name="class" />
|
276
|
-
<xsl:param name="style" />
|
277
|
-
<xsl:if test="count($current/*|$current/text()) = 0">
|
278
|
-
<w:p/>
|
279
|
-
</xsl:if>
|
280
|
-
<xsl:for-each select="$current/*|$current/text()">
|
281
|
-
<xsl:choose>
|
282
|
-
<xsl:when test="name(.) = 'table'">
|
283
|
-
<xsl:apply-templates select="." />
|
284
|
-
<w:p/>
|
285
|
-
</xsl:when>
|
286
|
-
<xsl:when test="contains('|p|h1|h2|h3|h4|h5|h6|ul|ol|', concat('|', name(.), '|'))">
|
287
|
-
<xsl:apply-templates select="." />
|
288
|
-
</xsl:when>
|
289
|
-
<xsl:when test="descendant::table|descendant::p|descendant::h1|descendant::h2|descendant::h3|descendant::h4|descendant::h5|descendant::h6|descendant::li">
|
290
|
-
<xsl:call-template name="block">
|
291
|
-
<xsl:with-param name="current" select="."/>
|
292
|
-
</xsl:call-template>
|
293
|
-
</xsl:when>
|
294
|
-
<xsl:otherwise>
|
295
|
-
<w:p>
|
296
|
-
<xsl:call-template name="text-alignment">
|
297
|
-
<xsl:with-param name="class" select="$class" />
|
298
|
-
<xsl:with-param name="style" select="$style" />
|
299
|
-
</xsl:call-template>
|
300
|
-
<xsl:apply-templates select="." />
|
301
|
-
</w:p>
|
302
|
-
</xsl:otherwise>
|
303
|
-
</xsl:choose>
|
304
|
-
</xsl:for-each>
|
305
|
-
</xsl:template>
|
306
|
-
|
307
|
-
<xsl:template match="text()">
|
308
|
-
<xsl:if test="string-length(.) > 0">
|
309
|
-
<w:r>
|
310
|
-
<xsl:if test="ancestor::i or ancestor::em">
|
311
|
-
<w:rPr>
|
312
|
-
<w:i />
|
313
|
-
</w:rPr>
|
314
|
-
</xsl:if>
|
315
|
-
<xsl:if test="ancestor::b or ancestor::strong">
|
316
|
-
<w:rPr>
|
317
|
-
<w:b />
|
318
|
-
</w:rPr>
|
319
|
-
</xsl:if>
|
320
|
-
<w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
|
321
|
-
</w:r>
|
322
|
-
</xsl:if>
|
323
|
-
</xsl:template>
|
324
|
-
|
325
|
-
<xsl:template match="*">
|
326
|
-
<xsl:apply-templates/>
|
327
|
-
</xsl:template>
|
328
|
-
|
329
|
-
<xsl:template name="text-alignment">
|
330
|
-
<xsl:param name="class" select="@class" />
|
331
|
-
<xsl:param name="style" select="@style" />
|
332
|
-
<xsl:variable name="alignment">
|
333
|
-
<xsl:choose>
|
334
|
-
<xsl:when test="contains(concat(' ', $class, ' '), ' center ') or contains(translate(normalize-space($style),' ',''), 'text-align:center')">center</xsl:when>
|
335
|
-
<xsl:when test="contains(concat(' ', $class, ' '), ' right ') or contains(translate(normalize-space($style),' ',''), 'text-align:right')">right</xsl:when>
|
336
|
-
<xsl:when test="contains(concat(' ', $class, ' '), ' left ') or contains(translate(normalize-space($style),' ',''), 'text-align:left')">left</xsl:when>
|
337
|
-
<xsl:when test="contains(concat(' ', $class, ' '), ' justify ') or contains(translate(normalize-space($style),' ',''), 'text-align:justify')">both</xsl:when>
|
338
|
-
<xsl:otherwise></xsl:otherwise>
|
339
|
-
</xsl:choose>
|
340
|
-
</xsl:variable>
|
341
|
-
<xsl:if test="string-length(normalize-space($alignment)) > 0">
|
342
|
-
<w:pPr>
|
343
|
-
<w:jc w:val="{$alignment}"/>
|
344
|
-
</w:pPr>
|
345
|
-
</xsl:if>
|
346
|
-
</xsl:template>
|
347
|
-
</xsl:stylesheet>
|
data/xslt/style2.xslt
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
2
|
-
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
|
3
|
-
xmlns:o="urn:schemas-microsoft-com:office:office"
|
4
|
-
xmlns:v="urn:schemas-microsoft-com:vml"
|
5
|
-
xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
|
6
|
-
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
|
7
|
-
xmlns:w10="urn:schemas-microsoft-com:office:word"
|
8
|
-
xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
|
9
|
-
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
|
10
|
-
xmlns:ext="http://www.xmllab.net/wordml2html/ext"
|
11
|
-
xmlns:java="http://xml.apache.org/xalan/java"
|
12
|
-
xmlns:str="http://exslt.org/common"
|
13
|
-
xmlns:fn="http://www.w3.org/2005/xpath-functions"
|
14
|
-
version="1.0"
|
15
|
-
exclude-result-prefixes="java msxsl ext w o v WX aml w10">
|
16
|
-
|
17
|
-
|
18
|
-
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" />
|
19
|
-
|
20
|
-
<xsl:template match="/ | html">
|
21
|
-
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14">
|
22
|
-
<xsl:apply-templates select="//body"/>
|
23
|
-
</w:document>
|
24
|
-
</xsl:template>
|
25
|
-
|
26
|
-
<xsl:template match="body">
|
27
|
-
<w:body>
|
28
|
-
<w:p>
|
29
|
-
<xsl:apply-templates/>
|
30
|
-
</w:p>
|
31
|
-
<w:sectPr>
|
32
|
-
<w:pgSz w:w="11906" w:h="16838"/>
|
33
|
-
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
|
34
|
-
<w:cols w:space="708"/>
|
35
|
-
<w:docGrid w:linePitch="360"/>
|
36
|
-
</w:sectPr>
|
37
|
-
</w:body>
|
38
|
-
</xsl:template>
|
39
|
-
|
40
|
-
<xsl:template match="h1|h2|h3|li|span">
|
41
|
-
<w:br/>
|
42
|
-
<w:r>
|
43
|
-
<xsl:comment>Im block</xsl:comment>
|
44
|
-
<w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
|
45
|
-
</w:r>
|
46
|
-
<w:br/>
|
47
|
-
</xsl:template>
|
48
|
-
|
49
|
-
</xsl:stylesheet>
|