Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Only parse XSLT files once
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Nov 15, 2016
1 parent 155389a commit 4bd49b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lib/dor/datastreams/default_object_rights_ds.rb
@@ -1,5 +1,9 @@
module Dor
class DefaultObjectRightsDS < ActiveFedora::OmDatastream
# Note that the XSL file was taken from the (apparently defunct) nokogiri-pretty project:
# https://github.com/tobym/nokogiri-pretty/blob/master/lib/indent.xsl
# The only modification made was to declare UTF-8 to be the encoding, instead of ISO-8859-1.
HUMAN_XSLT = Nokogiri::XSLT(File.read(File.expand_path('../human.xslt', __FILE__)))

set_terminology do |t|
t.root :path => 'rightsMetadata', :index_as => [:not_searchable]
Expand Down Expand Up @@ -131,12 +135,8 @@ def normalize!
end

# Returns a nicely indented XML document.
# Note that the XSL file was taken from the (apparently defunct) nokogiri-pretty project:
# https://github.com/tobym/nokogiri-pretty/blob/master/lib/indent.xsl
# The only modification made was to declare UTF-8 to be the encoding, instead of ISO-8859-1.
def prettify(xml_doc)
template = Nokogiri::XSLT(File.read(File.expand_path('../human.xslt', __FILE__)))
template.apply_to(xml_doc)
HUMAN_XSLT.apply_to(xml_doc)
end

# maintain AF < 8 indexing behavior
Expand Down
7 changes: 4 additions & 3 deletions lib/dor/utils/ng_tidy.rb
Expand Up @@ -20,8 +20,7 @@ def normalize_text!

class Nokogiri::XML::Document

def prettify
xslt = Nokogiri::XSLT <<-EOC
PRETTIFY_XSLT = Nokogiri::XSLT <<-EOC
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
Expand All @@ -31,7 +30,9 @@ def prettify
</xsl:template>
</xsl:stylesheet>
EOC
xslt.transform(self).to_xml

def prettify
PRETTIFY_XSLT.transform(self).to_xml
end

end

0 comments on commit 4bd49b6

Please sign in to comment.