473,582 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CDATA in an xsl transformation

Hello all,

I've a problem:

i've an xsl file that has a template that contains
the following:

<script type="text/javascript">
<![CDATA[

a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}

]]>>
</script>
Ok when this is transformed i get the following:

<script type="text/javascript">

a long javascript with &lt; &gt; characters, like:
for(var i=0;i&lt;xmlDat aFunctions.leng th;i++) {
}

</script>
But i dont want this, because javascript does not now &lt; and &gt;
So i used:

<script type="text/javascript"><xs l:text disable-output-escaping="yes"> <![CDATA[

a long javascript with &lt; &gt; characters, like:
for(var i=0;i&lt;xmlDat aFunctions.leng th;i++) {
}

]]></xsl:text></script>

Ok now i get:

<script type="text/javascript">

a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}

</script>

But because it is all part of an web-application i want to
get valid xhtml. This is not valid.So what i want is this as output:
<script type="text/javascript">
<![CDATA[

a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}

]]>
</script>

How do i do that with xslt??
Jul 20 '05 #1
8 12785
Tempore 18:12:59, die Friday 07 January 2005 AD, hinc in foro {comp.text.xml} scripsit Tjerk Wolterink <tj***@wolterin kwebdesign.com> :
But because it is all part of an web-application i want to
get valid xhtml. This is not valid.So what i want is this as output:
<script type="text/javascript">
<![CDATA[
a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}
]]>
</script>


Just specify 'cdata-section-elements' attribute

<xsl:output cdata-section-elements="scrip t" method="xml"/>
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
"Quot capita, tot sententiae" - Terentius , Phormio 454
Jul 20 '05 #2
Joris Gillis wrote:
Tempore 18:12:59, die Friday 07 January 2005 AD, hinc in foro
{comp.text.xml} scripsit Tjerk Wolterink <tj***@wolterin kwebdesign.com> :
But because it is all part of an web-application i want to
get valid xhtml. This is not valid.So what i want is this as output:
<script type="text/javascript">
<![CDATA[
a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}
]]>
</script>


Just specify 'cdata-section-elements' attribute

<xsl:output cdata-section-elements="scrip t" method="xml"/>
regards,


ok i understand, but now i want the output to be:
<script type="text/javascript">
//<![CDATA[
a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}
//]]>
</script>
Those // are javascript comments, these are neccesary because some old browsers
do support javascript but do not support xml, so i have to comment them out with //
..

How would you do that?
Jul 20 '05 #3
Tempore 11:05:57, die Saturday 08 January 2005 AD, hinc in foro {comp.text.xml} scripsit Tjerk Wolterink <tj***@wolterin kwebdesign.com> :
<script type="text/javascript">
//<![CDATA[
a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}
//]]>
</script>

Those // are javascript comments, these are neccesary because some old browsers
do support javascript but do not support xml, so i have to comment them out with //

How would you do that?


To the best of my knowledge, XSLT1.0 does not provide a way to create a CDATA section from only a part of a text node.

I'm not really convinced that there would ever be need of such output, but if you really need it and don't mind dirty hacks, you could use something like this:

<?xml version='1.0' encoding="UTF-8"?>
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

<xsl:template match="script">

<script type="text/javascript">
<![CDATA[
//<![CDATA[
a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}
//]]>
]]>
</script>

</xsl:template>

</xsl:stylesheet>
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Vincit omnia simplicitas
Keep it simple
Jul 20 '05 #4
> <script type="text/javascript">
//<![CDATA[
a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}
//]]>
</script>

How would you do that?


If the output type of your XSL is set to 'xml' (to produce xhtml) , I think this problem is literally unsolvable.

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Vincit omnia simplicitas
Keep it simple
Jul 20 '05 #5
Joris Gillis wrote:
<script type="text/javascript">
//<![CDATA[
a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}
//]]>
</script>

How would you do that?

If the output type of your XSL is set to 'xml' (to produce xhtml) , I
think this problem is literally unsolvable.


Thanks for your time, i already thought it was difficult to solve, but
i want both be xhtml-valid and cross-browser, those things collide.

On solution is to put the javascript in a separe js file and include it using <script src=""/>
But its a really page specific javascript so therefore i want to include it inline.

But anyways, thanks.
Jul 20 '05 #6
Tempore 11:49:41, die Saturday 08 January 2005 AD, hinc in foro {comp.text.xml} scripsit Joris Gillis <ro**@pandora.b e>:
<script type="text/javascript">
//<![CDATA[
a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}
//]]>
</script>

How would you do that?


If the output type of your XSL is set to 'xml' (to produce xhtml) , I think this problem is literally unsolvable.

Forget what I said, I was plain wrong...

This is a working - but rather ugly - solution:

<?xml version='1.0' encoding="UTF-8"?>
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"/>

<xsl:template match="/">
<script type="text/javascript">
<xsl:text disable-output-escaping="yes">
<![CDATA[
//<![CDATA[
a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}
//]]>
]]>
</xsl:text>
</script>
</xsl:template>

</xsl:stylesheet>

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Vincit omnia simplicitas
Keep it simple
Jul 20 '05 #7
In article <op************ **@news.pandora .be>,
"Joris Gillis" <ro**@pandora.b e> wrote:
To the best of my knowledge, XSLT1.0 does not provide a way to create a CDATA
section from only a part of a text node.

I'm not really convinced that there would ever be need of such output,


There is no need when the output is subjected to proper XML processing.

Producing XHTML with XSLT and serving it as text/html without a
specialized Appendix C converter is a bad idea. Using inline style
sheets or scripts in such a situation is an even worse idea.

--
Henri Sivonen
hs******@iki.fi
http://iki.fi/hsivonen/
Mozilla Web Author FAQ: http://mozilla.org/docs/web-developer/faq.html
Jul 20 '05 #8
Tjerk Wolterink wrote:
Hello all,

I've a problem:

i've an xsl file that has a template that contains
the following:

<script type="text/javascript">
<![CDATA[

a long javascript with < > characters, like:
for(var i=0;i<xmlDataFu nctions.length; i++) {
}

]]>>
</script>


FAQ.
http://www.ucc.ie/xml/#usecdata

///Peter
--
"The cat in the box is both a wave and a particle"
-- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
Jul 20 '05 #9

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

Similar topics

0
2079
by: Dimitre Novatchev | last post by:
You seem to be unaware of the xslt processing which uses the built-in rules in the absence of templates that match some selected node. http://www.w3.org/TR/xslt#built-in-rule According to the XSLT processing model: http://www.w3.org/TR/xslt#section-Processing-Model the root node will be processed by a built-in rule, because you do not
4
2249
by: troppfigo | last post by:
I have this example of xml <?xml version="1.0"?> <xml> <!]> </xml> I want to extract the contained data from <body> tag using an xslt transformation. I want to obtain this
10
2327
by: Simon Brooke | last post by:
Here's my problem: <xsl:template match="/category"> .... <script type="text/javascript"> &lt;!]&gt; </script> .... </xsl:template>
5
2204
by: Lals | last post by:
Hi, I am stuck in problem involving transformation where I want to put my source contents as itself in the target XML My input xml looks like <root> <State name = "abc"> mystate<sub1>xx</sub1> <p>This is description</p> </State>
7
3970
by: Max | last post by:
Hello everyone! Can anyone help me to convert the CDATA expression "CDATA ::= (Char* - (Char* ']]>' Char*)" to Javascript Regular Expression? Thanks, Max
1
4237
by: Dariusz Tomoñ | last post by:
Hi, I have got xml document with CDATA sections containing special characters like links to images. All Iwant is to display the content withing my div section. Can you provide me a snippet of a code. Thank you in advance. Darek T.
2
1619
by: andybdi | last post by:
I am playing with a few xml feeds changing them into different formats and merging them with others, and have found that when using cdata- section-elements salbatron adds an extra line break at the begining and end of the cdata tags. e.g. Inital code is <text>blah blah</text> This gets changed to
3
6369
by: satyajit123 | last post by:
HI All, I have a requirement which has an XML with CDATA content in it is to be passed through an XSL for transformation to HTML tags. The xml is of below format. <xml-service application="readernews" type="RESPONSE"> <services> <service name="getUserAndDLNames" response-type="JSON" status="SUCCESS"> <message>
6
4799
by: dkyadav80 | last post by:
Hi sir, I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all city values should display in city selection field and when user select any one city value then this state of this city should be display auto in state ...
0
7886
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...
0
7809
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...
0
8312
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6569
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...
1
5685
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
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...
0
3809
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...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1147
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...

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.