XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Chris ButlerSubject: how to print only cdata value/contents
Author: Chris Butler
Date: 26 Aug 2007 12:54 AM
Originally Posted: 25 Aug 2007 02:15 PM
Hi and thanks so much for this forum.

I am a web developer starting to get my feet wet re: xslt. I am working on a project which involves receiving a feed over which I have no control, formed like so:

<?xml version="1.0" encoding="utf-8"?>
<listings>
<listing>
<listingid>&lt;![CDATA[995155]]&gt;</listingid>
<otherlistingitems>&lt;![CDATA[BLAH]]&gt;</otherlistingitems>
</listing>
</listings>

... (copied from html source-not sure if the char entities are in the actual feed?) output to an html table via an xslt transformation accomplished via PHP's transformToURI():

http://dev.corcoranfeed.hypermediative.net/corcoranfeed/trans_corcoranfeed.php

I more or less have all the above working fine... my problem is that no matter what I do, "<![CDATA" and "]]>" are being printed in my table. I can find loads of info on how to transform to include these (are they known as?) tags, but nothing anywhere re: how NOT to print them... in fact, to all indications, they should simply be ignored in their output context. I have attached the xsl file, will be happy to supply any other code per your request.

Thanks again.

Best,
CDB


Documentcorcoranfeed.xsl
.xsl file for this issue

Postnext
Jamil TaylorSubject: how to print only cdata value/contents
Author: Jamil Taylor
Date: 26 Aug 2007 08:42 AM
Your XML contains the data that is appearing, so it's doing exactly what you are telling it to. If you want to remove the <![CDATA[ and ]]> from the text, you can do it two different ways depending on whether you're using XSLT 1.0 or 2.0.

If you're using 2.0, simply use nested replace functions:

replace(replace(/listings/listing/listingid,'&lt;!\[CDATA\[',''),'\]\]&gt;','')

If you're using 1.0, you will have to create templates that perform the replacement via recursion.

Postnext
Chris ButlerSubject: how to print only cdata value/contents
Author: Chris Butler
Date: 26 Aug 2007 12:40 PM
Jamil, thanks very much for your reply.

I am using 1.0-so far, I can't find anything on any string replacement functionality for 1.0-any possibility you could point me in the right direction?

Also, I think I am not understanding some fundamental things re: output... on this w3c pg:

http://www.w3.org/TR/xslt#misc-func

... re: xslt it says "The html output method should not perform escaping for the content of the script and style elements. For example, a literal result element written in the stylesheet as

<script>if (a &lt; b) foo()</script>

or

<script><![CDATA[if (a < b) foo()]]></script>

should be output as

<script>if (a < b) foo()</script>"

... I am using

<xsl:output method="html" encoding="utf-8" indent="no"/>

... which I understood should leave those CDATA brackets out of output... could I be overriding this behavior in my template?

I could just use PHP to replace but it seems like it would be better to figure it out on the xslt end of things...

Thanks again.

Posttop
Jamil TaylorSubject: how to print only cdata value/contents
Author: Jamil Taylor
Date: 26 Aug 2007 04:15 PM
The text from the page you referenced states 'script and style elements,' neither of which your text exists within. It does not apply to you.

Performing replacement of text in XSLT 1.0 is very common and should be easy to find examples of.

Good luck.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.