[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Handling elements which is inside CDATA in input X

Subject: Re: Handling elements which is inside CDATA in input XML
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 01 Nov 2010 13:02:15 +0000
Re:  Handling elements which is inside CDATA in input X
On 01/11/2010 12:24, Ramkumar.V wrote:
Hi, Experts

I need to remove the span tag which is inside the CDATA in input XML. Could anyone suggest me how to handle CDATA in XSLT Transform for the below?

The first thing to understand is that <span> isn't a tag. It looks like a tag, but the CDATA section is there for the purpose (its only purpose) of saying "this may look like a tag but I want it treated as ordinary text". So if you want to treat it as a tag rather than as ordinary text, it's not surprising you have a problem.


The CDATA section means that the parser ignored this "tag" during the initial parsing, so what you need to do is to extract the text and parse it again (without the CDATA tags). You can often do this using an extension function, but it can't be done within the language. If the subset of XML you need to parse is simple enough, you can use a parser written in XSLT itself.

Michael Kay
Saxonica


Input XML:


==========

<?xml version="1.0" encoding="utf-8"?>

<quiz>

<question><![CDATA[<span class="question">1. Biochemistry is based on the chemistry of which element?</span>]]></question>

</quiz>
XSLT:

=====

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="quiz"><html><xsl:apply-templates/></html></xsl:template>
<xsl:template match="question">


<p><xsl:apply-templates/></p>

</xsl:template>
</xsl:stylesheet>

Current HTML Output

===================

<html>
<p>&lt;span class="question"&gt;1. Biochemistry is based on the chemistry of which element?&lt;/span&gt;</p>
</html>


Expected HTML Output:

=====================

<html>
<p>1. Biochemistry is based on the chemistry of which element?</p>

</html>

Regards,

Ram Kumar V.



===========================================================
***Disclaimer***


This email, and any attachments ("this email"), is confidential. If you are not the addressee please tell the sender immediately, and destroy this email without using, sending or storing it. Any opinions, express or implied, in this email, are those of the sender, and are not necessarily approved by the company. Except as expressly stated, this e-mail should not be regarded as an offer, solicitation, recommendation or agreement to buy or sell products or services, or to enter into any contract. E-mail transmissions are not secure and may suffer errors, viruses, delay, interception and amendment. The company does not accept liability for damage caused by any of the foregoing.


ALL INCOMING AND OUTGOING MAILS MAY BE MONITORED BY THE COMPANY.
============================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.