XML Pretty Printer Missing 2 Key Edge Cases
Using this xslt file found on this blog to pretty print xml using Nokogiri, everything almost works, but to the point where I c开发者_Go百科an't use it for HTML.
First, if a node is empty, it turns it into a self closing node, so:
<textarea></textarea>
gets converted to
<textarea/>
But that messes up the html tree when rendered.
Second, if the node just has text, the text isn't tabbed, and the closing node isn't tabbed, so:
<li>
<label>some text</label>
</li>
becomes:
<li>
<label>some text
</label>
</li>
...but it would ideally be:
<li>
<label>
some text
</label>
</li>
Does anyone who's pro at XSLT know a quick fix for this?
Modify the xsl:output
element to indicate you want HTML output and indenting:
<xsl:output method="html" indent="yes" encoding="ISO-8859-1"/>
If you are only trying to pretty-print output and not concerned with any further transformations offered by XSL then just use http://prettydiff.com/?m=beautify
You can also use a parameter for HTML http://prettydiff.com/?m=beautify&html that treats certain tags as singletons even though they look like opening tags, such as <br> instead of <br/>.
精彩评论