Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 8th, 2010, 09:49 AM
Registered User
 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default CDATA and XPATH XSLT v1

Hi all, I am in need of help and any help greatly received and appreciated.

I have a XML document

<?xml version="1.0" encoding="UTF-8"?>
<root>
<header>sometext</header>
<letter><![CDATA[<?xml version="1.0"?><root><book title="1234"</root>]]></letter>
</root>

I wish to read the CDATA book element into a node set using XSLT so I can then continue to use normal XPATH queries but I can not find a solution either through trial and error or by researching online.

Thank you all in advance for any help and suggestions
 
Old November 8th, 2010, 09:52 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well whether it is XSLT/XPath 1.0 or 2.0, the CDATA section results in a text node with plain text and there is no function to parse such text as XML, unless your XSLT processor provides an extension function to do that (or someone has written a parser in pure XSLT where David Carlisle has done that in XSLT 2.0)).
So which XSLT processor do you use?

Note also that "<root><book title="1234"</root>" is not well-formed (as the book tag is not closed) so even with an extension function parsing as XML is not possible.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog

Last edited by Martin Honnen; November 8th, 2010 at 10:20 AM.. Reason: adding hint about syntax problem in code sample
 
Old November 8th, 2010, 12:24 PM
Registered User
 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI Martin, thank you for your quick reply, this is as I suspected and feared, I am using the Java Xalan processor
 
Old November 8th, 2010, 01:02 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I don't see anything suitable on http://xml.apache.org/xalan-j/extensionslib.html. As you use Java you could switch to XSLT 2.0 with Saxon 9 and then either use the built-in extension function http://www.saxonica.com/documentatio...ions/parse.xml (only available in the open source 9.1 release or in the commercial 9.2/9.3 releases) or you could try http://code.google.com/p/web-xslt/so...runk/htmlparse which is a pure XSLT 2.0 implementation of an HTML parser but should be able to deal with XML as well.
If you want to stick with Xalan then consider to ask on the Xalan user mailing list for help in writing an extension function that takes a string of XML and returns a data type suitable to be used by Xalan as a node-set.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Xpath on an XML wrapped in CDATA akentanaka XSLT 4 March 11th, 2009 05:26 AM
how to strip out CDATA from xml with xslt XSLUSer XSLT 0 March 10th, 2009 11:47 PM
CDATA thorugh xpath expression vinod.kumbar RSS and Atom 1 July 11th, 2008 07:29 AM
CDATA Section using XSLT misanaka XSLT 2 March 29th, 2007 06:53 PM
Problem with the CData Section while using Xslt Vered XSLT 2 September 21st, 2006 11:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.