[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XML pretty printer
This works for your example, but will most certainly need more sophistication. For example, it ignores text nodes entirely, doesn't take care of proper entity escaping in attributes, is ignorant of namespaces etc. <?xml version="1.0" encoding="UTF-8"?> <stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"> <output method="text"/> <template match="/"> <apply-templates/> </template> <template match="*"> <param name="indent" select="''"/> <value-of select="concat($indent,'<',local-name(),' ')"/> <apply-templates select="@*"> <with-param name="indent" select="concat($indent,' ')"/> </apply-templates> <apply-templates select="." mode="writeChildElementsAndClose"> <with-param name="indent" select="$indent"/> </apply-templates> </template> <template match="*[*]" mode="writeChildElementsAndClose"> <param name="indent"/> <value-of select="concat($indent,'>',' ')"/> <apply-templates select="*"> <with-param name="indent" select="concat($indent,' ')"/> </apply-templates> <value-of select="concat($indent,'</',local-name(),'> ')"/> </template> <template match="*" mode="writeChildElementsAndClose"> <param name="indent"/> <value-of select="concat($indent,'/>',' ')"/> </template> <template match="@*"> <param name="indent"/> <variable name="quot"> <text>"</text> </variable> <value-of select="concat($indent,local-name(),'=',$quot,string(),$quot,' ')"/> </template> </stylesheet> 2011/9/26 John Christopher <john.christopher1100@xxxxxxxxx>: > I am looking for a stylesheet (or free software > that runs from the command line on linux) that > will take the following input: > > <mydata attrib1="hello" attrib2="world" > attrib3="yes" >> > <person name="Fred" country="US" /> > <person name="Karen" country="DE" /> > </mydata> > > > and pretty prints it like this (each attribute > printed on a separate line beneath the element > and indented): > > > <mydata > attrib1="hello" > attrib2="world" > attrib3="yes" >> > <person > name="Fred" > country="US" > /> > <person > name="Sylvia" > country="DE" > /> > </mydata> > > Any ideas? Thanks for your help.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|