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 March 11th, 2009, 01:42 AM
Authorized User
 
Join Date: Jun 2008
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using Xpath on an XML wrapped in CDATA

Hi,

I'm having difficulty extracting the value (75) in REQUEST_ID from below XML

<result>
<row>
<column label="MESSAGE_SEQ_ID" name="MESSAGE_SEQ_ID"><![CDATA[974]]></column>
<column label="MESSAGE_PROCESS_FLAG" name="MESSAGE_PROCESS_FLAG"><![CDATA[NEW]]></column>
<column label="SOAP_XML" name="SOAP_XML"><![CDATA[<result><row><column name="REQUEST_ID" label="REQUEST_ID">75</column></row></result>]]></column>
</row>
</result>

Is it possible to use XPATH directly to extract the information?

I thought of making another document to isolate SOAP_XML then use Xpath. But still I can't retrieve the data.


Thanks for the help.
 
Old March 11th, 2009, 02:15 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Try this:

Code:
 
<xsl:template match="result">
<xsl:apply-templates select="row"></xsl:apply-templates>
</xsl:template>

<xsl:template match="row">
<xsl:apply-templates select="column"></xsl:apply-templates>
</xsl:template>

<xsl:template match="column">
<xsl:variable name="col" select="."></xsl:variable>
<xsl:analyze-string select="$col" regex="&lt;column name=(.)REQUEST_ID(.) label=(.)REQUEST_ID(.)&gt;([0-9]+)&lt;/column&gt;">
<xsl:matching-substring>
<xsl:value-of select="regex-group(5)"></xsl:value-of>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>


There may be a better and easy solution than this.
__________________
Rummy
 
Old March 11th, 2009, 04:02 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Wrapping XML in CDATA, and therefore turning into text, is such a bad practice and defeats the object of markup.
One alternative to parsing it as text as mrame suggests is to use an extension function. Saxon for example has saxon:parse.
__________________
Joe
http://joe.fawcett.name/
 
Old March 11th, 2009, 04:46 AM
Authorized User
 
Join Date: Jun 2008
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So it's not possible to use XPATH directly.

Then I will use RegEx. :(

Thanks, mrame!

@joefawcett - I can't use saxon:parse. :(
 
Old March 11th, 2009, 05:26 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
Originally Posted by akentanaka View Post
So it's not possible to use XPATH directly.
No, because it's not XML, it's text.
Quote:
Then I will use RegEx. :(

Thanks, mrame!
Quote:
@joefawcett - I can't use saxon:parse. :(
Which XSLT processor are you using?
__________________
Joe
http://joe.fawcett.name/





Similar Threads
Thread Thread Starter Forum Replies Last Post
CDATA thorugh xpath expression vinod.kumbar RSS and Atom 1 July 11th, 2008 07:29 AM
SQL Server 2005 XML: FOR XML PATH -> cdata? stoves SQL Server 2005 1 July 8th, 2008 02:40 AM
Extract the XML file from CDATA haixia XSLT 2 August 3rd, 2006 02:01 PM
CDATA Set with For XML Explicit Yehuda SQL Server 2000 0 August 13th, 2003 01:50 PM
CDATA in XML - convert to HTML suri XSLT 1 July 31st, 2003 08:22 AM





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