1 {% extends "base.html" %}
\r
3 {% block extrahead %}
\r
4 <link rel="stylesheet" href="{{STATIC_URL}}css/html.css" type="text/css" charset="utf-8" />
\r
5 <script src="{{STATIC_URL}}js/lib/codemirror/codemirror.js" type="text/javascript" charset="utf-8"></script>
\r
8 {% block maincontent %}
\r
10 <!-- <button type="button" id="render">Render</button>
\r
12 <table width="100%" align="center">
\r
15 <textarea id="source" cols="70" rows="30" ></textarea>
\r
18 <textarea id="dest" cols="70" rows="30" ></textarea>
\r
25 <div id="target"> </div>
\r
28 {% block extrabody %}
\r
30 <script type="text/javascript">
\r
32 var editor = new CodeMirror(CodeMirror.replace("target"), {
\r
33 parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
\r
34 path: "{{STATIC_URL}}js/lib/codemirror",
\r
35 stylesheet: "{{STATIC_URL}}css/xmlcolors.css",
\r
36 content: "Hello world!"
\r
42 <script type="text/javascript">
\r
44 function serializeAttribute(attr, acc) {
\r
45 return acc + ' ' + attr.nodeName + '="'+ attr.nodeValue + '"';
\r
48 function serializeElement(element, acc, level)
\r
50 var isBlock = false;
\r
52 if(element.nodeName != 'span' && element.nodeName != 'p')
\r
56 for(var i=0; i < level; i++)
\r
60 acc += "<" + element.nodeName;
\r
62 for(var i=0; i < element.attributes.length; i++)
\r
63 acc = serializeAttribute(element.attributes.item(i), acc);
\r
65 if(element.firstChild)
\r
69 if(element.firstChild)
\r
70 acc = serializeNode(element.firstChild, acc, level+1);
\r
74 for(var i=0; i < level; i++)
\r
77 acc += "</"+element.nodeName + ">";
\r
83 if(isBlock) acc += "\n";
\r
89 // step-by-step serializer
\r
90 function serializeNode(node, acc, level)
\r
94 if(node.nodeType == 11)
\r
95 return serializeNode(node.firstChild, acc, level);
\r
97 if(node.nodeType == 1)
\r
98 acc = serializeElement(node, acc, level);
\r
100 else if(node.nodeType == 3)
\r
101 acc += node.nodeValue;
\r
103 if(node.nextSibling)
\r
104 return serializeNode(node.nextSibling, acc, level);
\r
109 function serializeXML(element) {
\r
110 return serializeNode(element, '', 0);
\r
113 // w3c version first
\r
114 var there = new XSLTProcessor();
\r
115 var here = new XSLTProcessor();
\r
118 url: "/static/xsl/wl2html_client.xsl",
\r
120 success: function(data) {
\r
121 there.importStylesheet(data);
\r
122 console.log('There XSL loaded successfully');
\r
128 url: "/static/xsl/html2wl_client.xsl",
\r
130 success: function(data) {
\r
131 here.importStylesheet(data);
\r
132 console.log('Here XSL loaded successfully');
\r
137 $('#render').click(function()
\r
139 src = $('#source').val();
\r
140 src = src.replace(/\/\s+/g, '<br />');
\r
141 var doc = (new DOMParser()).parseFromString(src, "text/xml");
\r
142 // console.log("Parsed", doc);
\r
143 var along = there.transformToDocument(doc).documentElement;
\r
144 // console.log("HTML", along, serializeXML(along) );
\r
145 var xfrm = here.transformToDocument(along).documentElement;
\r
146 // console.log("WLML", xfrm, serializeXML(xfrm) );
\r
147 var out = (new XMLSerializer()).serializeToString(xfrm);
\r
148 $('#dest').val(out);
\r