Question

Show html code in xslt

Asked by: abgsc

Hi,
values in a "textarea" on a web form is stored in a database and retrived from database by xml and xslt. What we want to achieve is to write text with html code (to format the text), save it in the database and show it on the same web page. In the textarea we can write "This text shows <b>bold text</b>". The string with <b> tag is stored in the database, but when retrived in xsl file by <xsl-value-of> then the text is written as we wrote it with html tags and text is not formatted inside the textarea.

How can we write/modify the text with html tags in a textarea and show it afterwards when it's saved in the database within the same textarea? Is it possible or do we need to do it in another way?

Reg
Stian

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-05 at 02:43:41ID24873915
Tags

html xslt .net asp

Topics

Hypertext Markup Language (HTML)

,

Extensible Stylesheet Language Transformation (XSLT)

,

Active Server Pages (ASP)

Participating Experts
2
Points
500
Comments
27

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. xsl/xslt
    What is the core difference between xsl and xslt.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: GertonePosted on 2009-11-05 at 02:54:31ID: 25748222

use
<xsl-value-of disable-output-escaping="yes" select=".">
instead of
<xsl-value-of select=".">

the output escaping is disabled this way an a < will not be escaped as an entity

 

by: GertonePosted on 2009-11-05 at 02:55:20ID: 25748224

note that I copied your example and the xsl-value-of should read as xsl:value-of

 

by: serrutomPosted on 2009-11-05 at 03:21:19ID: 25748368

You can use CDATA tags

<html>
  <body>
    <xsl:for-each select="root/node">
      <div>
        <![CDATA[
        	<root>
        		<node>
        			test
        		</node>
        	</root>
        ]]>
      </div>
    </xsl:for-each>
  </body>
</html>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:

Select allOpen in new window

 

by: GertonePosted on 2009-11-05 at 03:26:56ID: 25748387

CDATA will have the opposite effect.
Everything inside the CDATA in the XSLT will be considered a textnode and the data will be escaped

from how I understand the question, this is what the original poster does not want
> then the text is written as we wrote it with html tags and text is not formatted
but reading the question again, I am not sure anymore

 

by: serrutomPosted on 2009-11-05 at 03:32:37ID: 25748419

Below some example files as i understood it

XML file: 
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="test.xsl" type="text/xsl" ?>
<root>
	<node><![CDATA[<root><node>test</node></root>]]></node>
	<node><![CDATA[<root><node>test</node></root>]]></node>
</root>  
XSLT file: 
<?xml version="1.0" encoding="ISO-8859-1"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
  <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
    <xsl:for-each select="root/node">
      <div style="background-color:teal;color:white;padding:4px">
        <textarea><xsl:value-of select="."/></textarea>
      </div>
      <xsl:value-of select="."/>
    </xsl:for-each>
  </body>
</html>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:

Select allOpen in new window

 

by: abgscPosted on 2009-11-05 at 03:42:49ID: 25748465

I have added  'disable-output-escaping="yes"', but this do no do the trick. In the comment field I write this text "This is <b>bold text</b>"

xsl-file

<textarea rows="4" cols="60">
<xsl:value-of select="@comment" disable-output-escaping ="yes"/>
</textarea>

output

This is <b>bold text</b>"

If I  move
<xsl:value-of select="@comment" disable-output-escaping ="yes"/>
outside the <textarea>, ie in a <div> then it shows ok, formatted correctly

 

by: serrutomPosted on 2009-11-05 at 03:50:55ID: 25748509

You will not be able to put your comment as attribute of your node. As attributes cannot contain all characters.
You need to add an extra child node, and put the content between cdata tags

<node>
    <comment><![CDATA[<root><node>test</node></root>]]></comment>
    ....
</node>

 

by: GertonePosted on 2009-11-05 at 03:52:45ID: 25748521

yeah, but I am not certain that you can actually layout a text area like you want.
That is why most BB like editors have some sort of "view" window above the text area,
to show how the text is finally layouted

 

by: GertonePosted on 2009-11-05 at 03:55:31ID: 25748541

@serrutom, no that is not the point.
You are right that you can not have CDATA inside an attribute, but in this case that simply doesn't matter
Whether this is CDATA or an escaped text node does not matter for the XSLT
The parser will make the CDATA an escaped text-node before it even reaches the XSLT
Obviously abgsc has access to the correct escaped text node, but is unable to unescape it in the text area
That is the real issue

 

by: serrutomPosted on 2009-11-05 at 04:02:40ID: 25748581

Your problem is not the text area, but your xml source data file.
If you don't escape the content coming from your server, you will get errors or.

<node>
    <comment><![CDATA[<b>test</b>]]></comment>
</node>

is not the same as

<node>
    <comment><b>test</b></comment>
</node>

and this is not allowed

<node comment="<b>test</b>">
</node>

Your <b> tas is seen as a node of the xml and your xml will not be well-formed

 

by: GertonePosted on 2009-11-05 at 04:03:27ID: 25748583

well, my last statement is somewhat vague
using disable-output-escaping abgsc can unescape the text node in the text area,
but this doesn't have the desired layout effect

I checked, you simply can not layout text in a text area.
So you should go from my earlier suggestion, have two divs,
one with the text area that contains the html code
and one with the layouted view of what is originally in the text area
you can add a button that allows you to "preview" the content of the text area in the "preview" pane

 

by: GertonePosted on 2009-11-05 at 04:06:40ID: 25748598

@serrutom, mmh, somewhere you diverted from the issue and you seem to be a bit slow in getting back on track

read this

>If I  move
> <xsl:value-of select="@comment" disable-output-escaping ="yes"/>
> outside the <textarea>, ie in a <div> then it shows ok, formatted correctly

which indicates the problem is not in the storage but in the view

and then reread my two last posts

 

by: GertonePosted on 2009-11-05 at 04:10:00ID: 25748616

@serrutom,

note that "blablabla<b>bold</b>"
will enter the database as (see below)
and there is nothing CDATA will add or remove from this picture
and elements or attributes will not have an effect on this
(likely in the database it is just a field)

blablabla&lt;b&gt;bold&lt;/b&gt;

                                              
1:

Select allOpen in new window

 

by: serrutomPosted on 2009-11-05 at 04:30:01ID: 25748713

@abgsc... can you post your input xml file and the part of your xslt file?

@Gertone... You assume that the data is escaped, i haven't seen a post that told us the data is escaped, or haven't seen an example. Abgsc wrote: In the comment field I write this text "This is <b>bold text</b>". This means to me that the data isn't escaped as it get to the parser.

@Gertone... i think i'm not realy slow to get on my track...!

 

by: GertonePosted on 2009-11-05 at 05:14:05ID: 25749020

First note that this is a question in the threads: HTML, XSLT and ASP
If I then read the word "textarea", I automatically assume a HTML form with a text area input field
http://www.w3schools.com/TAGS/tag_textarea.asp
just to make sure that we get the semantics right

If I then read the part you quoted
abcsg> I write this text "This is <b>bold text</b>".
I understand writing as typing text in the text area.
There is no parser touching this, and when it is sent to the server, it will be sent as a text stream, escaped to make it a legal html text stream

serrutom> i haven't seen a post that told us the data is escaped

yes you have seen a post that proves the data is escaped

combine this statement from the original question

abgsc> <xsl-value-of> then the text is written as we wrote it with html tags

with this later statement

abgsc> <xsl:value-of select="@comment" disable-output-escaping ="yes"/>
abgsc> outside the <textarea>, ie in a <div> then it shows ok, formatted correctly

Now think:
data goes in as tags (in a text area, actually then I allready know it will be escaped when sent back to the server, but anyhow)
data comes back as a literal string containing the tags
tell me which XSLT processor will spit out the tags using <xsl:value-of> if it were real tags, not an escaped string.
You could be right if abgsc used <xsl:copy-of> but he claimed he used <xsl:value-of>
xsl:value-of will only concatenate all the text nodes, and drop the tags... so if the tags reappear... they must have been in the text node
This is I think enough proof as a foundation to my claims
I assume you never came accross disable-output-escaping, I usually recommend not to use it anyway, but here is meets its proper use case

 

by: serrutomPosted on 2009-11-05 at 05:23:42ID: 25749111

@Gertone...

Some respect, friendlyness and respect for other poster would be nice... You might be a hot-shot, but other people have some knowledge to.
I thought we just want to find a good solution for abgsc, and don't start a war here.

I want to enjoy myself on Experts Exchange and learn from other peoples problems and situations.
While doing this I don't like to be called a dumb-nut, and be shouted at.

@abgsc...

Sorry it got this far, but i just wanted to help

With this said... I withdraw.

Have a nice day


PS: I have been writing XML/XSLT transformations for the past 10 year... I know what I'm talking about.

 

by: GertonePosted on 2009-11-05 at 05:32:10ID: 25749194

@serrutom,

sorry, if you felt that I was trying to start a war, and if one way or another I offended you, my sincere apologies.
I just felt misunderstood and all I tried to do is build up my case to explain to you what I think is happening.
I don't feel like a hot-shot at all, and had not a single intention at all to shout at you or call you a dumb-nut.
Sorry if my words gave you that impression, you must have understood them in another way the I intended them
(let us say that they juqt came out wrong, to meant well, English is not my mother tongue)

Yes, I am just trying to find a good solution for the original poster,
and would be happy to be proven not right, no problem with that

Again, my apologies

Geert

 

by: serrutomPosted on 2009-11-05 at 05:36:32ID: 25749233

@Geert: apologies accepted... now back to the problem

@abgsc: Would you be able to post some input data and code?

 

by: abgscPosted on 2009-11-05 at 06:41:31ID: 25749884

serrutom, the problem  is as gertone describes. What I want to achieve is to edit and show text with html in the same textarea tag, but that is not possible I guess.

As I understand, the solution is to have one input field (can be a <textarea>) where the  text with html tags is entered. This info is then saved in the database, incl tags as plain text. To show this text rendered as html I need a second field, but it is not possible to use a <textarea> since html code is not working inside this tag (I have tried it and it do not work).

 

by: GertonePosted on 2009-11-05 at 06:45:32ID: 25749933

Most buletin boards work with a double pane. One with a preview window and one with the text area.

I would prefer that option personally>

An other options is to use an embedded html editor, that is a bit heavy (try the Rich Text option in Experts Exchange),

but might suit you better

 

by: abgscPosted on 2009-11-05 at 06:48:06ID: 25749967

is there any easy way of start using a double pane like in bulletin board in a xsl file?

 

by: GertonePosted on 2009-11-05 at 06:48:06ID: 25749968

If you google
"embedded html editors" you get tons of suggestions,
I only played with them as a toy, never used one really in production
but it might help you

 

by: serrutomPosted on 2009-11-05 at 06:49:13ID: 25749982

Maybe the TinyMCE editor an option:

http://tinymce.moxiecode.com/

 

by: abgscPosted on 2009-11-05 at 06:52:38ID: 25750030

thx for your help!

 

by: GertonePosted on 2009-11-05 at 06:59:43ID: 25750117

double pane:
Basically. add a div above the text area. give the div an identifier (id attribute), also give the text area a id attribute
put a button on the page with a java script action that pushes the value of the textarea to the div (some sort of overwrite of the html innerHtml) Not sure what will happen to the code
Note that if you use client XSLT for this... disable-output-escaping is NOT supported by Mozilla based browsers

TinyMCE:
have no real experience with these editors. Seems like a plausible one.
Just make sure that if you need browser independence, you need to test for that when evbaluating.
I have come accross a couple that use ActiveX, and as such can only be used for IE

 

by: abgscPosted on 2009-11-06 at 03:17:24ID: 31650421

skillfull and very helpful

 

by: GertonePosted on 2009-11-06 at 03:26:33ID: 25758205

welcome

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...