Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Trouble with Embedded HTML during XSLT Transformation using JDOM

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 <xsl:output .../> 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
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Katie McCann
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!