Forum Moderators: open

Message Too Old, No Replies

Cdata?

Need some help understanding a basic detail

         

chrisjoha

6:32 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



I'm writing a XSLT stylesheet to transform XML to XHTML. I need a space between to tags, so I separated them with a space. No space in my output. After a little lurking around I ended up with this: <![CDATA[ ]]> to create the space. Is this the right way to go? I was suprised to see it not preserve (atleast one) space since it preserves newlines. Can anyone flesh out this behaviour for me?

athinktank

8:41 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



howdy chrisjoha,

short answer:
&#160;
or
<xsl:text> <xsl:text>
both should work.

You can't use &nbsp; out of the box because it's not an entity that xsl will recognize... it's equivalent is &#160; The xsl:text element is nice and i wrap up all my text in that just to not have any random text hanging around.

Spaces drove me nuts too. I just think it's part of the xsl hazing that has to happen.

I try to reserve CDATA to only when absolutely necessary. I like to use it when I cannot guarantee the data within the element or when the data must contain reserve characters.