• 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

text/html & text/plain

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using XML and XSL with xalan to show a DOM tree from a browser.
I would allow users to pick eith HTML or plain format at run time.
By using response.setContentType("text/plain" );
or response.setContentType("text/html" );
seems look the same from my browser.
Do I need to write different XSL files like taking out all html tags?
Thanks,
Grace
 
Author
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
Just because you set the content type to "text/plain" doesn't mean that HTML tags will be stripped out for you.
Jayson Falkner
V.P./CTO, Amberjack Software LLC
Jayson@jspinsider.com
www.jspinsider.com
[This message has been edited by Jayson Falkner (edited May 10, 2001).]
 
Grace Lo
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try to take out all html tag from xsl file but it gave me error message as following
Invalid at the top level of the document. Line 1, Position 39
<?xml version="1.0" encoding="UTF-8"?>

What did I do wrong?

Grace
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem has nothing to do with HTML tags. If the content type is "text/plain", the browser will display whatever you send as plain, uninterpreted text. If you send HTML, you will see the HTML source.
The problem is probably that you set a "text/plain" content type in your JSP, that is before it gets fed through Xalan. Actually, Xalan determines its own output content type. You can control this - how else? - using the XSL template. The tag controlling this is <output/>. You use it directly inside the <stylesheet> (or <transform> ) element.
<output method="text"/> should produce plain text output. If you want a MIME type other than "text/plain", add a "media-type" attribute, e.g. media-type="text/chocolate". You can also use an "encoding" attribute to indicate the character encoding used.
<output method="html"/> should produce HTML output. Again you can specify a MIME type and/or encoding. In addition, you can specify a document type attribute, e.g. doctype-system="html3.2.dtd". This should cause Xalan to emit a <!DOCTYPE> tag in the HTML output.
This means that you would create two stylesheets, each with a different <output/> tag. I assume your XML is supposed to specify the content, the stylesheets determine how it is rendered. Text and HTML are quite different ways to render your content; it makes sense to use separate stylesheets for them.
- Peter

[This message has been edited by Peter den Haan (edited May 10, 2001).]
 
Grace Lo
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is working!!!
Thanks a lot!
 
reply
    Bookmark Topic Watch Topic
  • New Topic