File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XSLT - empty tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT - empty tag" Watch "XSLT - empty tag" New topic

XSLT - empty tag

Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
I use XSLT to transform XML to XHTML, So when a particular tag NODE_VAL in XML is empty, I render a textarea tag as below

But the output HTML is different in different runtimes (may be the XALAN.jar is the culprit but cannot control it)
in some instances the XHTML looks like

and the browser happily renders a TEXTAREA widget
but in some instances the XHTML looks like (empty tag)

and the browser either is not displaying the widget or is displaying the wrapping HTML tags (example if the textarea is wrapped in div tag, the div tags are seen in the text area)

What should I code differently in XSLT to always render the XHTML ase

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

If you are generating XML (which is what XHTML is) then you have no way of controlling how empty elements are rendered in the output, and it shouldn't make any difference anyway.

So if it does make a difference (and from what you say, it does) then it looks to me like the browser isn't treating your output as XHTML, but just as HTML. Perhaps you should investigate why that is.
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
According to the SME of my other forum POST
I should not render the empty tags in XHTML
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

You're between a rock and a hard place. You can try sending the mdeia type of application/xhtml+xml but If that doesn't work you may be without paddle.

[Asking smart questions] [About Bear] [Books by Bear]
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
I tried that mime type too, and IE7 doesn't understand it
Guess I have to code some workarounds
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
I got around this issue, with a bit of hack in code by placing a known token in the textarea and removing it from the javascript on page load.
So for now the page is in business.
Thanks for your analysis.
I agree. Here's the link:
subject: XSLT - empty tag
It's not a secret anymore!