+/*
+ *
+ * XSLT STUFF
+ *
+ */
+function createXSLT(xsl) {
+ var p = new XSLTProcessor();
+ p.importStylesheet(xsl);
+ return p;
+}
+
+var xml2htmlStylesheet = null;
+
+// Wykonuje block z załadowanymi arkuszami stylów
+function withStylesheets(code_block, onError)
+{
+ if (!xml2htmlStylesheet) {
+ $.blockUI({message: 'Ładowanie arkuszy stylów...'});
+ $.ajax({
+ url: STATIC_URL + 'xsl/wl2html_client.xsl',
+ dataType: 'xml',
+ success: function(data) {
+ xml2htmlStylesheet = createXSLT(data);
+ $.unblockUI();
+ code_block();
+
+ },
+ error: onError
+ })
+ }
+ else {
+ code_block();
+ }
+}
+
+
+function xml2html(options) {
+ withStylesheets(function() {
+ var xml = options.xml.replace(/\/\s+/g, '<br />');
+ var parser = new DOMParser();
+ var serializer = new XMLSerializer();
+ var doc = parser.parseFromString(xml, 'text/xml');
+ var error = $('parsererror', doc);
+
+ if (error.length == 0) {
+ doc = xml2htmlStylesheet.transformToFragment(doc, document);
+ console.log(doc.firstChild);
+
+ if(doc.firstChild === null) {
+ options.error("Błąd w przetwarzaniu XML.");
+ return;
+ }
+
+ error = $('parsererror', doc);
+ }
+
+ if (error.length > 0 && options.error) {
+ options.error(error.text());
+ } else {
+ options.success(doc.firstChild);
+ }
+ }, function() { options.error && options.error('Nie udało się załadować XSLT'); });
+}
+
+/* USEFULL CONSTANTS */
+const ELEMENT_NODE = 1;
+const ATTRIBUTE_NODE = 2;
+const TEXT_NODE = 3;
+const CDATA_SECTION_NODE = 4;
+const ENTITY_REFERENCE_NODE = 5;
+const ENTITY_NODE = 6;
+const PROCESSING_INSTRUCTION_NODE = 7;
+const COMMENT_NODE = 8;
+const DOCUMENT_NODE = 9;
+const DOCUMENT_TYPE_NODE = 10;
+const DOCUMENT_FRAGMENT_NODE = 11;
+const NOTATION_NODE = 12;
+const XATTR_RE = /^x-attr-name-(.*)$/;
+
+const ELEM_START = 1;
+const ELEM_END = 2;
+const NS_END = 3;
+
+const NAMESPACES = {
+ // namespaces not listed here will be assigned random names
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#": "rdf",
+ "http://purl.org/dc/elements/1.1/": "dc",
+ "http://www.w3.org/XML/1998/namespace": "xml"
+};
+
+/*
+ * PADDING for pretty-printing
+ */
+const PADDING = {