xsl-list
[Top] [All Lists]

Re: [xsl] Removing namespaces without escaping CDATA???

2007-04-09 10:33:47
I shall try to explain my point of view..

Let's say we have following XML:
<x>
 <y></y>
 <p>
   <y></y>
   <q>
      <y></y>
   </q>
 </p>
</x>
(text content can be placed anywhere as desired)

If I do, <xsl:output cdata-section-elements="y" />, then all y
elements will contain CDATA sections. This may be desirable in very
specific cases. But it will be more convenient, if I am able to put
CDATA section at this location /x/p/q/y, and not to any other y's.

Can we achieve this (in 1.0 or 2.0)?

On 4/9/07, Abel Braaksma <abel(_dot_)online(_at_)xs4all(_dot_)nl> wrote:
>> Also, specifying cdata-section-elements here, <xsl:output
>> cdata-section-elements="qnames" /> seem to have a shortcoming, that
>> it's too global (as I said earlier). Do you agree to this point?

You can 'annotate' the result tree in XSLT 2.0, though possibly not as
conveniently as Mukul Gandhi requests. The attribute
'cdata-section-elements' is an AVT in the xsl:result-document element
and it must result in one or more qnames. But this requires redesigning
your stylesheets in such a way that you use xsl:result-document, instead
of xsl:output (but that should not be too hard if it is 'global'). This:

<xsl:variable name="my-cdata" select="'as-cdata'" />
<xsl:result-document cdata-section-elements="{$my-cdata}"
href="analyze.xml">
  <as-cdata>
      <xsl:text>Has some text</xsl:text>
      <not-cdata />
  </as-cdata>
  <as-cdata>Less then is: &lt;, ampersand is: &amp;</as-cdata>
</xsl:result-document>


results in the following output (Saxon 8.9):

<as-cdata><![CDATA[Has some text]]><not-cdata/>
</as-cdata>
<as-cdata><![CDATA[Less then is: <, ampersand is: &]]></as-cdata>


You have all freedom, the only drawback compared to your d-o-e-like
approach is that you will have to determine the contents of the AVT
beforehand, instead of per element. But as Michael and David already
pointed out, would you really want to do this?

Cheers,
-- Abel

PS: it is probably better to declare $my-cdata as 'xs:Qname' or 'xs:Qname*'.


--
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--