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

Re: remove tags + CDATA tag out of big xml file

Subject: Re: remove tags + CDATA tag out of big xml file
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 29 Jan 2010 14:38:28 +0000
Re:  remove tags + CDATA tag out of big xml file
On 29/01/2010 11:02, bw wrote:
Hello,

I have a big xml feed out of my content management system that
includes wysiwyg html tags inside CDATA tags.

I am looking for a way to remove the CDATA and only get the text.
CURRENT:
<add>
    <doc>
       <some_title>My title</some_title>
          <content><![CDATA[
<p>The<strong>keyword</strong>  is nice to have but is not needed to
include in a solr feed</p><p><table cellspacing="2" cellpadding="2"
border="1" width="100%"><tbody><tr><td>&#201;tape 1&nbsp;:</td></tr>
]]></content>
    </doc>
    <doc>
       ....
    </doc>
</add>

WANTED:
<add>
    <doc>
       <some_title>My title</some_title>
          <content>The keyword is nice to have but is not needed to
include in a solr feed</content>
    </doc>
    <doc>
       ....
    </doc>
</add>

Cheers


XSLT has no access to any tags in the input file, they are all resolved by an XML parser before XSLT sees the input.


So your input is


<content>
&lt;p>The&lt;strong>keyword&lt;/strong> is nice to have but is not needed to
include in a solr feed&lt;/p>&lt;p>&lt;table cellspacing="2" cellpadding="2"
border="1" width="100%">&lt;tbody>&lt;tr>&lt;td>&#201;tape 1&nbsp;:&lt;/td>&lt;/tr>
</content>



The best way to get from such a string to an XML element tree is to parse the string. saxon and some other systems havve extensions to do that


<xsl:copy-of seelct="saxon:parse(content)"/>

for example.

Otherwise as a deprecated and non portable alternative you may be able to get away with

<xsl:value-of disable-output-escaping="yes" select="content"/>

which doesn't create the element nodes, but just makes the appearance of them in the serialised reult.


david




________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________


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.