aspose file tools*
The moose likes XML and Related Technologies and the fly likes Trouble with Embedded HTML during XSLT Transformation using JDOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Trouble with Embedded HTML during XSLT Transformation using JDOM" Watch "Trouble with Embedded HTML during XSLT Transformation using JDOM" New topic
Author

Trouble with Embedded HTML during XSLT Transformation using JDOM

Katie McCann
Ranch Hand

Joined: Jul 24, 2000
Posts: 45
Hi all,
I'm desperately seeking help with a problem I'm having with an XSLT transformation using JDom. I'm pretty new to Jdom/XSLT/etc. and I'm not really sure if the problem is JDOM or XALAN related. Nonetheless, here goes:
One of my XML elements has HTML text in it. I'm storing it as CDATA:
<FullButton><![CDATA[<input type ="hidden" name="year" value="2001"><input type ="hidden" name="make" value="Volvo"><input type ="hidden" name="model" value="S40"><input type ="hidden" name="trim" value="SE 4dr Sedan (1.9L 4cyl Turbo 5A)">]]></FullButton>
After I do the transformation, the "<" and ">" are all transformed into < and >, screwing up the html formatting. I have spent all morning trying various fixes that I have found on various message boards, including:
* using disable-output-esacping="yes"- this just causes my resulting HTML doc to have this declartion surrounding the appropriate text: <?javax.xml.transform.disable-output-escaping?>
* using <xsl:copy-of .../> instead of <xsl:value-of>
* inserting a cdata-section-elements="//styleinfo/FullButton" element into the <xslutput .../> declaration.
I can't get anything to work. I was searching around on apache's Xalan site, and it looks like Xalan *SHOULD* process this correctly. So I'm wondering if it's something with JDom? For the most part, I am using the most recent Jdom .java files from the CVS (as opposed to what's in the build 6 .jar file)- and I'm also using xalan.jar etc. from the Jdom repository.
Any advice is greatly appreciated!
Katie
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Katie, is there any particular reason why you want to store HTML tags as CDATA? If they are well-formed, you can include them in XML document "as is". Do you want them to be a part of your resulting HTML? If so, you can use <xsl:copy-of> element:
XML:
<?xml version="1.0"?>
<FullButton>
<input type ="hidden" name="year" value="2001"/>
<input type ="hidden" name="make" value="Volvo"/>
<input type ="hidden" name="model" value="S40"/>
<input type ="hidden" name="trim" value="SE 4dr Sedan (1.9L 4cyl Turbo 5A)"/>
</FullButton>
XSL:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="input">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
resulting HTML:
<html>
<body>
<input type="hidden" name="year" value="2001">
<input type="hidden" name="make" value="Volvo">
<input type="hidden" name="model" value="S40">
<input type="hidden" name="trim" value="SE 4dr Sedan (1.9L 4cyl Turbo 5A)">
</body>
</html>
Or your HTML tags have another mission?

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Katie McCann
Ranch Hand

Joined: Jul 24, 2000
Posts: 45
No. I had originally tried using <xsl:copy-of .../> with the embedded HTML *NOT* stored as CDATA (just a regular element) but it still didn't work in JDOM.
About 15 min. after posting the original message, I solved my own problem. It was something that the JDOM XMLOutputter class file was doing. There is a escapeElementEntities(String st) method, and I had to comment out the following lines:
/*
case '<' :
stEntity = "<";
break;
case '>' :
stEntity = ">";
break;
*/
Not an elegant solution, but it worked.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with Embedded HTML during XSLT Transformation using JDOM