html tags inside xml elements

D

doulos05

I am working on an xml project that will contain numerous documents
which will be edited by about 100-150 non-technical people on a
regular basis. Because of this, I am trying to make it as simple as
possible for them. This project is an internal project so it will only
ever be viewed on IE 6.x (or maybe 7.x if my company ever decides to
shoot itself in the foot) and because this is being deployed as a
replacement for a pre-existing structure, it will not be running on a
web-server either (they will be the xml files sitting on a shared
drive accessed by everyone.

I need a way to format text within elements that is as simple for the
person typing the xml data as possible (if the stylesheet is
complicated, that's ok I'm the only one that will be looking at that
and code doesn't scare me). The simplest coding method I've seen so
far to put in formatting is html tags, however xml does not properly
escape those. I only need the <b><u><i> tags to work. Does anyone have
any ideas for an xsl stylesheet that will properly display this
element?

<element><i>This</i> is an <b>amazing</b> <u>element</u>!!</element>
 
B

Bjoern Hoehrmann

* (e-mail address removed) wrote in comp.text.xml:
I need a way to format text within elements that is as simple for the
person typing the xml data as possible (if the stylesheet is
complicated, that's ok I'm the only one that will be looking at that
and code doesn't scare me). The simplest coding method I've seen so
far to put in formatting is html tags, however xml does not properly
escape those. I only need the <b><u><i> tags to work. Does anyone have
any ideas for an xsl stylesheet that will properly display this
element?

<element><i>This</i> is an <b>amazing</b> <u>element</u>!!</element>

I am not sure why escaping might be a problem here. Transforming the
above into HTML should be trivial, you just copy the elements into the
result (using xsl:copy, xsl:copy-of, or some other method).
 
J

Joseph Kesselman

I am not sure why escaping might be a problem here. Transforming the
above into HTML should be trivial, you just copy the elements into the
result (using xsl:copy, xsl:copy-of, or some other method).

Exactly. If you want markup, use markup expressed in XML structure.
Personally I would prefer something more semantically meaningful than
fragments of XHTML (or concepts borrowed from XHTML), but XHTML would
have the advantage of being trivial to process and not requiring that
you educate the user about your own markup.
 
D

doulos05

Exactly. If you want markup, use markup expressed in XML structure.
Personally I would prefer something more semantically meaningful than
fragments of XHTML (or concepts borrowed from XHTML), but XHTML would
have the advantage of being trivial to process and not requiring that
you educate the user about your own markup.

Ok, I think I see what I'm doing wrong. I've been using xsl:value-of
select! I just tested it with xsl:copy-of and that fixed it. Thank
you, I've spent the last 3 days tearing my hair out looking for an
answer that was right in front of me.
 
D

doulos05

Ok, I'm not sure why, but suddenly that stopped working. All of my
xsl:copy-of selections quit making markup. Now, when I view my
documents, I get <b>this</b>, instead of formatted text. So, I poked
around and I found this transform which, when coupled with an
xsl:apply-templates command, should create the appropriate tags, but
it isn't working either. Here is the aforementioned code:

<xsl:template match="vendor">
<p><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="b|i|u">
<xsl:element name="{name()}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>

So what should happen is when it finds one with vendor, it should
apply templates, match all the <b>, <i>, and <u> tags, and create the
appropriate html tag. Instead, it is just passing them through as
text, so that I get this:

This vendor is <b>really</b> reliable.

Quick note on implimentation. The xml documents are stored on a shared
drive and accessed using Internet Explorer 6.0 (all computers in the
company have the same version of IE). The transforms are applied
dynamically using javascript calls in a shell html document. Currently
the code is being maintained in notepad and the office workers are
editing it in Word 2003, although plans are in the works to get a real
XML editor.
 
J

Joseph Kesselman

XSLT is namespace-sensitive. Check for namespaces, including a default
namespace declaration, in the source document.
 
D

Doulos05

XSLT is namespace-sensitive. Check for namespaces, including a default
namespace declaration, in the source document.

I tried it with and without namespace declarations in the xsl
document. Didn't seem to make a difference. The default namespace for
functions is supposed to be fn: but neither fn:name nor name produced
any results. Regardless of whether I declared the namespace or not.
 
P

p.lepin

I tried it with and without namespace declarations in the
xsl document. Didn't seem to make a difference. The
default namespace for functions is supposed to be fn: but
neither fn:name nor name produced any results. Regardless
of whether I declared the namespace or not.

Aw, shucks. I would like to help, but you see, my crystal
ball is malfunctioning at the moment.

(Does the phrase 'minimal complete example' ring any bells
with you?)
 
D

Doulos05

Aw, shucks. I would like to help, but you see, my crystal
ball is malfunctioning at the moment.

(Does the phrase 'minimal complete example' ring any bells
with you?)

My apologies, Pavel. I know a great crystal ball technician who may be
able to fix it for you, but in the interim I will copy the xml and xsl
documents. I was pressed for time when I posted the previous message
and did not have time to edit one of our account info documents to
remove the private information. Here is the XML document, named
"account info.xml" I stripped it down to the minimum necessary to
cause the problem:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="n:/Call Center Info/Call Center
All Accounts/Launchpad3_0/stylesheets/acctinfonormal.xsl"?>

<account>
<account_name>International Widget Factory</account_name>
<moddate>2007-04-11</moddate>
<greeting>Thank you for calling, this is _____ How may I help you?</
greeting>

<our_email>
<email>[email protected]</email>
<email_info><u>Do not give to customer.</u> This email is us to report
problems to Tier 2.</email_info>
</our_email>

<contacts>
<contact>
<contact_name>Terry</contact_name>
<contact_phone>123-456-7890</contact_phone>
<contact_email>[email protected]</contact_email>
<contact_description>Our on-site representative</contact_description>
</contact>
</contacts>

<warehouse_contacts>
<contact>
<contact_name><b>M54: </b> Heather</contact_name>
<contact_phone>123-451-1247</contact_phone>
<contact_email>[email protected]</contact_email>
<contact_description>Call for expediting, cancellation, etc.</
contact_description>
</contact>
</warehouse_contacts>

<buscard_contacts>
<contact>
<contact_name>Mike</contact_name>
<contact_phone>789-456-1470</contact_phone>
<contact_email>[email protected]</contact_email>
<contact_description><i>Do not give to customer.</i> Vendor has
requested that we not release this to the customer.</
contact_description>
</contact>
</buscard_contacts>

<rga>$40 restocking fee.</rga>

<miscs>
<misc>International Widget Factory occasionally requests foreign
deliveries. These are handled by Tier 2. Should you get a phone call
about a foreign delivery, contact Tier 2, they have the information.
The information <b>will not</b> be in the system because it cannot
handle international addresses.</misc>
</miscs>

</account>

Below is acctinfonormal.xsl:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:eek:utput method="html"/>
<xsl:template match="/">
<html>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="account_name">
<h1><xsl:apply-templates/></h1>
</xsl:template>

<xsl:template match="moddate">
<h3><xsl:apply-templates/></h3>
</xsl:template>

<xsl:template match="greeting">
<p><b>Standard Greeting: </b><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="our_email">
<p><b>Standard Register Email: </b><a href="mailto:{/account/
our_email/email}"><xsl:value-of select="/account/our_email/email"/></
a> - <xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="contacts">
<h2>Standard Register Contacts</h2>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="contact">
<p><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="contact_name">
<b>Name: </b><xsl:apply-templates/><br />
</xsl:template>

<xsl:template match="contact_phone">
<b>Phone: </b><xsl:apply-templates/><br />
</xsl:template>

</xsl:template>

<xsl:template match="contact_description">
<b>Info: </b><xsl:apply-templates/>
</xsl:template>

<xsl:template match="warehouse_contacts">
<h2>Warehouse, POD, and Plant Contacts <span style="font-size:
12pt">(for order status, expediting, and canceling)</span></h2>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="buscard_contacts">
<h2>Business Card and Stationary Contacts:</h2>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="miscs">
<h2>Miscellaneous Information</h2>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="misc">
<p><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="b|i|u">
<xsl:element name="{name()}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>

</xsl:stylesheet>

This is my latest revision attempting to get the <b>, <u>, and <i>
tags to transform into html b,u, and i tags. Previously, I had used
<xsl:copy-of select="node_name"/> and that was working fine until a
few days ago. Not sure what change caused the problems (this is a
fairly rapidly evolving project), but right now they are coming
through like so:

International Widget Factory occasionally requests foreign deliveries.
These are handled by Tier 2. Should you get a phone call about a
foreign delivery, contact Tier 2, they have the information. The
information <b>will not</b> be in the system because it cannot handle
international addresses.

Any assistance would be greatly appreciated. Thank you!
 
P

p.lepin

This is my latest revision attempting to get the <b>,
<u>, and <i> tags to transform into html b,u, and i tags.
Previously, I had used <xsl:copy-of select="node_name"/>
and that was working fine until a few days ago. Not sure
what change caused the problems (this is a fairly rapidly
evolving project), but right now they are coming through
like so:

[looks like disable-output-escaping or something]

I'm unable to reproduce your problem in Firefox 2.0.0.3
using the sample documents provided. The transformation
result looks just peachy to me and renders just fine as
well. None of my stand-alone transformation processors
exhibited the behavior you seem to have described.

Either your XSLT processor is just a bit borken, or you
were tinkering with it and inadvertently broke it. I don't
see any other explanation at the moment.
 
D

Doulos05

[looks like disable-output-escaping or something]

I'm unable to reproduce your problem in Firefox 2.0.0.3
using the sample documents provided. The transformation
result looks just peachy to me and renders just fine as
well. None of my stand-alone transformation processors
exhibited the behavior you seem to have described.

Either your XSLT processor is just a bit borken, or you
were tinkering with it and inadvertently broke it. I don't
see any other explanation at the moment.

Ok, thanks for the help. I'll look back over the code again, step
through it and see if I missed something when I snipped it down to fit
it more readily into the post. Also, is there any chance this could be
a "feature" of Internet Explorer's built-in XSLT processor? I know
I've heard that there were some portions of the old XSLT processor
that IE used that weren't W3C compliant, but I haven't seen whether or
not they fixed it. I've got Firefox at home as well, I'll send myself
the files and test it there to see if that's the case. I'll post what
I find when I get back from lunch.

Jonathan Bennett
 
P

p.lepin

[looks like disable-output-escaping or something]
I'm unable to reproduce your problem in Firefox 2.0.0.3
using the sample documents provided. The transformation
result looks just peachy to me and renders just fine as
well. None of my stand-alone transformation processors
exhibited the behavior you seem to have described.
Either your XSLT processor is just a bit borken, or you
were tinkering with it and inadvertently broke it. I
don't see any other explanation at the moment.

Ok, thanks for the help. I'll look back over the code
again, step through it and see if I missed something when
I snipped it down to fit it more readily into the post.

Works just fine for me in IE6 as well. The problem is not
with your code, but with your XSLT processor and/or with
whatever you use to invoke the processor in question.
Also, is there any chance this could be a "feature" of
Internet Explorer's built-in XSLT processor?

It has little to do with IE per se, and everything to do
with MSXML. Anyway, I wouldn't put it past Microsoft to
break something and say it's better that way, but I
consider it unlikely in this case. You might want to try
upgrading your MSXML in either case. microsoft.public.xsl
probably has a more thriving population of experts on
MSXML's transformation engine and is ===> that way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top