473,624 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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:styleshe et 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 5449
* 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****@h oehrmann.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.bjoe rn.hoehrmann.de >,
Bjoern Hoehrmann <bj****@hoehrma nn.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****@h oehrmann.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
2825
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 example. Here's my XML file: <?xml version="1.0"?> <!DOCTYPE para PUBLIC "-//Norman Walsh//DTD Website Full V2.4.0//EN" "http://docbook.sourceforge.net/release/website/2.4.0/website-full.dtd"
1
2192
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 Input XML Document, Output XML Document and my scratch XSLT file. At the end is my request Output XML. Greetings H. Kaya
5
3550
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 grouping, I also output conditionally? <xsl:for-each
3
5696
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 to convert XML like this: <?xml version="1.0" encoding="UTF-8"?> <java version="1.4.2_03" class="java.beans.XMLDecoder"> <object class="javax.swing.JButton"> <string>Hello, world</string>
8
6008
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 ASP.NET tags and HTML tags. <%@ Page Language= etc...
4
1974
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 output the formatted string. So far everything process correctly (the method is called without any issue) but my problem is that the output is htmlencoded, it means that my method (wich work as intended in other contexts) is called but the...
4
4817
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 transform via code? Any examples would be great.
3
2192
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 the development environment or recommend me some other that you know. XML IDE's - http://xslt-process.sourceforge.net - http://www.mentattech.com/themes/mentat/alchemist/index.html Regards,
1
1757
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 complains that they cannot traverse hrefs in the emails. When er acquire the culprit email it appears that their reader is not handling the HTML encoded values (i.e. &amp;) properly. Is this a problem only with older readers (i.e. old version of Lotus...
4
2723
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/> </item> <item name="PageHeader">
0
8231
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8168
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8672
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8330
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7153
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4075
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1474
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.