[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: escaping from CDATA

Subject: Re: escaping from CDATA
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 26 Oct 2001 10:30:42 +0100
javascript strings cdata
Hi Steve,

> Question 1:
> You are using java - is there a way to do this in javascript
> in IE6? I am write javascript in the following context:

> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
>                 xmlns:user="http://mycompany.com/mynamespace"
>                 version="1.0">
>
> <msxsl:script language="javascript" implements-prefix="user">
>   <![CDATA[
>    function Fun(arg) {
>
>    }
>   ]]>
> </msxsl:script>
>
> <xsl:template ...>
>   <xsl:value-of select="user:Fun($arg)"/>
> </xsl:template>
>
> </xsl:stylesheet>

Yes. Create a Document object and use the loadXML() method to parse
the XML string into a document. Return the Document object from the
function (this turns into a node set containing a single root node in
XPath terms). Then you probably want to *copy* that Document with
xsl:copy-of rather than get its value with xsl:value-of.

If the XML string isn't a well-formed XML document (e.g. it's got more
than one 'document element') then you can wrap a start tag and end tag
around it using JavaScript string manipulation.

> Question 2:
> I originally said the text was wrapped in CDATA:
>
>    <![CDATA[<element attr="100"><a>100</a><b>200</b></element>]]>
>
> Would it make any difference if the string was not wrapped in CDATA
> but just had the angle brackets represented as entities (which is
> the actual case):
>
>   &lt;element attr=&quot;100&quot;&gt; ... &lt;/element&gt;

No, none at all. An XSLT processor sees the two versions as being
exactly the same string.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.