GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes Allowing & br tags to show using XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Allowing & br tags to show using XSL " Watch "Allowing & br tags to show using XSL " New topic
Author

Allowing & br tags to show using XSL

Chris Behr
Greenhorn

Joined: Jun 12, 2001
Posts: 17
I have a XML document that has multiple comment elements that look something like this:
<GstBk:Comments>Line1
<BR/>Line2
<BR/>Line3
<BR/>Line4
<BR/>Line5
<BR/>Line6</GstBk:Comments>
But when I try to use the following code:
<xsl:value-of select="GstBk:Comments" />
or
<xsl:apply-templates select="GstBk:Comments" />
All I get is:
Line1
Line2
Line3
Line4
Line5
Line6
with no <br/> tags. Does anyone have any ideas how I can display the comments with the break formatting?
Thanks
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Have you tried <xsl:copy-of select="GstBk:Comments" /> ?


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Chris Behr
Greenhorn

Joined: Jun 12, 2001
Posts: 17
That worked great! Thanks for the help!
Chris Behr
Greenhorn

Joined: Jun 12, 2001
Posts: 17
I spoke too soon. It seems to work for the existing xml data but when I add new comment elements they now display in the html as & l t ; and & g t ; (no spaces in between) so they show up as <BR> when looking at the data in the browser instead of being <br> in the html text data. When I look at the raw file data I can't tell the difference between the comments that display properly and the ones that don't. The weird thing is that when I view the file and then save it the next time I use the xml/xsl everything displays fine until the servlet adds another element. Does anyone have any idea what may be causing this?
Thanks
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065

Seems that the problem lies in how you add your comments element. Is there any middleware software between your hands and XML file? Looks like this software escapes "<" characters as &lt; before writing to the XML file, when it shouldn't.
Chris Behr
Greenhorn

Joined: Jun 12, 2001
Posts: 17
I am using JDOM to read in the existing xml document and then write it back out. Here is a sample of the code:
try{
SAXBuilder builder = new SAXBuilder();
doc = builder.build(fileIn);
root = doc.getRootElement();
}
... add element using .addContent(new Element("Comments", ns).addContent(commentString));
FileOutputStream fileOut = new FileOutputStream(fileName);
XMLOutputter xmlOut = new XMLOutputter();
xmlOut.output(doc, fileOut);
fileOut.flush();
fileOut.close();
My web provider has a way that I can edit the file using a textarea in a html form and when I look at the data there everything looks fine. And if I save the file from the form then the xml/xsl works just fine.
 
GeeCON Prague 2014
 
subject: Allowing & br tags to show using XSL