Thank you, that works perfectly! I also found a workaround using "html" as the output method, which lets me create a CDATA section with syntax-specific comments, for example:

<script type="text/turtle">{concat('#<![CDATA[', $body, '#]]>')}</script>

(Following the W3C example for embedding Turtle in XHTML[1].)

Best regards,
Tim

[1] http://www.w3.org/TR/turtle/#xhtml

--
Tim A. Thompson
Metadata Librarian (Spanish/Portuguese Specialty)
Princeton University Library


On Mon, Jul 13, 2015 at 4:40 AM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Tim,

I must confess I haven't run your full example, but you'll probably
need to explicitly specify the namespace of your script element, as
shown in the following two function calls:

  file:write("result.xml",
    <xml xmlns="http://www.w3.org/1999/xhtml">
      <script> &lt; </script>
    </xml>,
    <output:serialization-parameters>
      <output:method
        value="xhtml"/>
      <output:cdata-section-elements
        value="Q{{http://www.w3.org/1999/xhtml}}script"/>
    </output:serialization-parameters>
  )

  file:write("result.xml",
    <xml xmlns="http://www.w3.org/1999/xhtml">
      <script> &lt; </script>
    </xml>,
    map {
      'cdata-section-elements':
      'Q{http://www.w3.org/1999/xhtml}script'
    }
  )

Otherwise, the CDATA section does only apply to the empty namespace:

  file:write("result.xml",
    <xml xmlns="http://www.w3.org/1999/xhtml">
      <script xmlns=""> &lt; </script>
    </xml>,
    map { 'cdata-section-elements': 'script' }
  )

Regarding your second question:

  (: Does this work? :)
  %output:cdata-section-elements("script")

Yes, that's indeed a valid way to specify serialization parameters.

Hope this helps,
Christian