Sunday, 1 March 2015

trying to use jaxp : java obj -> xml node -> xslt -> display html



I'm having kind of a weird problem I can't really figure out. I'm writing a web application, and I have a strategy for rendering the html which is giving me problems.


I have a group of objects with an asXML() method that returns an org.w3c.com.Node obj. That node has some html marked up as CDATA; I want to pass the entire node to an xslt stylesheet that will render the html the way I want it.


I wrote a junit test case that seems to work properly...meaning when I print it out on the console, it gives me the output I want



String sTransformedHtml = XMLUtils.runXmlTransform(sStylesheetPath, myNode);


a snippet of output:



<h1>This is a test description</h1>
<p>it uses some nice <em>markdown</em> formatting.</p>


yet when I try to call that same method in the same way from a servlet, I a) get escaped <, >, &, etc and b) the stylesheet seems to have been bypassed. In other words, the html markup created by the stylesheet itself has been omitted(not shown in example).



&lt;h1&gt;This is a test description&lt;/h1&gt;
&lt;p&gt;it uses some nice &lt;em&gt;markdown&lt;/em&gt; formatting.&lt;/p&gt;


Is there something inside the tomcat container that does char escaping? I've checked to make sure the stylesheet exists and everything else I could think of.


The function example I showed returns a string...I thought I might have better results if that func returned a node...but I ran into other annoying issues. for example, This is one of the html tags in the xslt template that should appear in the output :



<input type="hidden" name="my_id" value="{$myId}"></input></form>


but for some reason the output from the transform does not close the input tag....



<input type="hidden" name="my_id" value="2652"></form>


with all of this, I am considering just bagging the obj -> xml node -> xslt -> display html approach.


Just wondering if a) the approach itself sucks, b) have any of you ever dealt with this situation, and c) is there something simple I'm missing?


thanks, jw


No comments:

Post a Comment