@@ -31,6 +31,36 @@ export function addGenre(doc) {
3131 return doc
3232}
3333
34+ /**
35+ * local/courseInfo/courseName -> mods/identifier[@type="course number"]
36+ * local/courseInfo/section -> mods/identifier[@type="section"]
37+ *
38+ * @param {Document } doc XML document
39+ *
40+ * @returns {Document } transformed document
41+ */
42+ function addIdentifiers ( doc ) {
43+ const courseCode = safeSelectFirst ( "//local/courseInfo/courseName" , doc )
44+ const sectionCode = safeSelectFirst ( "//local/courseInfo/section" , doc )
45+ const mods = safeSelectFirst ( "//mods" , doc )
46+
47+ if ( hasDirectTextContent ( courseCode ) ) {
48+ const identifier = createElement ( doc , 'identifier' )
49+ identifier . setAttribute ( 'type' , 'course number' )
50+ identifier . textContent = courseCode . textContent
51+ mods . appendChild ( identifier )
52+ }
53+
54+ if ( hasDirectTextContent ( sectionCode ) ) {
55+ const identifier = createElement ( doc , 'identifier' )
56+ identifier . setAttribute ( 'type' , 'section' )
57+ identifier . textContent = sectionCode . textContent
58+ mods . appendChild ( identifier )
59+ }
60+
61+ return doc
62+ }
63+
3464/**
3565 * semester -> mods/subject/temporal
3666 * local/department -> strip degree postfix -> mods/subject/topic
@@ -43,7 +73,7 @@ export function addSubjects(doc) {
4373 const department = safeSelectFirst ( "//local/department" , doc )
4474 const mods = safeSelectFirst ( "//mods" , doc )
4575
46- if ( semester ) {
76+ if ( hasDirectTextContent ( semester ) ) {
4777 const temporal = createElement ( doc , 'temporal' )
4878 temporal . textContent = semester . textContent
4979 let subjectParent = safeSelectFirst ( "//mods/subject" , doc )
@@ -54,7 +84,7 @@ export function addSubjects(doc) {
5484 subjectParent . appendChild ( temporal )
5585 }
5686
57- if ( department ) {
87+ if ( hasDirectTextContent ( department ) ) {
5888 // TODO we could have a better map of department names to subject terms with URIs
5989 // TODO terms like "Individualized" are not informative
6090 const topic = createElement ( doc , 'topic' )
@@ -160,11 +190,9 @@ export function convertSyllabusXMLtoMODS(xmlString) {
160190 // mods/part/number to part/text @type =attachment-uuid
161191 convertPartNumbers ( doc )
162192
163- // Add syllabi genre
164193 addGenre ( doc )
165-
166- // Add subjects
167194 addSubjects ( doc )
195+ addIdentifiers ( doc )
168196
169197 // Remove empty elements last, after all transformations are complete
170198 removeEmptyElements ( doc )
0 commit comments