vb@0: // xml2yml2.ysl2 version 2.4.4 vb@0: vb@0: include yslt.yml2 vb@0: vb@0: decl textstylesheet is estylesheet(*output="text") { vb@0: output *output; vb@0: const "space", !"'" + " " * 200 + "'"!; vb@0: param "autoindent", 4; vb@0: content; vb@0: }, tstylesheet is textstylesheet; vb@0: vb@0: define operator "†" as call "convert" with "tag", "name()"; vb@0: vb@0: tstylesheet { vb@0: function "printNS" vb@0: for "*/namespace::*[local-name()!='xml']" { vb@0: > xmlns vb@0: if "not(local-name()='')" vb@0: > :«local-name()» vb@0: > ="«.»" vb@0: if "position() , vb@0: } vb@0: vb@0: template "/" { vb@0: if "count(*/namespace::*)>1" { vb@0: | decl «name(*)»(`call "printNS"`); vb@0: | vb@0: } vb@0: apply "*", 0; vb@0: } vb@0: vb@0: template "text()" { vb@0: param "text", "normalize-space()"; vb@0: vb@0: if "string-length($text)>0" choose { vb@0: when "contains($text,'\\n')" choose { vb@0: when "string-length(substring-before($text,'\\n')) \n||\n«$text»||\n\n vb@0: otherwise > > «str:replace($text,'\\n','\\\\n')»\n vb@0: } vb@0: otherwise > | «$text»\n vb@0: } vb@0: otherwise > > `copy "."`\n vb@0: } vb@0: } vb@0: vb@0: template "*" { vb@0: 0> vb@0: call "convert" with "tag", "name()"; vb@0: apply "@*"; vb@0: vb@0: choose { vb@0: when "count(*)=0 and string-length(normalize-space())=0" vb@0: > ;\n vb@0: when "count(*)=1 and string-length(normalize-space())=0" { vb@0: > \n vb@0: apply "*"; vb@0: } vb@0: when "count(*)=0 and string-length(normalize-space())>0" { vb@0: > vb@0: apply "text()"; vb@0: } vb@0: otherwise { vb@0: > {\n vb@0: for "*|text()" { vb@0: if "local-name()=''" vb@0: if "string-length(normalize-space())>0" vb@0: 1> vb@0: apply "."; vb@0: } vb@0: | } vb@0: } vb@0: } vb@0: } vb@0: vb@0: template "@*" { vb@0: > «name()»="«.»" vb@0: if "position() , vb@0: } vb@0: vb@0: function "convert" { vb@0: param "tag"; vb@0: vb@0: > «translate($tag, '-', '_')» vb@0: } vb@0: }