Allowing tags to show using XSL

I have a XML document that has multiple comment elements that look something like this:

<GstBk:Comments>Line1


Line2


Line3


Line4


Line5


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
tags. Does anyone have any ideas how I can display the comments with the break formatting?

Thanks

[764 byte] By [OmahaLancer] at [2007-9-26 5:37:14]
# 1

Because you're getting the string value of the GstBk:Comments element when you do that, which is the concatenation of all of its text-node children. If you want to copy the BR elements to the output, simply do so. There's nothing special about BR in XML, it just acts like any other element.

DrClap at 2007-7-1 13:48:42 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

I looked closer at my problem and this is what I found. 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
when looking at the data in the browser instead of being

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

OmahaLancer at 2007-7-1 13:48:42 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

I thought it was a simple question but now I'm totally lost. Who or what is generating this XML? You, through a text editor or an XML editor? Or the servlet? Or somebody or something else? Or perhaps the servlet is the thing transforming the XML to HTML (more likely)? And when you "view" the XML and the resulting HTML are you using a browser or a text editor?

Let me just give you a couple of pieces of information, since your problem is now totally beyond me. You may already know these things, but I find a lot of people get messed up with them when working with XML and HTML.

If your HTML contains the following text: abc<BR>def

then your browser display will look like this:

abc

def

However, if your HTML contains this: abc&lt;BR&gt;def

then your browser display will look like this:

abc<BR>def

Now, if your XML contains this:

<GstBk:Comments>Line1


Line2

</GstBk:Comments>

then you have what is known as "mixed content", which means a mixture of text and elements. You have two text nodes and you have a BR element.

But if your XML contains this:

<GstBk:Comments>Line1

&lt;BR/&gt;Line2

</GstBk:Comments>

then your GstBk:Comments element only contains a single text node.

Hope this helps you to figure out what's going on.

DrClap at 2007-7-1 13:48:42 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
DrClap, sorry for interfering, but how do you get the & l t sequence to be displayed correctly in this forum ?
lk555 at 2007-7-1 13:48:42 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Sorry, I should have explained the situation better. I have a jsp page that has forms and when posted go to a servlet which reads an existing xml file using JDOM and then adds the form data. I am replacing the '\n' carage returns with a "
" so it will display like I want with the xsl. I am using strings for the
so I don't know how & l t ; is getting in there. The document is then written out using the following code:

FileOutputStream fileOut = new FileOutputStream(fileName);

XMLOutputter xmlOut = new XMLOutputter();

xmlOut.output(doc, fileOut);

fileOut.flush();

fileOut.close();

I don't know if the problem is with the way I create the element or the way the XMLOutputer writes the files or something else. If anyone has an ideas it would be greatly appreciated!

Thanks

OmahaLancer at 2007-7-1 13:48:42 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...