Jason Hoskins

Greenhorn
+ Follow
since Oct 30, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jason Hoskins

I guess the next question is....is there any easy way to use xalan to convert a w3c document into html ?? Every example i have seen on the net have been transforming xml files with Sreamsource.
I can create the exact w3c Document I want to convert. But when I feed the Document into the transformer class it bombs (code below):
DOMSource xmlSource = new DOMSource(objDocument);
DOMResult xmlResult = new DOMResult();
transformer.transform(xmlSource, xmlResult);
My questions is why does the Xalan convert XML docs fine as Streamsource (which I can't use) and not DOMSource ?? Even if the content of the document I supply to the DOMSource is exactly the same ??
The apache javadoc is pretty sparse.
Hmm...I did instatiate the jdom DOMBuilder class but I never actually called any of its methods.
Right now I have left the code mentioned above and went straight with an JDOM solution...which still does not work.
Here is what I have:
//Build XML Document:
SAXBuilder builder = new SAXBuilder();
org.jdom.Document doc = builder.build("c:/source.xml");
//Convert with JDOM using Xalan
Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(new File("c:/stylesheet.xsl")));
// Run the transformation
JDOMSource source = new JDOMSource(doc);
JDOMResult result = new JDOMResult();
transformer.transform(source, result);
//output the result into a string (for now):
Document doc2 = result.getDocument();
XMLOutputter outp = new XMLOutputter();
outp.setOmitDeclaration(true);
outp.setTextNormalize(true);
outp.setIndent(" ");
outp.setNewlines(true);
String test = outp.outputString(doc2);
Of course this doesn't work. It throws this exception : a java.lang.IllegalStateException: Root element not set
From reading the documentation, it should just be a matter of feeding your XML document into your xslt engine. The results will go in your result Document, and you just write it out using the XMLOutputer class. However, for some reason my result Document will not print.
Anyone have any ideas ??
Thanks LAsse...are the xalan libs not able to perform this ??
Hi Guys,
I'm new to XSLT, and I'm trying to do a very simple transformation using the Xerces DOMParser and the Xalan XSL engine. However I can't get it to work.
Here is what my xml doc looks like (slightly trimmed):
<?xml version="1.0" encoding="UTF-8"?>
<storydetail>
<title>Network Status: Important notice</title>
<byline>Last Update</byline>
<date>10/28/03 5:10 AM</date>
<body>Various text in here</body>
</storydetail>
My xsl stylesheet is extremely simple:
<?xml version='1.0' encoding='ISO-8859-1'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl utput method="html" media-type="text/html" encoding="ISO-8859-1"/>
<xsl:template match="storydetail">
<br />
<b><xsl:value-of select="title"/></b><br />
<p><xsl:apply-templates select="body"/></p>
</xsl:template>
<xsl:template match="htmltag" mode="hidename">
<xsl:text disable-output-escaping="yes"><</xsl:text>
<xsl:value-of select="@htmlname"/>
<xsl:value-of select="@htmlattrs"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="image">
<img src="{.}" align="right" vspace="10" hspace="8"/>
<br clear="all"/>
</xsl:template>
<xsl:template match="a[@href]">
<a class="textred" href="javascript:launch('{@href}')">
<xsl:value-of select="."/>
</a>
</xsl:template>
<xsl:template match="@* | * | text()">
<xsl:copy>
<xsl:apply-templates select="@* | * | text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The XML document basically sits at a URI on a separate web server. I'm just trying to build the Document object using the DOMParser, and feed the entire Document into XSL.
Here is the guts of my code (stripped down for space):

String strBulletinUrl = "http:www.site.com";
DocumentBuilder objDB = null;
DocumentBuilderFactory objDBF = null;
org.jdom.input.DOMBuilder objDOMBuilder = null;
objDBF = DocumentBuilderFactory.newInstance();
objDB = objDBF.newDocumentBuilder();
objDocument = objDB.parse(strBulletinUrl);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(new File("stylesheet.xsl")) );
DOMSource xmlSource = new DOMSource(objDocument);
DOMResult xmlResult = new DOMResult();
transformer.transform(xmlSource, xmlResult);
Seems simple enough but it keeps bombing on me big time . I keep getting the following error:
javax.xml.transform.TransformerException: XSL-1103: (Fatal Error) DOMResult can not be this kind of node.

Just a little background info. I'm trying to run this from a jsp page and I have all the proper jar files installed. Any help would be appreciated.
Hi Everyone,
This is my first post. I've been searching for a solution to my problem but to no avail.
Here goes:
I am trying to write a java bean which reads a URL and parses out certain info. This info is then stored in another object and used by some jsp pages at an application level. Its basically a peice of code which holds "Status" information and is read by numerous jsp pages (it refreshes every 5 minutes).
Anyways, here is the guts of my problem. The info I am trying to parse is from an XML document. At first I had written the bean to parse the document using the xerces DOM parser. However, the XML document (see below) has html mark-up which is not contained in a CDATA section. I have to retain the html mark-up, so I abandoned the DOMParser (long story) and jsut decided to read the XML (which sits on a web server) into a string via the HttpUrlConnection class. The using standard String methods I parsed out the few bits of info I needed.
This logic works fine, but I am having trouble with the encoding. The XML document is UTF-8 encoded, however the html mark-up contains ISO-8859-1 encoding. This includes those pesky curly quotes. The HttpUrlConnection class reads the URL fine but can not read the quotations cahracters and replaces them with gibberish.
Has anyone encountered anything like this before ?? I'm trying to run the beans on a Solaris 5.8 box.
<?xml version="1.0" encoding="UTF-8"?>
<storydetail>
<abstract>Insert various html tags in here</abstract>
</storydetail>