[ACCEPTED]-XSLT output formatting: removing line breaks, and blank output lines from removed elements while keeping indent-xslt
Accepted answer
Adding these templates to your stylesheet:
<xsl:template match="*/text()[normalize-space()]">
<xsl:value-of select="normalize-space()"/>
</xsl:template>
<xsl:template match="*/text()[not(normalize-space())]" />
Produces 1 this output:
<?xml version="1.0" encoding="UTF-8"?>
<newdoc xmlns="http://www/w3.org/1999/xhtml">
<segment xmlns="" xmlns:foo="http://www.foo.org" title="Mr. Title">
<h2>Mr. Title</h2>
<p>This is one paragraph.</p>
<p>Another paragraph.</p>
<ol>
<li>An item paragraph.</li>
<li>Another item paragraph</li>
</ol>
</segment>
</newdoc>
At the very end of the stylesheet add these two templates:
<xsl:template match=
"text()[not(string-length(normalize-space()))]"/>
<xsl:template match=
"text()[string-length(normalize-space()) > 0]">
<xsl:value-of select="translate(.,'

', ' ')"/>
</xsl:template>
You now get the wanted result:
<?xml version="1.0" encoding="UTF-8"?>
<newdoc xmlns="http://www/w3.org/1999/xhtml">
<segment xmlns="" xmlns:foo="http://www.foo.org" title="Mr. Title">
<h2>Mr. Title</h2>
<p>This is one paragraph. </p>
<p>Another paragraph. </p>
<ol>
<li>An item paragraph.</li>
<li>Another item paragraph</li>
</ol>
</segment>
</newdoc>
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.