Skip to content

Commit

Permalink
Merge pull request #152 from sul-dlss/remove-modsxml-constant
Browse files Browse the repository at this point in the history
remove the constant that loads an .xsl from loc so that the app can c…
  • Loading branch information
ndushay committed Oct 8, 2018
2 parents f8c42a2 + 0bce1b3 commit 5cc68ce
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
8 changes: 5 additions & 3 deletions app/models/marcxml_resource.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# MARC resource model for retrieving and transforming MARC records
class MarcxmlResource
MARC_TO_MODS_XSLT = Nokogiri::XSLT(File.read(File.join(Rails.root, 'app', 'xslt', 'MARC21slim2MODS3-6_SDR_v1.xsl')))

def self.find_by(catkey: nil, barcode: nil)
if catkey
new(catkey: catkey)
Expand All @@ -23,7 +21,7 @@ def initialize(catkey:)
end

def mods
MARC_TO_MODS_XSLT.transform(Nokogiri::XML(marcxml)).to_xml
marc_to_mods_xslt.transform(Nokogiri::XML(marcxml)).to_xml
end

def marcxml
Expand All @@ -32,6 +30,10 @@ def marcxml

private

def marc_to_mods_xslt
@marc_to_mods_xslt ||= Nokogiri::XSLT(File.open(File.join(Rails.root, 'app', 'xslt', 'MARC21slim2MODS3-6_SDR_v1.xsl')))
end

def marc_record
SymphonyReader.new(catkey: catkey).to_marc
end
Expand Down
2 changes: 1 addition & 1 deletion app/xslt/MARC21slim2MODS3-6_SDR_v1.xsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<xsl:stylesheet xmlns="http://www.loc.gov/mods/v3" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xlink marc" version="1.0">
<xsl:include href="http://www.loc.gov/standards/marcxml/xslt/MARC21slimUtils.xsl"/>
<xsl:include href="MARC21slimUtils.xsl"/>
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>

Expand Down
65 changes: 65 additions & 0 deletions app/xslt/MARC21slimUtils.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="datafield">
<xsl:param name="tag"/>
<xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
<xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
<xsl:param name="subfields"/>
<xsl:element name="datafield">
<xsl:attribute name="tag">
<xsl:value-of select="$tag"/>
</xsl:attribute>
<xsl:attribute name="ind1">
<xsl:value-of select="$ind1"/>
</xsl:attribute>
<xsl:attribute name="ind2">
<xsl:value-of select="$ind2"/>
</xsl:attribute>
<xsl:copy-of select="$subfields"/>
</xsl:element>
</xsl:template>

<xsl:template name="subfieldSelect">
<xsl:param name="codes"/>
<xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
<xsl:variable name="str">
<xsl:for-each select="marc:subfield">
<xsl:if test="contains($codes, @code)">
<xsl:value-of select="text()"/><xsl:value-of select="$delimeter"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
</xsl:template>

<xsl:template name="buildSpaces">
<xsl:param name="spaces"/>
<xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
<xsl:if test="$spaces>0">
<xsl:value-of select="$char"/>
<xsl:call-template name="buildSpaces">
<xsl:with-param name="spaces" select="$spaces - 1"/>
<xsl:with-param name="char" select="$char"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template name="chopPunctuation">
<xsl:param name="chopString"/>
<xsl:variable name="length" select="string-length($chopString)"/>
<xsl:choose>
<xsl:when test="$length=0"/>
<xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
<xsl:call-template name="chopPunctuation">
<xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="not($chopString)"/>
<xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
<metaInformation>
<scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
</metaInformation>
-->
1 change: 0 additions & 1 deletion spec/controllers/marcxml_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
describe 'GET mods' do
it 'transforms the MARCXML into MODS' do
stub_request(:get, Settings.CATALOG.SYMPHONY.JSON_URL % { catkey: resource.catkey }).to_return(body: '{}')

get :mods, params: { catkey: '12345' }
expect(response.body).to match(/mods/)
end
Expand Down

0 comments on commit 5cc68ce

Please sign in to comment.