• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

whitespace formatting defined in XSL stylesheet disappears from my xhtml page

 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, (thanks in advance!)

I am trying to generate an xhtml page that includes text with line numbers. The line numbers align with the left-hand margin, and are separated from the text by whitespacing. To generate this formatting I have written some XSL code like this:




This code works. (Note that in this code code I represent the spaces using the whitespace entity ' AmpersandPounsign160; '. These whitespace characters vanish on the Javaranch page.) It produces the desired whitespace padding between the line number and the text.

But then, if I revisit the page or even another page generated with this same stylesheet, the whitespacing collapses. This is true, unpredictably, if I clear the browser cache.

I also feed this xhtml into a java applet, where I display it in a textPane using HTMLDocument. The result is the same is that on the plain xhtml page: sometimes the whitespacing collapses. In fact, if the collapse of whitespacing occurs in the xhtml page, it always occurs in the applet, and vice versa.

including an xsl:preserve-space directive has not worked.

This led me to wonder, might the whitespacing collapse with XSLT stylesheet compilation? That's the only think I can think of.

So, some questions:
(1) how can I fix this problem?
(2) if it is indeed an XSL compilation problem, how can I insure my whitespacing does not collapse during (re-?) compilation.
(3) should I represent my 8 whitespaces using some kind of loop? ('print a single whitespace 8 times?)
(4) perhaps insure that the compiled stylesheet is not cached?

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would start like this:

(1) Identify your problem first. Are you saying that a browser renders an XHTML document, which happens to be the output of an XSLT transformation, differently the second time than the first time? If so then you should look at fixing the browser. Or are you saying that the two transformations result in different XHTML and that results in the differences between the rendered versions?

(2) I don't understand what you mean by "XSL compilation". Are you actually using an XSLT compiler like XSLTC? If so, then aren't you compiling before you generate any XHTML documents?

(3) There's no point in writing different code which results in the same output. The browser doesn't know or care what code generated the document it's rendering.

(4) Again you haven't mentioned the environment in which you are doing the transformations. It's up to you whether you cache things, isn't it? Or were you thinking of a browser cache? That clearly wouldn't affect the behaviour of an applet, and you say you see the same problems there.

Edit: By the way, to have XML escaped forms appear in the forum the way you want to see them, as opposed to having the forum interpret them as is, you simply escape them again. So to get   to appear like that you just type it in as   (and if you want to type something explaining that, you escape it again one more time).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic