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