citeproc-js 0.0.1.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ var System = function () {};
2
+
3
+ System.prototype.retrieveLocale = function (lang) {
4
+ return this.locales[lang];
5
+ };
6
+
7
+ System.prototype.retrieveItem = function (id) {
8
+ return this.items[id];
9
+ };
10
+
11
+ System.prototype.getAbbreviations = function (context, variable) {
12
+ return (this.abbreviations[context] || {})[variable];
13
+ };
14
+
15
+ System.prototype.update = function (attributes) {
16
+ var name;
17
+ for (name in attributes) {
18
+ if (attributes.hasOwnProperty(name)) {
19
+ this[name] = attributes[name];
20
+ }
21
+ }
22
+ return this;
23
+ };
24
+
25
+ var system = new System(), citeproc = null;
26
+ system.update({ abbreviations: { 'default': {} }, locales: {}, items: {} });
@@ -0,0 +1,387 @@
1
+ /*
2
+ * Copyright (c) 2009, 2010 and 2011 Frank G. Bennett, Jr. All Rights
3
+ * Reserved.
4
+ *
5
+ * The contents of this file are subject to the Common Public
6
+ * Attribution License Version 1.0 (the “License”); you may not use
7
+ * this file except in compliance with the License. You may obtain a
8
+ * copy of the License at:
9
+ *
10
+ * http://bitbucket.org/fbennett/citeproc-js/src/tip/LICENSE.
11
+ *
12
+ * The License is based on the Mozilla Public License Version 1.1 but
13
+ * Sections 14 and 15 have been added to cover use of software over a
14
+ * computer network and provide for limited attribution for the
15
+ * Original Developer. In addition, Exhibit A has been modified to be
16
+ * consistent with Exhibit B.
17
+ *
18
+ * Software distributed under the License is distributed on an “AS IS”
19
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
+ * the License for the specific language governing rights and limitations
21
+ * under the License.
22
+ *
23
+ * The Original Code is the citation formatting software known as
24
+ * "citeproc-js" (an implementation of the Citation Style Language
25
+ * [CSL]), including the original test fixtures and software located
26
+ * under the ./std subdirectory of the distribution archive.
27
+ *
28
+ * The Original Developer is not the Initial Developer and is
29
+ * __________. If left blank, the Original Developer is the Initial
30
+ * Developer.
31
+ *
32
+ * The Initial Developer of the Original Code is Frank G. Bennett,
33
+ * Jr. All portions of the code written by Frank G. Bennett, Jr. are
34
+ * Copyright (c) 2009 and 2010 Frank G. Bennett, Jr. All Rights Reserved.
35
+ *
36
+ * Alternatively, the contents of this file may be used under the
37
+ * terms of the GNU Affero General Public License (the [AGPLv3]
38
+ * License), in which case the provisions of [AGPLv3] License are
39
+ * applicable instead of those above. If you wish to allow use of your
40
+ * version of this file only under the terms of the [AGPLv3] License
41
+ * and not to allow others to use your version of this file under the
42
+ * CPAL, indicate your decision by deleting the provisions above and
43
+ * replace them with the notice and other provisions required by the
44
+ * [AGPLv3] License. If you do not delete the provisions above, a
45
+ * recipient may use your version of this file under either the CPAL
46
+ * or the [AGPLv3] License.”
47
+ */
48
+ var ActiveXObject;
49
+ var XMLHttpRequest;
50
+ var DOMParser;
51
+ var CSL_IS_IE;
52
+ var CSL_CHROME = function () {
53
+ if ("undefined" == typeof DOMParser || CSL_IS_IE) {
54
+ CSL_IS_IE = true;
55
+ DOMParser = function() {};
56
+ DOMParser.prototype.parseFromString = function(str, contentType) {
57
+ if ("undefined" != typeof ActiveXObject) {
58
+ var xmldata = new ActiveXObject('MSXML.DomDocument');
59
+ xmldata.async = false;
60
+ xmldata.loadXML(str);
61
+ return xmldata;
62
+ } else if ("undefined" != typeof XMLHttpRequest) {
63
+ var xmldata = new XMLHttpRequest;
64
+ if (!contentType) {
65
+ contentType = 'text/xml';
66
+ }
67
+ xmldata.open('GET', 'data:' + contentType + ';charset=utf-8,' + encodeURIComponent(str), false);
68
+ if(xmldata.overrideMimeType) {
69
+ xmldata.overrideMimeType(contentType);
70
+ }
71
+ xmldata.send(null);
72
+ return xmldata.responseXML;
73
+ }
74
+ };
75
+ this.hasAttributes = function (node) {
76
+ var ret;
77
+ if (node.attributes && node.attributes.length) {
78
+ ret = true;
79
+ } else {
80
+ ret = false;
81
+ }
82
+ return ret;
83
+ };
84
+ } else {
85
+ this.hasAttributes = function (node) {
86
+ return node["hasAttributes"]();
87
+ };
88
+ }
89
+ this.importNode = function (doc, srcElement) {
90
+ if ("undefined" == typeof doc.importNode) {
91
+ var ret = this._importNode(doc, srcElement, true);
92
+ } else {
93
+ var ret = doc.importNode(srcElement, true);
94
+ }
95
+ return ret;
96
+ };
97
+ this._importNode = function(doc, node, allChildren) {
98
+ switch (node.nodeType) {
99
+ case 1:
100
+ var newNode = doc.createElement(node.nodeName);
101
+ if (node.attributes && node.attributes.length > 0)
102
+ for (var i = 0, il = node.attributes.length; i < il;)
103
+ newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName));
104
+ if (allChildren && node.childNodes && node.childNodes.length > 0)
105
+ for (var i = 0, il = node.childNodes.length; i < il;)
106
+ newNode.appendChild(this._importNode(doc, node.childNodes[i++], allChildren));
107
+ return newNode;
108
+ break;
109
+ case 3:
110
+ case 4:
111
+ case 8:
112
+ }
113
+ };
114
+ this.parser = new DOMParser();
115
+ var str = "<docco><institution institution-parts=\"long\" delimiter=\", \" substitute-use-first=\"1\" use-last=\"1\"><institution-part name=\"long\"></institution></docco>";
116
+ var inst_doc = this.parser.parseFromString(str, "text/xml");
117
+ var inst_node = inst_doc.getElementsByTagName("institution");
118
+ this.institution = inst_node.item(0);
119
+ var inst_part_node = inst_doc.getElementsByTagName("institution-part");
120
+ this.institutionpart = inst_part_node.item(0);
121
+ this.ns = "http://purl.org/net/xbiblio/csl";
122
+ };
123
+ CSL_CHROME.prototype.clean = function (xml) {
124
+ xml = xml.replace(/<\?[^?]+\?>/g, "");
125
+ xml = xml.replace(/<![^>]+>/g, "");
126
+ xml = xml.replace(/^\s+/, "");
127
+ xml = xml.replace(/\s+$/, "");
128
+ xml = xml.replace(/^\n*/, "");
129
+ return xml;
130
+ };
131
+ CSL_CHROME.prototype.getStyleId = function (myxml) {
132
+ var text = "";
133
+ var node = myxml.getElementsByTagName("id");
134
+ if (node && node.length) {
135
+ node = node.item(0);
136
+ }
137
+ if (node) {
138
+ text = node.textContent;
139
+ }
140
+ if (!text) {
141
+ text = node.innerText;
142
+ }
143
+ if (!text) {
144
+ text = node.innerHTML;
145
+ }
146
+ return text;
147
+ };
148
+ CSL_CHROME.prototype.children = function (myxml) {
149
+ var children, pos, len, ret;
150
+ if (myxml) {
151
+ ret = [];
152
+ children = myxml.childNodes;
153
+ for (pos = 0, len = children.length; pos < len; pos += 1) {
154
+ if (children[pos].nodeName != "#text") {
155
+ ret.push(children[pos]);
156
+ }
157
+ }
158
+ return ret;
159
+ } else {
160
+ return [];
161
+ }
162
+ };
163
+ CSL_CHROME.prototype.nodename = function (myxml) {
164
+ var ret = myxml.nodeName;
165
+ return ret;
166
+ };
167
+ CSL_CHROME.prototype.attributes = function (myxml) {
168
+ var ret, attrs, attr, key, xml, pos, len;
169
+ ret = new Object();
170
+ if (myxml && this.hasAttributes(myxml)) {
171
+ attrs = myxml.attributes;
172
+ for (pos = 0, len=attrs.length; pos < len; pos += 1) {
173
+ attr = attrs[pos];
174
+ ret["@" + attr.name] = attr.value;
175
+ }
176
+ }
177
+ return ret;
178
+ };
179
+ CSL_CHROME.prototype.content = function (myxml) {
180
+ var ret;
181
+ if ("undefined" != typeof myxml.textContent) {
182
+ ret = myxml.textContent;
183
+ } else if ("undefined" != typeof myxml.innerText) {
184
+ ret = myxml.innerText;
185
+ } else {
186
+ ret = myxml.txt;
187
+ }
188
+ return ret;
189
+ };
190
+ CSL_CHROME.prototype.namespace = {
191
+ "xml":"http://www.w3.org/XML/1998/namespace"
192
+ }
193
+ CSL_CHROME.prototype.numberofnodes = function (myxml) {
194
+ if (myxml) {
195
+ return myxml.length;
196
+ } else {
197
+ return 0;
198
+ }
199
+ };
200
+ CSL_CHROME.prototype.getAttributeName = function (attr) {
201
+ var ret = attr.name;
202
+ return ret;
203
+ }
204
+ CSL_CHROME.prototype.getAttributeValue = function (myxml,name,namespace) {
205
+ var ret = "";
206
+ if (myxml && this.hasAttributes(myxml) && myxml.getAttribute(name)) {
207
+ ret = myxml.getAttribute(name);
208
+ }
209
+ return ret;
210
+ }
211
+ CSL_CHROME.prototype.getNodeValue = function (myxml,name) {
212
+ var ret = "";
213
+ if (name){
214
+ var vals = myxml.getElementsByTagName(name);
215
+ if (vals.length > 0) {
216
+ if ("undefined" != typeof vals[0].textContent) {
217
+ ret = vals[0].textContent;
218
+ } else if ("undefined" != typeof vals[0].innerText) {
219
+ ret = vals[0].innerText;
220
+ } else {
221
+ ret = vals[0].text;
222
+ }
223
+ }
224
+ } else {
225
+ ret = myxml;
226
+ }
227
+ if (ret && ret.childNodes && (ret.childNodes.length == 0 || (ret.childNodes.length == 1 && ret.firstChild.nodeName == "#text"))) {
228
+ if ("undefined" != typeof ret.textContent) {
229
+ ret = ret.textContent;
230
+ } else if ("undefined" != typeof ret.innerText) {
231
+ ret = ret.innerText;
232
+ } else {
233
+ ret = ret.text;
234
+ }
235
+ }
236
+ return ret;
237
+ }
238
+ CSL_CHROME.prototype.setAttributeOnNodeIdentifiedByNameAttribute = function (myxml,nodename,partname,attrname,val) {
239
+ var pos, len, xml, nodes, node;
240
+ if (attrname.slice(0,1) === '@'){
241
+ attrname = attrname.slice(1);
242
+ }
243
+ nodes = myxml.getElementsByTagName(nodename);
244
+ for (pos = 0, len = nodes.length; pos < len; pos += 1) {
245
+ node = nodes[pos];
246
+ if (node.getAttribute("name") != partname) {
247
+ continue;
248
+ }
249
+ node.setAttribute(attrname, val);
250
+ }
251
+ }
252
+ CSL_CHROME.prototype.deleteNodeByNameAttribute = function (myxml,val) {
253
+ var pos, len, node, nodes;
254
+ nodes = myxml.childNodes;
255
+ for (pos = 0, len = nodes.length; pos < len; pos += 1) {
256
+ node = nodes[pos];
257
+ if (!node || node.nodeType == node.TEXT_NODE) {
258
+ continue;
259
+ }
260
+ if (this.hasAttributes(node) && node.getAttribute("name") == val) {
261
+ myxml.removeChild(nodes[pos]);
262
+ }
263
+ }
264
+ }
265
+ CSL_CHROME.prototype.deleteAttribute = function (myxml,attr) {
266
+ myxml.removeAttribute(attr);
267
+ }
268
+ CSL_CHROME.prototype.setAttribute = function (myxml,attr,val) {
269
+ var attribute;
270
+ if (!myxml.ownerDocument) {
271
+ myxml = myxml.firstChild;
272
+ }
273
+ attribute = myxml.ownerDocument.createAttribute(attr);
274
+ myxml.setAttribute(attr, val);
275
+ return false;
276
+ }
277
+ CSL_CHROME.prototype.nodeCopy = function (myxml) {
278
+ var cloned_node = myxml.cloneNode(true);
279
+ return cloned_node;
280
+ }
281
+ CSL_CHROME.prototype.getNodesByName = function (myxml,name,nameattrval) {
282
+ var ret, nodes, node, pos, len;
283
+ ret = [];
284
+ nodes = myxml.getElementsByTagName(name);
285
+ for (pos = 0, len = nodes.length; pos < len; pos += 1) {
286
+ node = nodes.item(pos);
287
+ if (nameattrval && !(this.hasAttributes(node) && node.getAttribute("name") == nameattrval)) {
288
+ continue;
289
+ }
290
+ ret.push(node);
291
+ }
292
+ return ret;
293
+ }
294
+ CSL_CHROME.prototype.nodeNameIs = function (myxml,name) {
295
+ if (name == myxml.nodeName) {
296
+ return true;
297
+ }
298
+ return false;
299
+ }
300
+ CSL_CHROME.prototype.makeXml = function (myxml) {
301
+ var ret, topnode;
302
+ if (!myxml) {
303
+ myxml = "<docco><bogus/></docco>";
304
+ }
305
+ myxml = myxml.replace(/\s*<\?[^>]*\?>\s*\n*/g, "");
306
+ var nodetree = this.parser.parseFromString(myxml, "application/xml");
307
+ return nodetree.firstChild;
308
+ };
309
+ CSL_CHROME.prototype.insertChildNodeAfter = function (parent,node,pos,datexml) {
310
+ var myxml, xml;
311
+ myxml = this.importNode(node.ownerDocument, datexml);
312
+ parent.replaceChild(myxml, node);
313
+ return parent;
314
+ };
315
+ CSL_CHROME.prototype.insertPublisherAndPlace = function(myxml) {
316
+ var group = myxml.getElementsByTagName("group");
317
+ for (var i = 0, ilen = group.length; i < ilen; i += 1) {
318
+ var node = group.item(i);
319
+ if (node.childNodes.length === 2) {
320
+ var twovars = [];
321
+ for (var j = 0, jlen = 2; j < jlen; j += 1) {
322
+ var child = node.childNodes.item(j);
323
+ if (child.childNodes.length === 0) {
324
+ twovars.push(child.getAttribute('variable'));
325
+ if (child.getAttribute('suffix')
326
+ || child.getAttribute('prefix')) {
327
+ twovars = [];
328
+ break;
329
+ }
330
+ }
331
+ }
332
+ if (twovars.indexOf("publisher") > -1 && twovars.indexOf("publisher-place") > -1) {
333
+ node.setAttribute('has-publisher-and-publisher-place', true);
334
+ }
335
+ }
336
+ }
337
+ };
338
+ CSL_CHROME.prototype.addMissingNameNodes = function(myxml) {
339
+ var nameslist = myxml.getElementsByTagName("names");
340
+ for (var i = 0, ilen = nameslist.length; i < ilen; i += 1) {
341
+ var names = nameslist.item(i);
342
+ var namelist = names.getElementsByTagName("name");
343
+ if ((!namelist || namelist.length === 0)
344
+ || names.parentNode.tagName.toLowerCase() !== "substitute") {
345
+ var doc = names.ownerDocument;
346
+ var name = doc.createElement("name");
347
+ names.appendChild(name);
348
+ }
349
+ }
350
+ };
351
+ CSL_CHROME.prototype.addInstitutionNodes = function(myxml) {
352
+ var names, thenames, institution, theinstitution, name, thename, xml, pos, len;
353
+ names = myxml.getElementsByTagName("names");
354
+ for (pos = 0, len = names.length; pos < len; pos += 1) {
355
+ thenames = names.item(pos);
356
+ name = thenames.getElementsByTagName("name");
357
+ if (name.length == 0) {
358
+ continue;
359
+ }
360
+ institution = thenames.getElementsByTagName("institution");
361
+ if (institution.length == 0) {
362
+ theinstitution = this.importNode(myxml.ownerDocument, this.institution);
363
+ theinstitutionpart = theinstitution.getElementsByTagName("institution-part").item(0);
364
+ thename = name.item(0);
365
+ thenames.insertBefore(theinstitution, thename.nextSibling);
366
+ for (var j = 0, jlen = CSL.INSTITUTION_KEYS.length; j < jlen; j += 1) {
367
+ var attrname = CSL.INSTITUTION_KEYS[j];
368
+ var attrval = thename.getAttribute(attrname);
369
+ if (attrval) {
370
+ theinstitutionpart.setAttribute(attrname, attrval);
371
+ }
372
+ }
373
+ var nameparts = thename.getElementsByTagName("name-part");
374
+ for (var j = 0, jlen = nameparts.length; j < jlen; j += 1) {
375
+ if ('family' === nameparts[j].getAttribute('name')) {
376
+ for (var k = 0, klen = CSL.INSTITUTION_KEYS.length; k < klen; k += 1) {
377
+ var attrname = CSL.INSTITUTION_KEYS[k];
378
+ var attrval = nameparts[j].getAttribute(attrname);
379
+ if (attrval) {
380
+ theinstitutionpart.setAttribute(attrname, attrval);
381
+ }
382
+ }
383
+ }
384
+ }
385
+ }
386
+ }
387
+ };
@@ -0,0 +1,253 @@
1
+ /*
2
+ * Copyright (c) 2009, 2010 and 2011 Frank G. Bennett, Jr. All Rights
3
+ * Reserved.
4
+ *
5
+ * The contents of this file are subject to the Common Public
6
+ * Attribution License Version 1.0 (the “License”); you may not use
7
+ * this file except in compliance with the License. You may obtain a
8
+ * copy of the License at:
9
+ *
10
+ * http://bitbucket.org/fbennett/citeproc-js/src/tip/LICENSE.
11
+ *
12
+ * The License is based on the Mozilla Public License Version 1.1 but
13
+ * Sections 14 and 15 have been added to cover use of software over a
14
+ * computer network and provide for limited attribution for the
15
+ * Original Developer. In addition, Exhibit A has been modified to be
16
+ * consistent with Exhibit B.
17
+ *
18
+ * Software distributed under the License is distributed on an “AS IS”
19
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
+ * the License for the specific language governing rights and limitations
21
+ * under the License.
22
+ *
23
+ * The Original Code is the citation formatting software known as
24
+ * "citeproc-js" (an implementation of the Citation Style Language
25
+ * [CSL]), including the original test fixtures and software located
26
+ * under the ./std subdirectory of the distribution archive.
27
+ *
28
+ * The Original Developer is not the Initial Developer and is
29
+ * __________. If left blank, the Original Developer is the Initial
30
+ * Developer.
31
+ *
32
+ * The Initial Developer of the Original Code is Frank G. Bennett,
33
+ * Jr. All portions of the code written by Frank G. Bennett, Jr. are
34
+ * Copyright (c) 2009 and 2010 Frank G. Bennett, Jr. All Rights Reserved.
35
+ *
36
+ * Alternatively, the contents of this file may be used under the
37
+ * terms of the GNU Affero General Public License (the [AGPLv3]
38
+ * License), in which case the provisions of [AGPLv3] License are
39
+ * applicable instead of those above. If you wish to allow use of your
40
+ * version of this file only under the terms of the [AGPLv3] License
41
+ * and not to allow others to use your version of this file under the
42
+ * CPAL, indicate your decision by deleting the provisions above and
43
+ * replace them with the notice and other provisions required by the
44
+ * [AGPLv3] License. If you do not delete the provisions above, a
45
+ * recipient may use your version of this file under either the CPAL
46
+ * or the [AGPLv3] License.”
47
+ */
48
+ var CSL_E4X = function () {};
49
+ CSL_E4X.prototype.clean = function (xml) {
50
+ xml = xml.replace(/<\?[^?]+\?>/g, "");
51
+ xml = xml.replace(/<![^>]+>/g, "");
52
+ xml = xml.replace(/^\s+/g, "");
53
+ xml = xml.replace(/\s+$/g, "");
54
+ return xml;
55
+ };
56
+ CSL_E4X.prototype.getStyleId = function (myxml) {
57
+ var text = "";
58
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
59
+ var node = myxml..id;
60
+ if (node && node.length()) {
61
+ text = node[0].toString();
62
+ }
63
+ return text;
64
+ };
65
+ CSL_E4X.prototype.children = function (myxml) {
66
+ return myxml.children();
67
+ };
68
+ CSL_E4X.prototype.nodename = function (myxml) {
69
+ var ret = myxml.localName();
70
+ return ret;
71
+ };
72
+ CSL_E4X.prototype.attributes = function (myxml) {
73
+ var ret, attrs, attr, key, xml;
74
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
75
+ ret = new Object();
76
+ attrs = myxml.attributes();
77
+ for each (attr in attrs) {
78
+ key = "@" + attr.localName();
79
+ if (key.slice(0,5) == "@e4x_") {
80
+ continue;
81
+ }
82
+ ret[key] = attr.toString();
83
+ }
84
+ return ret;
85
+ };
86
+ CSL_E4X.prototype.content = function (myxml) {
87
+ return myxml.toString();
88
+ };
89
+ CSL_E4X.prototype.namespace = {
90
+ "xml":"http://www.w3.org/XML/1998/namespace"
91
+ }
92
+ CSL_E4X.prototype.numberofnodes = function (myxml) {
93
+ return myxml.length();
94
+ };
95
+ CSL_E4X.prototype.getAttributeName = function (attr) {
96
+ var ret = attr.localName();
97
+ return ret;
98
+ }
99
+ CSL_E4X.prototype.getAttributeValue = function (myxml,name,namespace) {
100
+ var xml;
101
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
102
+ if (namespace) {
103
+ var ns = new Namespace(this.namespace[namespace]);
104
+ var ret = myxml.@ns::[name].toString();
105
+ } else {
106
+ if (name) {
107
+ var ret = myxml.attribute(name).toString();
108
+ } else {
109
+ var ret = myxml.toString();
110
+ }
111
+ }
112
+ return ret;
113
+ }
114
+ CSL_E4X.prototype.getNodeValue = function (myxml,name) {
115
+ var xml;
116
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
117
+ if (name){
118
+ return myxml[name].toString();
119
+ } else {
120
+ return myxml.toString();
121
+ }
122
+ }
123
+ CSL_E4X.prototype.setAttributeOnNodeIdentifiedByNameAttribute = function (myxml,nodename,attrname,attr,val) {
124
+ var xml;
125
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
126
+ if (attr[0] != '@'){
127
+ attr = '@'+attr;
128
+ }
129
+ myxml[nodename].(@name == attrname)[0][attr] = val;
130
+ }
131
+ CSL_E4X.prototype.deleteNodeByNameAttribute = function (myxml,val) {
132
+ delete myxml.*.(@name==val)[0];
133
+ }
134
+ CSL_E4X.prototype.deleteAttribute = function (myxml,attr) {
135
+ delete myxml["@"+attr];
136
+ }
137
+ CSL_E4X.prototype.setAttribute = function (myxml,attr,val) {
138
+ myxml['@'+attr] = val;
139
+ }
140
+ CSL_E4X.prototype.nodeCopy = function (myxml) {
141
+ return myxml.copy();
142
+ }
143
+ CSL_E4X.prototype.getNodesByName = function (myxml,name,nameattrval) {
144
+ var xml, ret;
145
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
146
+ ret = myxml.descendants(name);
147
+ if (nameattrval){
148
+ ret = ret.(@name == nameattrval);
149
+ }
150
+ return ret;
151
+ }
152
+ CSL_E4X.prototype.nodeNameIs = function (myxml,name) {
153
+ var xml;
154
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
155
+ if (myxml.localName() && myxml.localName().toString() == name){
156
+ return true;
157
+ }
158
+ return false;
159
+ }
160
+ CSL_E4X.prototype.makeXml = function (myxml) {
161
+ var xml;
162
+ XML.ignoreComments = true;
163
+ XML.ignoreProcessingInstructions = true;
164
+ XML.ignoreWhitespace = true;
165
+ XML.prettyPrinting = true;
166
+ XML.prettyIndent = 2;
167
+ if ("xml" == typeof myxml){
168
+ myxml = myxml.toXMLString();
169
+ };
170
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
171
+ xml = new Namespace("http://www.w3.org/XML/1998/namespace");
172
+ if (myxml){
173
+ myxml = myxml.replace(/\s*<\?[^>]*\?>\s*\n*/g, "");
174
+ myxml = new XML(myxml);
175
+ } else {
176
+ myxml = new XML();
177
+ }
178
+ return myxml;
179
+ };
180
+ CSL_E4X.prototype.insertChildNodeAfter = function (parent,node,pos,datexml) {
181
+ var myxml, xml;
182
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
183
+ myxml = XML(datexml.toXMLString());
184
+ parent.insertChildAfter(node,myxml);
185
+ delete parent.*[pos];
186
+ return parent;
187
+ };
188
+ CSL_E4X.prototype.insertPublisherAndPlace = function(myxml) {
189
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
190
+ for each (var node in myxml..group) {
191
+ if (node.children().length() === 2) {
192
+ var twovars = [];
193
+ for each (var child in node.children()) {
194
+ if (child.children().length() === 0
195
+ ) {
196
+ twovars.push(child.@variable.toString());
197
+ if (child.@suffix.toString()
198
+ || child.@prefix.toString()) {
199
+ twovars = [];
200
+ break;
201
+ }
202
+ }
203
+ }
204
+ if (twovars.indexOf("publisher") > -1 && twovars.indexOf("publisher-place") > -1) {
205
+ node["@has-publisher-and-publisher-place"] = "true";
206
+ }
207
+ }
208
+ }
209
+ };
210
+ CSL_E4X.prototype.addMissingNameNodes = function(myxml) {
211
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
212
+ for each (node in myxml..names) {
213
+ if ("xml" == typeof node && node.parent().localName() !== "substitute" && node.elements("name").length() === 0) {
214
+ var name = <name/>;
215
+ node.appendChild(name);
216
+ }
217
+ }
218
+ };
219
+ CSL_E4X.prototype.addInstitutionNodes = function(myxml) {
220
+ var institution_long, institution_short, name_part, children, node, xml;
221
+ default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
222
+ for each (node in myxml..names) {
223
+ if ("xml" == typeof node && node.elements("name").length() > 0) {
224
+ if (!node.institution.toXMLString()) {
225
+ institution_long = <institution
226
+ institution-parts="long"
227
+ substitute-use-first="1"
228
+ use-last="1"/>
229
+ institution_part = <institution-part name="long"/>;
230
+ node.name += institution_long;
231
+ node.institution.@delimiter = node.name.@delimiter.toString();
232
+ if (node.name.@and.toXMLString()) {
233
+ node.institution.@and = "text";
234
+ }
235
+ node.institution[0].appendChild(institution_part);
236
+ for each (var attr in CSL.INSTITUTION_KEYS) {
237
+ if (node.name.@[attr].toString()) {
238
+ node.institution['institution-part'][0].@[attr] = node.name.@[attr].toString();
239
+ }
240
+ }
241
+ for each (var namepartnode in node.name['name-part']) {
242
+ if (namepartnode.@name.toString() === 'family') {
243
+ for each (var attr in CSL.INSTITUTION_KEYS) {
244
+ if (namepartnode.@[attr].toString()) {
245
+ node.institution['institution-part'][0].@[attr] = namepartnode.@[attr].toString();
246
+ }
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+ }
253
+ };