469,938 Members | 2,492 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,938 developers. It's quick & easy.

html tags inside xml elements

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><itags to work. Does anyone have
any ideas for an xsl stylesheet that will properly display this
element?

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

Mar 30 '07 #1
11 11353
* do******@gmail.com 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><itags to work. Does anyone have
any ideas for an xsl stylesheet that will properly display this
element?

<element><i>This</iis 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).
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Mar 30 '07 #2
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.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Mar 30 '07 #3
On Mar 30, 9:31 am, Joseph Kesselman <keshlam-nos...@comcast.net>
wrote:
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.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
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.

Mar 30 '07 #4
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 <utags, 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</breliable.

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.

Apr 12 '07 #5
XSLT is namespace-sensitive. Check for namespaces, including a default
namespace declaration, in the source document.
Apr 12 '07 #6
On Apr 12, 6:00 pm, Joseph Kesselman <keshlam-nos...@comcast.net>
wrote:
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.

Apr 14 '07 #7
On Apr 14, 4:55 am, "Doulos05" <doulo...@gmail.comwrote:
On Apr 12, 6:00 pm, Joseph Kesselman
<keshlam-nos...@comcast.netwrote:
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.
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?)

--
Pavel Lepin

Apr 14 '07 #8
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?)

--
Pavel Lepin
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>jo******@company.com</email>
<email_info><u>Do not give to customer.</uThis 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>te***@company.com</contact_email>
<contact_description>Our on-site representative</contact_description>
</contact>
</contacts>

<warehouse_contacts>
<contact>
<contact_name><b>M54: </bHeather</contact_name>
<contact_phone>123-451-1247</contact_phone>
<contact_email>he*****@company.com</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>mi**@stationary.com</contact_email>
<contact_description><i>Do not give to customer.</iVendor 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</bbe 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:output method="html"/>
<xsl:template match="/">
<html>
<body>
<input type="button" value="Close this window" onclick="self.close()"/
>
<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 match="contact_email">
<b>Email: </b><a href="mailto:{.}"><xsl:value-of select="."/></a><br /
>
</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</bbe in the system because it cannot handle
international addresses.

Any assistance would be greatly appreciated. Thank you!
Apr 16 '07 #9

On Apr 16, 5:04 pm, "Doulos05" <doulo...@gmail.comwrote:
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?)

This is my latest revision attempting to get the <b>,
<u>, and <itags 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.

--
Pavel Lepin

Apr 16 '07 #10
On Apr 16, 10:46 am, p.le...@ctncorp.com wrote:
[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.

--
Pavel Lepin
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

Apr 16 '07 #11
On Apr 16, 7:20 pm, "Doulos05" <doulo...@gmail.comwrote:
On Apr 16, 10:46 am, p.le...@ctncorp.com wrote:
[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.

--
Pavel Lepin

Apr 17 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by sindre hiåsen | last post: by
3 posts views Thread by jjliu | last post: by
5 posts views Thread by Donald Firesmith | last post: by
2 posts views Thread by hoz | last post: by
3 posts views Thread by gaya3 | last post: by
17 posts views Thread by V S Rawat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.