Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > [XSLT] How to generate /*<![CDATA[*/ for XHTML style element?

Reply
Thread Tools

[XSLT] How to generate /*<![CDATA[*/ for XHTML style element?

 
 
Vincent Lefevre
Guest
Posts: n/a
 
      06-16-2006
I'd like to generate something like that:

<style type="text/css">/*<![CDATA[*/
body { }
*/]]></style>

I thought the following would work, but it doesn't (I tried with
xsltproc).

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">

<xslutput method="xml"
encoding="iso-8859-1"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
indent="yes"/>

<xsl:template match="/">
<html>
<head>
<title>.</title>
<style type="text/css">
<xsl:text disable-output-escaping="yes">/*&lt;![CDATA[*/
body { }
/*]]&gt;*/</xsl:text>
</style>
</head>
<body><p>.</p></body>
</html>
</xsl:template>

</xsl:stylesheet>

Any idea?

--
Vincent Lefèvre <> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA
 
Reply With Quote
 
 
 
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      06-17-2006
* Vincent Lefevre wrote in comp.text.xml:
>I'd like to generate something like that:
>
><style type="text/css">/*<![CDATA[*/
>body { }
>*/]]></style>


This construct is useful only if the stylesheet contains "]]>", "&", or
"<" and you want both HTML tag soup and XML processors to successfully
process the document; if that is ever the case you should use external
style sheets instead, or, if possible, escape the characters using
\hhhhhh escapes instead.
--
Björn Höhrmann · private.php?do=newpm&u= · 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/
 
Reply With Quote
 
 
 
 
Vincent Lefevre
Guest
Posts: n/a
 
      06-17-2006
In article < ehrmann.de>,
Bjoern Hoehrmann <> wrote:

> * Vincent Lefevre wrote in comp.text.xml:
> >I'd like to generate something like that:
> >
> ><style type="text/css">/*<![CDATA[*/
> >body { }
> >*/]]></style>


> This construct is useful only if the stylesheet contains "]]>", "&", or
> "<" and you want both HTML tag soup and XML processors to successfully
> process the document;


Or for better maintainability, e.g. if the styles are incomplete and
one wants to make sure not to forget to add this construct when the
styles get "&" or "<" characters in future modifications.

> if that is ever the case you should use external style sheets
> instead,


This is the best solution when the page is on a web server, but in
other cases, e.g. when one wants to distribute a HTML file by e-mail,
internal styles may be an easier solution.

> or, if possible, escape the characters using \hhhhhh escapes
> instead.


But this is less readable and also more prone to bugs when generating
styles from a programming language where \ is the escape character.

--
Vincent Lefèvre <> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      06-21-2006
You can tell XSLT that the text children of certain elements should be
escaped as CDATA Sections, via the cdata-section-elements attribute of
the xslutput directive.

I agree that this is generally something you should avoid, but if the
customer/boss insists on it...

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      06-21-2006
* Joe Kesselman wrote in comp.text.xml:
>You can tell XSLT that the text children of certain elements should be
>escaped as CDATA Sections, via the cdata-section-elements attribute of
>the xslutput directive.


That would not work here as the CDATA section delimiters have to be
surrounded by /* ... */ comment delimiters.
--
Björn Höhrmann · private.php?do=newpm&u= · 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/
 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      06-21-2006
Bjoern Hoehrmann wrote:

> That would not work here as the CDATA section delimiters have to be
> surrounded by /* ... */ comment delimiters.


Why does <style> have to be a CDATA section anyway? (ignoring the
bogosity of the /* <![CDATA[ ... ]]> */ construction)

<script> has some arguments for it, in some particular circumstances,
but <style> doesn't.

 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      06-22-2006
Bjoern Hoehrmann wrote:
> That would not work here as the CDATA section delimiters have to be
> surrounded by /* ... */ comment delimiters.


In that case, assembling it out of characters -- and outputting through
a path which suppresses normal XML escaping -- may indeed be the best
you can do. Or you can perform non-XML-based postprocessing to replace
the <![CDATA[]]> delimiters with their Javascript-commented-out equivalents.

The better answer remains: Don't Do That. The whole point of XHTML is
that it is XML-based, and that *should* mean you don't have to kluge
using <![CDATA[]]> and comments to make it accept scripts. If that isn't
true, beat up the browser authors until they fix their code.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      06-22-2006

Joe Kesselman wrote:

> The better answer remains: Don't Do That. The whole point of XHTML is
> that it is XML-based, and that *should* mean you don't have to kluge
> using <![CDATA[]]> and comments to make it accept scripts.


It's no an XHTML problem, it's a problem for appendix C XHTML which is
being fed to SGML parsers and expected to work transparently as
_either_ XML or SGML, from the same document. The addition of the
comment markers is a particularly obsessive case. Hixie is obsessed
with this, no-one else really cares.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
convert xhtml to another xhtml using xslt Usha2009 XML 0 12-20-2009 01:13 PM
Should I Convert Site To XHTML or XHTML mobile? chronos3d HTML 9 12-05-2006 04:46 PM
parse URL (href) from xhtml, xhtml -> text, for data hawat.thufir@gmail.com XML 7 02-08-2006 07:39 PM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM



Advertisments