Just wanted to report, sometimes days start off good :)
I had never seen this HTML output even when specifying HTML mode in
xslt because I was overriding the serialization in my code.
Serializer ser = ...
ser.setOutputProperty(Serializer.Property.METHOD, "xml");
Changing it to
ser.setOutputProperty(Serializer.Property.METHOD, "html");
Voila !
Now I dont even need to run the null XSLT , I can programatically
affect the output method and I tested that even a result of xquery
results in the HTML serializaiton I want.
(not to self: dont get too excited and hard code to "html" now :)
David A. Lee
dlee@calldei.com
http://www.calldei.com
http://www.xmlsh.org
812-482-5224
David A. Lee wrote:
4B0A9BBA.3040207@calldei.com" type="cite">
This is awsoeme ! I didnt think it would be this easy.
I had tried it in my own program and it didnt work (now I need to
investigate why, probably overriding the serializer settings)
But if I try it in Stylus Studio it works.
Now I'm going to try to see if I can do this just with mucking with the
serializer.
Thank you !
Input:
<?xml
version="1.0"?>
<html>
<body>
<H1>Title</H1>
<p>paragraph</p>
<p/>
<img src=""foo.jpg"/>
<hr/>
<p/>
<unknown/>
</body>
</html>
XSLT:
<?xml
version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of
select="."/>
</xsl:template>
</xsl:stylesheet>
Output:
<html>
<body>
<H1>Title</H1>
<p>paragraph</p>
<p></p>
<img src=""foo.jpg">
<hr>
<p></p>
<unknown></unknown>
</body>
</html>
David A. Lee
dlee@calldei.com
http://www.calldei.com
http://www.xmlsh.org
812-482-5224
Michael Kay wrote:
D2CA2D72BCFE47A7A5707D8D6DF0AD65@Sealion"
type="cite">
Can't quite see what the problem is. The standard HTML output method in XSLT
should work just fine. It should also be easy enough to use the serializer
from an XSLT engine without actually needing to do a transformation - but
the details depend on your platform.
Regards,
Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay
-----Original Message-----
From: David A. Lee [mailto:dlee@calldei.com]
Sent: 23 November 2009 13:05
To: XML Developers List
Subject: [xml-dev] XML to "HTML"
I'm faced with the 'interesting' request of the web team to
produce HTML not XHTML.
The request came to encode empty elements like <BR/> as <BR>
(and <HR/> as <HR>) The rationale is that they are trying
for maximum browser compatibility and CSS style capabilities.
Although they could not actually point to an actual current
case where using XTHML syntax breaks things, nonetheless they
are insisting on not using it, "just in case" , "for
maximimal conformity".
They also requested that if I use a tag that takes bodies but
the body is empty to not write it as <tag/> Example
<P/> should be written as <P></P> .... although I
think I can waffle on this one.
So I'm tasked now with having to convert reasonably good HTML
into 'perfect' HTML mainly fixing up these empty tags.
Any suggestions ? The proposal from the web team was "Just
use perl to do regex replacements" ... Ug.
I'm not going to use perl. But I might resort to the equivlent of
using Java regex replacements on the final output phase.
But maybe there is a 'better' way to do this ? I'm not
enough familiar
with XSLT to know but it does have an "html" mode ... will it
do this kind of thing ?
I'm hoping I don't need to write my own serializer and have
to actcually
*parse* the 'HTML' to generate these reqirements ... so maybe
a regex is the best fit ?
I'd love to run it through a trivial xquery or xslt filter in
"make the web team happy" mode ...
Other suggestions welcome.
--
David A. Lee
dlee@calldei.com
http://www.calldei.com
http://www.xmlsh.org
812-482-5224
______________________________________________________________
_________
XML-DEV is a publicly archived, unmoderated list hosted by
OASIS to support XML implementation and development. To
minimize spam in the archives, you must subscribe before posting.
[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
subscribe: xml-dev-subscribe@lists.xml.org List archive:
http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
|