+
+ asWLML: function(element)
+ {
+ console.log("Source", element);
+ var doc = this.parser.parseFromString(this.serializer.serializeToString(element), 'text/xml');
+
+ var result = this.wlmlXSL.transformToDocument(doc);
+
+ if(!result) {
+ console.log("Failed", this.wlmlXSL, doc);
+ throw "Failed to transform fragment";
+ }
+
+ console.log("Transformed", doc, " to: ", result.documentElement);
+ return this.serializer.serializeToString(result.documentElement);
+ },
+
+ updateWithWLML: function($element, text)
+ {
+ // filter the string
+ text = text.replace(/\/\s+/g, '<br />');
+ var chunk = this.parser.parseFromString("<chunk>"+text+"</chunk>", "text/xml");
+
+ var errors = $('parsererror', chunk);
+
+ // check if chunk is parsable
+ if(errors.length > 0)
+ throw {text: errors.text(), html: errors.html()};
+
+ var result = this.htmlXSL.transformToFragment(chunk, document);
+
+ console.log("RESULT", this.serializer.serializeToString(result));
+
+ if(!result)
+ throw "WLML->HTML transformation failed.";
+
+ $element.replaceWith(result);
+ this.set('state', 'dirty');
+ },
+
+ createXSLT: function(xslt_doc) {
+ var p = new XSLTProcessor();
+ p.importStylesheet(xslt_doc);
+ return p;
+ },
+
+ htmlXSLLoadSuccess: function(data)
+ {
+ try {
+ this.htmlXSL = this.createXSLT(data);
+
+ if(this.wlmlXSL && this.htmlXSL && this.rawText)
+ this.loadSuccess();
+ } catch(e) {
+ this.loadingFailed();
+ }
+ },
+
+ wlmlXSLLoadSuccess: function(data)
+ {
+ try {
+ this.wlmlXSL = this.createXSLT(data);
+
+ if(this.wlmlXSL && this.htmlXSL && this.rawText)
+ this.loadSuccess();
+ } catch(e) {
+ this.loadingFailed();
+ }
+ },
+
+ textLoadSuccess: function(data) {
+ this.rawText = data;
+
+ if(this.wlmlXSL && this.htmlXSL && this.rawText)
+ this.loadSuccess();
+ },
+
+ loadSuccess: function() {