473,320 Members | 2,117 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,320 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 5416
* 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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.