This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Allowing & br tags to show using XSL

 
Chris Behr
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried <xsl:copy-of select="GstBk:Comments" /> ?
 
Chris Behr
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked great! Thanks for the help!
 
Chris Behr
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic