where did the whitespace go? [modified]
-
Hi all, I'm having a problem with my XSL converting to HTML. I can view all content fine, except the white space is not preserved! I've tried all relevant attributes such as xml:space, xsl:preserve-space, bt don't work :(:(:(:(:(:(:(:(:(:( For example in my XML: <catalog> <content> lines and lines of text more text </content> </catalog> When transforming I get: lines and lines of text more text It's all bunched up...where did the newline characters go? my XSL contains this: <xsl:value-of select="content"/> Any ideas? Thanks. -- modified at 11:55 Thursday 29th June, 2006
-
Hi all, I'm having a problem with my XSL converting to HTML. I can view all content fine, except the white space is not preserved! I've tried all relevant attributes such as xml:space, xsl:preserve-space, bt don't work :(:(:(:(:(:(:(:(:(:( For example in my XML: <catalog> <content> lines and lines of text more text </content> </catalog> When transforming I get: lines and lines of text more text It's all bunched up...where did the newline characters go? my XSL contains this: <xsl:value-of select="content"/> Any ideas? Thanks. -- modified at 11:55 Thursday 29th June, 2006
In order for your message to show correctly you have to use < to create the < and > to create the > signs. Anyways, this typically happens when doing an XSL transform. If you're coding the transformation yourself in .NET, you can put settings on the
XmlTextWriter
that will handle the spacing. If you're using a tool like XmlSpy, you can do a pretty print. There might be settings on the transformation software you're using to format the output.
-
In order for your message to show correctly you have to use < to create the < and > to create the > signs. Anyways, this typically happens when doing an XSL transform. If you're coding the transformation yourself in .NET, you can put settings on the
XmlTextWriter
that will handle the spacing. If you're using a tool like XmlSpy, you can do a pretty print. There might be settings on the transformation software you're using to format the output.
thanks. i think you might misunderstand my issue, the problem is about how to transform xml to html with all whitespace which the xml file has, not about the pretty print.;) plz help me
-
thanks. i think you might misunderstand my issue, the problem is about how to transform xml to html with all whitespace which the xml file has, not about the pretty print.;) plz help me
Well, I am doing the same thing as you. I pass some XML through a stylesheet to create HTML. The source is all cramped together, but I don't mind much as long as the HTML comes out ok. But sometimes it doesn't. For instance, if I want a space between two items like so:
<xsl:value-of select="$data/ch2_State"/> <xsl:value-of select="$data/vch10_ZipCode"/>
XSL will strip out the space between the state and the zip code so it looks like this: NY12345 That's a real pain. And, like you say, preserve space and whatever else you put there just doesn't work. So, what I ended up doing was this:
<xsl:value-of select="$data/ch2_State"/>
<xsl:text disable-output-escaping="yes">&</xsl:text>nbsp;
<xsl:value-of select="$data/vch10_ZipCode"/>It's an extra annoyance, but it gets the job done.
-
Well, I am doing the same thing as you. I pass some XML through a stylesheet to create HTML. The source is all cramped together, but I don't mind much as long as the HTML comes out ok. But sometimes it doesn't. For instance, if I want a space between two items like so:
<xsl:value-of select="$data/ch2_State"/> <xsl:value-of select="$data/vch10_ZipCode"/>
XSL will strip out the space between the state and the zip code so it looks like this: NY12345 That's a real pain. And, like you say, preserve space and whatever else you put there just doesn't work. So, what I ended up doing was this:
<xsl:value-of select="$data/ch2_State"/>
<xsl:text disable-output-escaping="yes">&</xsl:text>nbsp;
<xsl:value-of select="$data/vch10_ZipCode"/>It's an extra annoyance, but it gets the job done.
it is also one of solutions, but what i'm aim to do is to write a xsl file, and i use this xsl to transform all articles which stored in xml file. So the positions of carriage return in each article are random. do you have any solution to deal with it? thanks?
-
it is also one of solutions, but what i'm aim to do is to write a xsl file, and i use this xsl to transform all articles which stored in xml file. So the positions of carriage return in each article are random. do you have any solution to deal with it? thanks?
In one situation where I needed the HTML to look exactly a certain way, I changed my output type from HTML to Text. This way, the stylesheet had to pay more attention to me. The stylesheet was harder to write because you have to enclose things in xsl:text tags, but it got the job done. To do a new line, you can do something like this:
xsl:text
</xsl:text>or
xsl:text </xsl:text>
Even if the target is set to Text, XSL still likes to get rid of whitespace, so it's a lot of trial and error. I hope that helps. If you find an easier solution, I'd be happy to hear it!
-
In one situation where I needed the HTML to look exactly a certain way, I changed my output type from HTML to Text. This way, the stylesheet had to pay more attention to me. The stylesheet was harder to write because you have to enclose things in xsl:text tags, but it got the job done. To do a new line, you can do something like this:
xsl:text
</xsl:text>or
xsl:text </xsl:text>
Even if the target is set to Text, XSL still likes to get rid of whitespace, so it's a lot of trial and error. I hope that helps. If you find an easier solution, I'd be happy to hear it!
oh god! i tried your way to do a new line with tags: xsl:text </xsl:text> it's just displayed a space instead of carriage return. what's wrong? -- modified at 17:51 Thursday 29th June, 2006
-
oh god! i tried your way to do a new line with tags: xsl:text </xsl:text> it's just displayed a space instead of carriage return. what's wrong? -- modified at 17:51 Thursday 29th June, 2006
Ya, unfortunately that way works with some XSL transformers and not with others. It's really quite annoying. You might want to use the other method instead. I'm not sure if you have to escape it or not, but this seemed to work pretty well for one guy at work. The only trouble is that it makes the XSL really ugly.
-
Ya, unfortunately that way works with some XSL transformers and not with others. It's really quite annoying. You might want to use the other method instead. I'm not sure if you have to escape it or not, but this seemed to work pretty well for one guy at work. The only trouble is that it makes the XSL really ugly.
yes, i tried to enter <cr/> tag (my self-define tag )to substitute each CARRIAGE RETURN, when i am entering content of my article into xml file, and make relevant manipulation for this tag in xsl file. however, i meet another problem:((, how to find out all <cr/> tags in a xml file? because this tag can be existed in different hierarchy of xml file. any ideas? many thanks
-
yes, i tried to enter <cr/> tag (my self-define tag )to substitute each CARRIAGE RETURN, when i am entering content of my article into xml file, and make relevant manipulation for this tag in xsl file. however, i meet another problem:((, how to find out all <cr/> tags in a xml file? because this tag can be existed in different hierarchy of xml file. any ideas? many thanks
That sounds difficult. Is it that you have text in your XML document that has newlines in it and you want the formatting to be the same in the HTML? If you have the ability to, you might want to try putting it into a CDATA in the XML. After switching to text output, I was able to get my stylesheets working the way I wanted them to.
-
yes, i tried to enter <cr/> tag (my self-define tag )to substitute each CARRIAGE RETURN, when i am entering content of my article into xml file, and make relevant manipulation for this tag in xsl file. however, i meet another problem:((, how to find out all <cr/> tags in a xml file? because this tag can be existed in different hierarchy of xml file. any ideas? many thanks
Define a template match for your <cr> node. In the absence of a select attribute, the xsl:apply-templates instruction processes all of the children of the current node, including text nodes. Tutorial for XSLT : http://www.zvon.org/xxl/XSLTreference/Output/index.html[^]
-
Define a template match for your <cr> node. In the absence of a select attribute, the xsl:apply-templates instruction processes all of the children of the current node, including text nodes. Tutorial for XSLT : http://www.zvon.org/xxl/XSLTreference/Output/index.html[^]
THanks everyone. finally, I use <xsl:copy-of select="./node()"/>to address my problem. Thanks for the Url you provided, it is very helpful.:)