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

Commit

Permalink
Use explicit namespaces for xpaths
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Nov 17, 2016
1 parent 2d7e982 commit 584de11
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/dor/models/describable.rb
Expand Up @@ -3,6 +3,8 @@ module Describable
extend ActiveSupport::Concern

MODS_TO_DC_XSLT = Nokogiri::XSLT(File.new(File.expand_path(File.dirname(__FILE__) + "/mods2dc.xslt")))
XMLNS_OAI_DC = 'http://www.openarchives.org/OAI/2.0/oai_dc/'.freeze
XMLNS_DC = 'http://purl.org/dc/elements/1.1/'.freeze

class CrosswalkError < Exception; end

Expand Down Expand Up @@ -45,7 +47,7 @@ def generate_dublin_core(include_collection_as_related_item: true)
desc_md = descMetadata.ng_xml.dup(1)
add_collection_reference(desc_md) if include_collection_as_related_item
dc_doc = MODS_TO_DC_XSLT.transform(desc_md)
dc_doc.xpath('/oai_dc:dc/*[count(text()) = 0]').remove # Remove empty nodes
dc_doc.xpath('/oai_dc:dc/*[count(text()) = 0]', oai_dc: XMLNS_OAI_DC).remove # Remove empty nodes
raise CrosswalkError, "Dor::Item#generate_dublin_core produced incorrect xml (no root):\n#{dc_doc.to_xml}" if dc_doc.root.nil?
raise CrosswalkError, "Dor::Item#generate_dublin_core produced incorrect xml (no children):\n#{dc_doc.to_xml}" if dc_doc.root.children.size == 0
dc_doc
Expand Down Expand Up @@ -226,15 +228,15 @@ def to_solr(solr_doc = {}, *args)
dc_doc = generate_dublin_core(include_collection_as_related_item: false)
# we excluding the generated collection relation here; we instead get the collection
# title from Dor::Identifiable.
dc_doc.xpath('/oai_dc:dc/*').each do |node|
dc_doc.xpath('/oai_dc:dc/*', oai_dc: XMLNS_OAI_DC).each do |node|
add_solr_value(solr_doc, "public_dc_#{node.name}", node.text, :string, [:stored_searchable])
end
creator = ''
dc_doc.xpath('//dc:creator').each do |node|
dc_doc.xpath('//dc:creator', dc: XMLNS_DC).each do |node|
creator = node.text
end
title = ''
dc_doc.xpath('//dc:title').each do |node|
dc_doc.xpath('//dc:title', dc: XMLNS_DC).each do |node|
title = node.text
end
creator_title = creator + title
Expand Down

0 comments on commit 584de11

Please sign in to comment.