xml editor

Supported platforms

Compatible with Windows7 & Mac OS X Snow Leopard

Ready for data server software
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Problem with < and > in front and after CDATA section


Subject: Re: [xsl] Problem with < and > in front and after CDATA section
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Mon, 08 Dec 2008 12:17:09 +0100

jo lemen schrieb:

Is there a way in XSL 1.0 to fix the &lt; and &gt; in front of and
after the CDATA section?

<rss version="2.0">
<item>
<title>Title text</title>
<link>URL</link>
<description>&lt;![CDATA[description text]]&gt;</description>
<pubDate>pubDate</pubDate>
</item>

Isn't this simply a case of XML errouneously encoded as a string? The generator probably wanted a CDATA section, but not knowing how to do it inserted a text node, like this:

12:12:30,45 C:\MILU\dev\XSLT-1
# more cdata-unparsed.pl
use strict;
use warnings;
use XML::LibXML;

my $doc = XML::LibXML::Document->new;
my $root = $doc->createElement( 'Urmel');
$doc->setDocumentElement( $root);

my $text = 'Eene & meene <und> miste';

my $node1 = $doc->createElement('eins');
$node1->appendTextNode( "<![CDATA[$text]]>"); # wrong
$root->appendChild( $node1);

my $node2 = $doc->createElement('zwei');
$node2->appendChild( XML::LibXML::CDATASection->new( $text)); # right
$root->appendChild( $node2);

print $doc->serialize(1), "\n";


12:12:47,15 C:\MILU\dev\XSLT-1 # perl cdata-unparsed.pl <?xml version="1.0"?> <Urmel> <eins>&lt;![CDATA[Eene &amp; meene &lt;und&gt; miste]]&gt;</eins> <zwei><![CDATA[Eene & meene <und> miste]]></zwei> </Urmel>

Supposing this error is predictable and reliable, can't this be safely
undone using one simple d-o-e attribute for the element in question?

 <xsl:template match="description">
  <xsl:copy>
   <xsl:value-of select="." disable-output-escaping="yes"/>
  </xsl:copy>
 </xsl:template>

Michael Ludwig


Current Thread
Keywords
XML Editor | XML Author | WYSIWYG Editors | Schema Editor | XSD Documentation | XSL/XSLT Editor | XQuery | XML Databases | SVN Client
© 2002-2011 SyncRO Soft Ltd. All rights reserved. | Sitemap | Privacy Policy | This website was created & generated with <oXygen/>®XML Editor