This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Javascript looping expression in stylesheet


Zoe, this is not "very strange". You should understand that this is
required by XML. That's why I referred you to the XML 1.0 specification.

It might help to see that XML does two main things: it defines a data
model and a serialization specification. The data model that XML defines
is a hierarchical tree of data. XML serialization specifies how data in
that data model can be written out to a file or byte stream. Using the <
symbol to start XML markup tags and the & symbol to escape special
characters are artifacts of XML serialization. When we write "& lt ;" or
"& amp ;"  (without the spaces) we are telling the XML parser that these
characters are not part of the XML markup, but literal characters.
Similarly, when we use a CDATA section it tells the XML parser to not
try to interpret anything between  <![CDATA[ and ]]> as XML. And XSLT
deals in the world of XML: XSLT is expressed in terms of XML, XSLT
transforms XML source data, and often XSLT produces XML results (or HTML
or text). Hope that makes it seem less strange.

The book "Essential XML" by Don Box, Aaron Skonnard and John Lam,
Addison-Wesley, 2001, is a good place to become acquainted with the
wonderful (and sometimes quirky) world of XML.

Cheers,
Stuart

-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of Zoe Peng
Sent: Wednesday, May 08, 2002 15:18
To: xsl-list@lists.mulberrytech.com
Subject: RE: [xsl] Javascript looping expression in stylesheet

Thank you guys. 
It ends up to use <![CDATA[]]> to make javascript work. 
very strange...It works in CSS, too. 

// those two are produced the same results. =)
<!-- load the css file -->
<xsl:processing-instruction name="xml-stylesheet">
<xsl:text>href="menu.css" type="text/css"</xsl:text>
</xsl:processing-instruction>
 
<!-- load the css file -->
<style type="text/css">
<![CDATA[
        .link
        {
        ...
        }
]]>
</style>


--Zoe

> XSLT is XML, and all XML needs to escape certain characters. According
> to the XML specification
> (http://www.w3.org/TR/2000/REC-xml-20001006#syntax), section 2.6,
> Character Data and Markup:
> 
> The ampersand character (&) and the left angle bracket (<) may appear 
in
> their literal form only when used as markup delimiters, or within a
> comment, a processing instruction, or a CDATA section. If they are
> needed elsewhere, they must be escaped using either numeric character
> references or the strings "& amp ;" and "& lt ;" respectively.
> 
> [NOTE: omit the space characters in the quotes - I've added those so
> that some email programs don't thing they are HTML and render them as
> characters!]
> 
> The reason for this is that ampersand and left angle bracket have
> special meaning to XML: they indicate escaped characters and the start
> of XML tags, respectively. Know your XML.
> 
> So if you've only got a few occurrences of these characters, you can 
use
> the & amp ; and & lt ; symbols, or you can place the contents of the
> text block in a CDATA section, such as this:
> 
> <xsl:text>
>   <![CDATA[My funky text that uses < and & all the time...]]>
> </xsl:text>
> 
> Cheers,
> Stuart
>

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]