• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Allowing & br tags to show using XSL

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That worked great! Thanks for the help!
 
Chris Behr
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic