--- In [email protected], "run2bmi21"
<[EMAIL PROTECTED]> wrote:
>
> 
> I'm trying to generate SVG from an XML file using XSLT.  Most of the
> SVG boilerplate that I want the XSLT to add to the resulting SVG file
> is a JavaScript which *should* look something like this in the SVG
output:
> 
>     <script><![CDATA[
>     // JavaScript code here
>     ]]></script>

> Could
> xsl:cdata-section-elements be part of the answer?

Yes, you need to use that, here is a short and simple example, the
original SVG without script element is for example

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg";>
<circle cx="5" cy="20" r="10" fill="blue" />
</svg>

then the XSLT stylesheet that adds a script element could look like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0"
  xmlns:svg="http://www.w3.org/2000/svg";
  exclude-result-prefixes="svg">

<xsl:output
  method="xml"
  cdata-section-elements="svg:script" 
  media-type="image/svg+xml" />
  
<xsl:template match="svg:svg">
  <xsl:copy>
    <xsl:apply-templates select="@*" />
    <script xmlns="http://www.w3.org/2000/svg";
            type="text/ecmascript"><![CDATA[
      // just an example statement which would need to be escaped
      for (var i = 0; i < 1; i++) {}
    ]]></script>
    <xsl:apply-templates />
  </xsl:copy>
</xsl:template>

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()" />
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

An XSLT processor would then generate a result document like this:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg";><script
type="text/ecmascript"><![CDATA[
      // just an example statement which would need to be escaped
      for (var i = 0; i < 1; i++) {}
    ]]></script>
<circle cx="5" cy="20" r="10" fill="blue"/>
</svg>

Don't have xsltproc to test that but it should hopefully do that the
same as other XSLT processors.









-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
---- 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to