Re: Minify an xml into one line
Klaus Johannes Rusch <[email protected]> Sat, 27 Aug 2011 12:24:28 +0200
| Newsgroups | gmane.comp.web.html-tidy.devel |
|---|---|
| Organization | atmedia.net |
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============3920518086667481884==
Content-Type: multipart/alternative;
boundary="------------090709010604080507020707"
This is a multi-part message in MIME format.
--------------090709010604080507020707
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
On 27.08.2011 12:14, J=E9r=F4me DESPATIS wrote:
> Hello,
>
> Thanks for your quick answer!
> Ok so tidy doesn't support that natively
>
> You're talking about the TidyNewline, but can I change this value in a=20
> config file somewhere ?
> Because I only see it in=20
> http://tidy.sourceforge.net/docs/api/tidyenum_8h-source.html, and I=20
> would need to recompile tidy in order to change this value I'm afraid,=20
> no ?
>
> If it's impossible without recompiling tidy, yes the only solution is=20
> to use a minifier as post process, I'm using some of them, gonna look=20
> deeper on xml support...
A simple XSLT stylesheet should work for post-processing, e.g.
<?xml version=3D"1.0" encoding=3D"utf-8"?>
<!--=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Condense.xsl
Removes comments and extraneous whitespace from a source file.
Good for optimizing an XSL document. Only pitfalls are that it might
rearrange attributes, depending on the processor implementation.
(I haven't actually seen that happen, though), and it will definitel=
y
not copy DTD information or entity references into the new tree.
Written by: Mike J. Brown <[email protected]>
License: none; use and distribute freely.
Version 1.0 - 05 Jan 2000: First public version. XSLT 1.0 conformant=
.
=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-->
<!-- beginning of the stylesheet -->
<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"=20
version=3D"1.0">
<!-- desired output method -->
<xsl:output method=3D"xml" version=3D"1.0" indent=3D"no"/>
<!-- source document whitespace handling -->
<xsl:strip-space elements=3D"*"/>
<xsl:preserve-space elements=3D"xsl:text"/>
<!--=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-->
<!-- when processing root, element, attribute, or processing-instruction=20
node -->
<xsl:template match=3D"/|*|@*|processing-instruction()">
<!-- create a copy of the current node in the result tree -->
<xsl:copy>
<!-- its attributes and children will be the result of the following=20
instruction -->
<!-- go process attributes and any non-comment children of current node -=
->
<xsl:apply-templates select=3D"@*|node()[not(self::comment())]"/>
</xsl:copy>
</xsl:template>
<!-- end of the stylesheet -->
</xsl:stylesheet>
--=20
Klaus Johannes Rusch
[email protected]
http://www.atmedia.net/KlausRusch/
--------------090709010604080507020707
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 27.08.2011 12:14, Jérôme DESPATIS wrote:
<blockquote cite="mid:[email protected]" type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
Hello,<br>
<br>
Thanks for your quick answer!<br>
Ok so tidy doesn't support that natively<br>
<br>
You're talking about the TidyNewline, but can I change this value
in a config file somewhere ?<br>
Because I only see it in <a moz-do-not-send="true"
class="moz-txt-link-freetext"
href="http://tidy.sourceforge.net/docs/api/tidyenum_8h-source.html">http://tidy.sourceforge.net/docs/api/tidyenum_8h-source.html</a>,
and I would need to recompile tidy in order to change this value
I'm afraid, no ?<br>
<br>
If it's impossible without recompiling tidy, yes the only solution
is to use a minifier as post process, I'm using some of them,
gonna look deeper on xml support...<br>
</blockquote>
A simple XSLT stylesheet should work for post-processing, e.g.<br>
<br>
<?xml version="1.0" encoding="utf-8"?><br>
<br>
<!--=======================================================================<br>
Condense.xsl<br>
<br>
Removes comments and extraneous whitespace from a source file.<br>
Good for optimizing an XSL document. Only pitfalls are that it
might<br>
rearrange attributes, depending on the processor implementation.<br>
(I haven't actually seen that happen, though), and it will
definitely<br>
not copy DTD information or entity references into the new tree.<br>
<br>
Written by: Mike J. Brown <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]"><[email protected]></a><br>
License: none; use and distribute freely.<br>
<br>
Version 1.0 - 05 Jan 2000: First public version. XSLT 1.0
conformant.<br>
=======================================================================--><br>
<br>
<!-- beginning of the stylesheet --><br>
<xsl:stylesheet
xmlns:xsl=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/1999/XSL/Transform">"http://www.w3.org/1999/XSL/Transform"</a> version="1.0"><br>
<br>
<!-- desired output method --><br>
<xsl:output method="xml" version="1.0" indent="no"/><br>
<br>
<!-- source document whitespace handling --><br>
<xsl:strip-space elements="*"/><br>
<xsl:preserve-space elements="xsl:text"/><br>
<br>
<!--=======================================================================--><br>
<!-- when processing root, element, attribute, or
processing-instruction node --><br>
<xsl:template match="/|*|@*|processing-instruction()"><br>
<!-- create a copy of the current node in the result tree
--><br>
<xsl:copy><br>
<!-- its attributes and children will be the result
of the following instruction --><br>
<!-- go process attributes and any non-comment
children of current node --><br>
<xsl:apply-templates
select="@*|node()[not(self::comment())]"/><br>
</xsl:copy><br>
</xsl:template><br>
<br>
<!-- end of the stylesheet --><br>
</xsl:stylesheet><br>
<br>
<br>
<pre class="moz-signature" cols="72">--
Klaus Johannes Rusch
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://www.atmedia.net/KlausRusch/">http://www.atmedia.net/KlausRusch/</a></pre>
</body>
</html>
--------------090709010604080507020707--
--===============3920518086667481884==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management
Up to 160% more powerful than alternatives and 25% more efficient.
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
--===============3920518086667481884==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Tidy-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tidy-develop
--===============3920518086667481884==--