473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">

<xsl:output 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 <vi*****@vinc17.org> - 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
Jun 16 '06 #1
7 5421
* 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 · 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/
Jun 17 '06 #2
In article <hf********************************@hive.bjoern.ho ehrmann.de>,
Bjoern Hoehrmann <bj****@hoehrmann.de> 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 <vi*****@vinc17.org> - 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
Jun 17 '06 #3
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 xsl:output 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
Jun 21 '06 #4
* 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 xsl:output directive.


That would not work here as the CDATA section delimiters have to be
surrounded by /* ... */ comment delimiters.
--
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/
Jun 21 '06 #5
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.

Jun 21 '06 #6
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
Jun 22 '06 #7

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.

Jun 22 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Vincent Lefevre | last post by:
I would like to know if the base URI considered to resolve an unparsed entity defined by a relative URI should be the URI before or after its rewriting due to a possible catalog. Let's take an...
1
by: H. Kaya | last post by:
Hallo, I have a problem converting a XML file to a other. I have no idea how I can do this. I try it for a long time but I can not find a solution. Has anyone a Idea? Below you can find my...
5
by: Marcel Akkerman | last post by:
Hi, Does anyone have a clue how to reduce the number of nodes using XSLT? When outputing all nodes in order I could just use <xsl:for-each select="name"> But what if I, besides sorting and...
3
by: J Trost | last post by:
I was wondering if anyone knows if it is possible to do basic string replacement using XSLT even though the strings being replaced may contain "<" and ">". Here is my problem: I need to be able...
8
by: Kathleen Dollard | last post by:
Hi, Oleg's answer about attribute value templates led me to look back at a different problem, and wonder if someone else had solved it. I want to output an ASP.NET page. Thus I need to output...
4
by: Gauthier | last post by:
Hi, I've a simple issue with the use of extension objects. I'm trying to call a text formating method from an object that I add to my arguments collection, this method take an input string and...
4
by: schneider | last post by:
Anyone know if there is a way to dynamicly create a Xslt template/s and use them as an xml transform with-out use files for the Xslt? All the methods I see use files. I want to create a Xslt...
3
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about...
1
by: tconti | last post by:
Howdy: I have 2 general questions regarding the use of XSLT to generate emails. We have several procecesses that use XSLT to generate emails. We frequently run into issues where a client...
4
by: GoguLKS | last post by:
Hi, I am trying to manipulate a XSLT variable. Manipulating is replacing the string value in it. My XML file looks like: <root> <item name="PageTitle"> <value>Screen Page<value/>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.