Transforming XHTML to HTML
Hi all!
Here's the deal: I'm trying to transform an XHTML document to HTML using XSLT and the Tranformers in the JAXP. So far, I can get documents that are entirely text (w/ no HTML tags at all) or documents that have tags but no text! Basically, all I need to do is strip the xml declaration from the top of the document and replace
tags with <br> tags (get rid of the trailing slash). Any suggestions on the correct XSL templates to use? Is there a simpler way of doing this than using XSLT?
Regards,
V.
You basically want to do an identity transform (outputs what was input), but specify that you want the output formatted as html. I did a quick search for identity stylesheet and this is what I found (untested):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
My xsl skills are fuzzy, so we'll just assume it works and let you test it. You also want to include the following rule, which generates html style tags and leaves out the xml declaration:
<xsl:output method="html"/>
As to whether this is the easiest way to do what you want, I really don't know. Maybe DOM or JDom have an output writer which can use html style, or maybe it's not that difficult to write your own.
Similar Messages
-
Problems in transforming XML to HTML using HP-UX with Netscape Enterprise Server 4.0 sp3
Hi,
Has anyone ever had any problem using XML in NES 4.0 sp3?
I'm using the libraries com.sun.xml.parser, com.sun.xml.tree, javax.xml.transform.
The html is being created but is not being returned.
(it is not showed in browser)
This same xml application works well in Solaris with Iplanet Web Server 4.1, but it is not working in HP-UX with Netscape Enterprise Server 4.0 sp3.
I'm entirely lost. I don't know if there is a bug in this version (NES 4.0) or if I need other xml libraries or it is a problem of JRE version.
Any comments will be appreciate.
Thanks<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Norbert Clavaux ([email protected]):
Hi,
Last year we built a complete new website, based on XML/XSL.
We assumed all browsers would cope with XSL by now, but that was far to optimistic.
Our company planned to launch the new site this december, but XSL is giving us some major problems:
*** All our customers are obliged to use Internet Explorer 4/5.x. Some don't like that at all: they stick to Netscape.
*** IE users have to download and install the MS-XSL parser. At our pilotsites this is giving a lot of trouble and frustration.
I heard that it is possible to do the parsing at the serverside, using XSLT, creating HTML.
HOW CAN WE INSTALL / IMPLEMENT THIS OPTION IN OUR CONFIGURATION?
(PL/SQL / IAS 9i / Sun Solaris / Oracle 8.1.2)
Thanks in advance,
Norbert Clavaux
Nederlandse Bibliotheek Dienst
The Netherlands<HR></BLOCKQUOTE>
You could use DB Prism / Cocoon CMS.
This CMS is built on top of Apache Cocoon Framework and DB Prism servlet engine.
This CMS stores the assets in the DB (CLOB) and applys the stylesheet at runtime.
If you need more information about this CMS look at is free.
This CMS builts the DB Prism web site at www.plenix.com/dbprism/
Best regards, Marcelo. -
Batch Changing Dreamweaver files from XHTML to HTML
Almost all of my Dreamweaver files were created in XHTML
mode. In other
words, when I created a page and was asked whether I wanted
to make it
XHTML compatible, I said YES.
About the time I moved my websites from my PC to my Mac, I
finally
realized that XHTML is a lost cause and changed my doctypes
to HTML. But
I just discovered that even PHP include files that have no
doctype at
all automatically insert <br /> instead of <br>.
So I'm assuming that
there must be some invisible code that says "Format this page
for XHTML!"
So I'm wondering if there's a way to change every file in an
entire site
(or all my sites) from XHTML to HTML.
Thanks.I use XHTML because it forces good coding practices such as
always closing
tags. The usual reason most people give for not using XHTML
is that IE
chokes when it is served as xml+application instead of text.
XHTML Strict
does not allow target="page.html" but transitional does so I
stick with
transitional.
I won't use XHTML 1.1 because I don't like the modularization
part of the
spec. I like a nice standard spec and don't want to create my
own picking
and choosing which modules to include.
Cheryl D Wise
Adobe Community Expert
http://starttoweb.com
"David Blomstrom" <[email protected]> wrote
in message
news:[email protected]...
> Cheryl D Wise wrote:
>> While I can't help you with your batch convert issue
would you mind
>> sharing why you consider XHTML a "lost cause"?
>>
>
> As I recall, the first one to make me scratch my head
was our own Al
> Sparber. If I remember correctly, he said he still used
HTML because
> XHTML...well, I can't even remember the specific
reason(s) he gave. But
> I've noticed a lot of other pros still using HTML.
>
> I THOUGHT XHTML was supposed to serve as sort of a
bridge between HTML and
> XML, which was supposedly the direction the web was
heading. But I began
> reading more and more articles claiming that there was
little point in
> embracing XHMTL as the web simply wasn't moving in that
direction - or at
> least not very quickly. I'm not sure if this was another
of those things
> that Microsoft was retarding or not; I've read so many
confusing things
> about XHTML.
>
> Still, I stuck with XHTML for years until I recently had
some sort of
> problem. I can't even remember what it was offhand -
something to do with
> the doctype, I think. Or maybe there's something you can
do in HTML but
> not in XHTML.
>
> In the meantime, I asked questions about XHTML on forums
but never got a
> really clear explanation regarding WHY I should use it.
XML is even more
> perpelexing. I understand that it can function similar
to a database, but
> I already have a database software program - MySQL. I
tried to figure out
> some of the cool things I could do with XHTML and XML
but all the
> responses I got from geeks were - well, geeky. They seem
to use them
> because they think they're cool, but no one could offer
any practical
> reasons for embracing them.
>
> So I finally said to H*ll with it and changed all my
doctypes to HTML. Now
> I just have to change all my closing tags from </>
to <>. -
Transform EVENT_DATA into HTML message
Hi!
I am trying the following:
From Interconnect we receive an event message containing the common view message in xml format in the EVENT_DATA section of the event.
I want to use an XML transformation to transform the message into HTML and have a department confirm the contents of the message.
To do this, I used XML transformation to generate a new event type attribute with the XHTML contents of the message.
How can I attach this to a message?
Jeroen van VeldhuizenAfter your XML Transform Activity you could transition to a function activity that performs a setitemattr to populate an item attribute with the contents of the 'NewDocument' Message attribute, then transition to a notification activity that has a message attribute that refers to the item attribute set from the function activity.
-
Problem in transforming xml to html using xsl
Hi everybody ,
I am creating a xml in memory and i want to transform using xsl into an html.
I want to embed some html code also in the data node.But when I get the html it simply writes as it is. I tried to make it cdata section but it did not worked. Pls help.
crypticashu
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class mytemp {
public static void main(String args[])
DocumentBuilder builder = null;
Document document = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try
builder = factory.newDocumentBuilder();
document = builder.newDocument();
catch (ParserConfigurationException e)
e.printStackTrace();
Element root = (Element) document.createElement("REPORT");
document.appendChild(root);
Node child = document.createElement("DATA");
CDATASection data = document.createCDATASection("<b>Hello World </b>");
child.appendChild(data);
root.appendChild(child);
document.getDocumentElement().normalize();
DOMSource domsource = new DOMSource(document);
TransformerFactory tfactory = TransformerFactory.newInstance();
File f = new File("c:/mytemp/report.xsl");
StreamSource xsl = new StreamSource(f);
File html = new File("c:/myhtml.html");
try
Templates templates = tfactory.newTemplates(xsl);
Transformer transformer = templates.newTransformer();
transformer.transform(domsource, new StreamResult(html));
catch(Exception e)
e.printStackTrace();
}want to embed some html code also in the data node.But when I get the html it simply writes as it is.That statement contradicts:
In real application i will be getting data containg html tags.I want the parser to read that data as simple text. Both cannot be true. You either want the HTML to not be parsed or you want the transformer to deal with it. Which one?
- Saish -
XSLT Transform XML 2 HTML does not work well
Hi,
This is my first attempt to use XSLT to convert my XML file into HTML using Java. I have included below the java code I used for the transformation, the xsl file and the xml file.
As per the xml file, I would like to display the carrier's common-name for each host. However, I can only get to display the carrier-id using the code line
<xsl:value-of select="./@carrier"/>
as shown in the last part of the xsl file, but cannot get the carrier's commonname from the carrierid using the code,
<xsl:variable name="hostCarr" select="./@carrier"/>
<xsl:variable name="hostcomName" select="id($hostCarr)/common-name"/>
<xsl:value-of select="$hostcomName"/>
However this works well if I were to use XML SPY for the conversion, instead of the Transform class in Java. I am using version 1.4.1 of Java.
Please help.
Thanks,
Prasuna
XML file
<pathinfo pathogen-name="Brucella spp.">
<taxonomy>
<carrier carrierID="wild">
<common-name>Wild cies</common-name>
</carrier>
<carrier carrierID="sheepandgoats">
<common-name>Domestic Pig</common-name>
</carrier>
<carrier carrierID="lab">
<common-name>Laboratory environment</common-name>
</carrier>
</taxonomy>
<host-list>
<host carrier="wild"></host>
<host carrier="lab"></host>
<host carrier="sheepandgoats"></host>
</host-list>
</pathinfo>
XSL file
<xsl:stylesheet version="1.0" xmlns:a="http://www.xmlspy.com/schemas/orgchart" xmlns:ipo="http://www.altova.com/IPO" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" omit-xml-declaration="no" indent="no" media-type="text/html"/>
<xsl:template match="pathinfo">
<html>
<head><title><xsl:value-of select="@pathogen-name"/></title>
</head>
<body bgcolor="#ffffe5" text="#000000" link="#007a00" vlink="#7a0000" alink="#ff0000">
<xsl:apply-templates select="host-list"/>
</body>
</html>
</xsl:template>
<xsl:template match="host-list">
<ol>
<xsl:for-each select="host">
<li>
<xsl:variable name="hostCarr" select="./@carrier"/>
<xsl:variable name="hostcomName" select="id($hostCarr)/common-name"/>
<!--
<xsl:value-of select="./@carrier"/>
<xsl:value-of select="$hostcomName"/>
-->
<xsl:value-of select="$hostcomName"/>
</li>
</xsl:for-each>
</ol>
</xsl:template>
</xsl:stylesheet>
Java Code
import javax.xml.transform.*;
import java.net.*;
import java.io.*;
public class Xml2Html {
public static void main(String[] args) {
try {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer =
tFactory.newTransformer
(new javax.xml.transform.stream.StreamSource
("temp.xsl"));
transformer.transform
(new javax.xml.transform.stream.StreamSource
("temp.xml"),
new javax.xml.transform.stream.StreamResult
( new FileOutputStream("temp.html")));
catch (Exception e) {
e.printStackTrace( );From Michael Kay's book "XSLT Programmer's Reference":
'A non-validating XML parser isn't required to read attribute definitions from an external DTD. In this situation the XSLT processor will assume there are no ID attributes present, and the id() function will always return an empty result."
Presumably you didn't set your transformer to use a validating parser, and I don't even see a reference to a DTD there. However the expression id('X') is equivalent to //*[@id='X'], Kay goes on to say. Try that instead. -
How to use a transformer xml to html
hi
I want to develop jsp pages based on xml data, so to construct components with xml data i must use a transformer converting xml to htm. so if there is a better or more generic solution of classes or examples that can help me , i tried to use cocoon but the problem was to use it within a jsp page.
please to mail me your suggestions or solutions .
thank youReview Xalan/Xerces from the Apache project.
http://xml.apache.org/xalan-j/index.html
http://xml.apache.org/xalan-j/usagepatterns.html#servlet
http://xml.apache.org/xalan-j/samples.html
Just one method... -
Help Please ! -- transform XML to HTML using xslt tag in JSP
Hello,
I have problem to do XSL transform in JSP.
I have an XSL : test.xsl
I have an XML : test.xml
In JSP I have:
<x:xslt media="html" xml="test.xml">
<x:stylesheet media="html" uri="test.xsl" />
</x:xslt>
But It doesn't work the way it suppose to. What is wrong in my code ? I followed the URL http://e-docs.bea.com/wls/docs81/xml/xml_apps.html
Thanks in advance,
ChristinaBasically:
try{
//Setting up parameters.
xml=new StreamSource(new File(xmlInput));
xsl=new StreamSource(new File(xslInput));
baos=new ByteArrayOutputStream();
htmlResult=new StreamResult(baos);
//Transform input(xml, xsl) onto html output.
TransformerFactory tfactory=TransformerFactory.newInstance();
Transformer transformer=tfactory.newTransformer(xsl);
transformer.transform(xml, htmlResult);
baos.writeTo(out);
//System.err.println(htmlResult.getOutputStream().toString());
catch(...){
}I havent tested and I havent use this for a while, but I hope this can serve as a staring point.
Regards,
OO -
Multiple XML transformed to one HTML
Can any one please help and tell me how to transform many small xml's to one html using one style sheet. What I want to do is to transform many small xml's(summary.xml, detail.xml etc) into one HTML using one or many xsl.
Thanks,
VijayanYou can use the document() function in XSL.
-
Hi,
How to converting PDF file to HTML file using java?.
Thanks,
NithyaYou basically want to do an identity transform (outputs what was input), but specify that you want the output formatted as html. I did a quick search for identity stylesheet and this is what I found (untested):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
My xsl skills are fuzzy, so we'll just assume it works and let you test it. You also want to include the following rule, which generates html style tags and leaves out the xml declaration:
<xsl:output method="html"/>
As to whether this is the easiest way to do what you want, I really don't know. Maybe DOM or JDom have an output writer which can use html style, or maybe it's not that difficult to write your own. -
How to transform Xml to html which contains javascript
I know it is useful to use xsl to do simple transformation, but since I need to pass some values into the javascript's functions in html, just don't know how to do that. Any advice is apprciated!!
try
<xsl:element name="script">
<xsl:attribute name="language">javascript</xsl:attribute>
your regular javascript ... take care about the special characters
</xsl:element>
s_Scorpius@yahoo -
Why is CS5.5 assigning HTML extensions rather XHTML?
Ken.John Hawkinson wrote:
the EPUB Content Documents 3.0 specification unambiguously states in
Section 2.1.1 under File Properties:
The XHTML Content Document filename should use the file extension .xhtml.
This means CS5.5's export to EPUB has got it wrong, doesn't it? -
Use Transformer tag within HTML tag
Does anyone know how to use the transformer tag within the HTML tag? I couldn't get it to work...
I.e <input type="hidden" name"id" value="<pt:userInfo name='EmployeeID' xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/'/>">
The example above didn't give the actual value...the <pt> tag never got parsed...
I even tried with the <c:set> JSTL tag as well, same result...the <pt> tag never got parsed...
Please advise!
Thanks
BCYou can work around this with JavaScript:
<input type="hidden" id="myHiddenField" value="" />
<script type="text/javascript">
var employeeID = "<pt:userInfo name='EmployeeID' xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/'/>";
document.getElementById('myHiddenField').value = employeeID;
</script> -
Quote transformed into ' (quote html code)
Hi all,
I try to translate an dbms_xmlapi.DOMDocument with xslt.
My problem is all quote ' are translated to their html code entity : &apos.
The french accent causes problem too.
Could you help me ? I'd like to know if it's possible to disable this translation.
Benoit PironetNot currently. You would need to specify output at text, but this is not currently supported by the database XSLT engine
-
Load a .doc file and transform to an .html
Hi all,
I'm develop a web application but I have two problems, with a JSP I need load a file with extension .doc and save it in the server (upload files) but I don't know how to do that.
Actually I use an AccessRandomFile and ByteArrayOutputStream objects to write the file but when I open it the information in the file appears with extrange symbols. How can I do to write correctly the file .doc in te server?
And the second problem is, when the file .doc are in the serever I need to convert the file to an .html file. How can i do it?
Thanks.You know one thing you can do is simply require the user to provide an HTML file, rather than an Word file. Word has a "save as html" option.
Anyway...
This looks promising for the document conversion part:
http://jakarta.apache.org/poi/
You can use this for file upload on the server:
http://jakarta.apache.org/commons/fileupload/
Maybe you are looking for
-
Hello, I've just bought my new ink cartridge today and just refresh them all 4. Estimate ink level stand ok. Everything fine but there's one small problem. My black ink cartridge is not working. Black ink didn't came out even i did 10 times print and
-
How can I scan my network to determine which PC is using static IP or DHCP?
Hello friends, I`m using Spiceworks for couple of days alreadyand need some help on this - In another post i saw that via SpiceWorks I can see how many PCs are using DHCP or Static IP (http://community.spiceworks.com/topic/37663-how-can-i-scan-my-net
-
Two action in Universal Worklist
Hi Experts, Whenever I test any of the process by initiating it and then I check that action in the universal worklist then it show two action means if I have generated Action1 from the process1. then in the Universal Worklist I found the list as
-
Time Machine options are not working. I am unable to schedule automatic backups.
Time Machine options are not working. I am unable to schedule automatic backups. The On-Off button is grayed out. I can perform a backup manually.
-
Start date for Solaris on Intel
Hi all, Does anyone know the date when Solaris first became available on the Intel Platform? Also, is 2.6 available on Intel?