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 February 16th, 2010, 06:19 AM
Authorized User
 
Join Date: Nov 2007
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default Transforming Using Escaped Characters

Hi all,

I have some input xml which is actually a large string with escaped characters, inside one xml tag, like so:

Code:
<a:ResponseXML>
&lt;?xml version="1.0" ?&gt;&lt;PolMessage Type="TransactionResponse" Version="1"&gt;&lt;TranResult&gt;
...
...
&lt;/PolMessage&gt; </a:ResponseXML>

I need to unescape the xml within ResponseXML and then transform it all to a totally different xml format, so need to be able to pick values out using xpath.

So far I have got my xsl stylesheet to return everything within ResponseXML with unescaped characters, however it is output as xml (with the xml header) under another xml header, like so:

Code:
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" ?><PolMessage Type="TransactionResponse" Version="1"><TranResult> ... ...
</PolMessage>


My stylesheet code is this:

Code:
<xsl:output method="xml" indent="yes" /> <xsl:strip-space elements="*" /> <xsl:template match="a:ResponseXML">
<xsl:value-of disable-output-escaping="yes" select="/*" />
</xsl:template>
I am just testing using the Orangevolt plugin for Eclipse - the transformer is set to "Default Transformer" (provided by Java Runtime) so I'm not sure what version of XSLT this is.

At this point, it outputs the whole unescaped xml - instead I want to be able to start extracting values from it using xpath and output the values within the different xml format.


Please could someone point me in the right direction as to how I can use this unescaped xml as if it is the input xml, so I can use xpath to navigate through the elements.


If you need any more info, let me know.

Many thanks in advance.
__________________
Neil Belch
Technical Officer
CDL

The views opinions and judgements expressed in this message are solely those of the author. The message contents have not been reviewed or approved by CDL.
 
Old February 16th, 2010, 06:42 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

What you need to do is to extract the contents of ResponseXML as a string, and then parse that string to create an XML tree of nodes, which you can then process using XPath.

Saxon provides an extension function saxon:parse() to perform this operation; it's not too difficult to write a similar extension function for other processors, but the logic depends on the XSLT processor you are using and on the facilities it provides for writing extension functions.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 17th, 2010, 07:29 AM
Authorized User
 
Join Date: Nov 2007
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thanks Michael, I have passed your suggestion on to a colleague here who'll extract and parse the escaped string outside of the transform.
__________________
Neil Belch
Technical Officer
CDL

The views opinions and judgements expressed in this message are solely those of the author. The message contents have not been reviewed or approved by CDL.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Escaped CDATA - outputting HTML mattisimo XSLT 8 February 3rd, 2010 11:01 AM
Remove First and Last Characters from String if it Contains Those Characters DoriftuEvo Excel VBA 9 September 22nd, 2009 09:01 AM
Exception when transforming using ksskumar XSLT 1 October 10th, 2006 02:33 AM
Retrieve the escaped node content carlos.bravo XSLT 4 September 16th, 2005 03:23 PM





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