RE: [xsl] Xml file in an Xml file

Subject: RE: [xsl] Xml file in an Xml file
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 4 Apr 2007 17:19:47 +0100
You need to extract the embedded XML document as text and parse it. With
Saxon you can do this using saxon:parse(). With other processors you may be
able to call an extension function.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Danny Leblanc [mailto:leblancd@xxxxxxxxxxxxxxxxxxx] 
> Sent: 04 April 2007 17:07
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Xml file in an Xml file
> 
> 
> Hello everyone.
> 
>   Using web services I am getting the following XML file 
> returned to me.
> 
> <S:Envelope
> 	xmlns:S="http://schemas.xmlsoap.org/soap/envelope/";
> 	xmlns:XS="http://www.w3.org/2001/XMLSchema";
> 	xmlns:XI="http://www.w3.org/2001/XMLSchema-instance";
> 	
> xmlns:a="http://www.webserviceX.NET";><S:Body><a:GetWeatherResp
> onse><a:GetWeatherResult XI:type="XS:string">&lt;?xml 
> version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt; 
> &lt;CurrentWeather&gt;
>   &lt;Location&gt;Montreal / Pierre Elliot Trudeau 
> International Airport, Que, Canada (CYUL) 45-28N 073-45W 
> 36M&lt;/Location&gt;
>   &lt;Time&gt;Apr 04, 2007 - 11:00 AM EDT / 2007.04.04 1500 
> UTC&lt;/Time&gt;
>   &lt;Wind&gt; from the ESE (120 degrees) at 15 MPH (13 KT) 
> gusting to 28 MPH (24 KT):0&lt;/Wind&gt;
>   &lt;Visibility&gt; 6 mile(s):0&lt;/Visibility&gt;
>   &lt;SkyConditions&gt; overcast&lt;/SkyConditions&gt;
>   &lt;Temperature&gt; 37 F (3 C)&lt;/Temperature&gt;
>   &lt;DewPoint&gt; 33 F (1 C)&lt;/DewPoint&gt;
>   &lt;RelativeHumidity&gt; 86%&lt;/RelativeHumidity&gt;
>   &lt;Pressure&gt; 29.79 in. Hg (1008 hPa)&lt;/Pressure&gt;
>   &lt;Status&gt;Success&lt;/Status&gt;
> &lt;/CurrentWeather&gt;</a:GetWeatherResult></a:GetWeatherResp
> onse></S:Body></S:Envelope>
> 
>   What I would like to do is "yank out" the second Xml file 
> that is contained at 
> S:Envelope/S:body/a:GetWeatherResponse/a:GetWeatherResult. 
> 
>   I tried the following Xslt code using the latest Altova engine
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="2.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
> xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"; 
> xmlns:XS="http://www.w3.org/2001/XMLSchema"; 
> xmlns:XI="http://www.w3.org/2001/XMLSchema-instance"; 
> xmlns:a="http://www.webserviceX.NET";>
> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
>  
>   <xsl:template match="/">
>     <NewRoot>
>       <xsl:value-of 
> select="/S:Envelope/S:Body/a:GetWeatherResponse/a:GetWeatherResult"/>
>     </NewRoot>
>   </xsl:template>
>  
>   <xsl:template match="@*|node()">
>     <xsl:copy>
>       <xsl:apply-templates select="@*|node()"/>
>     </xsl:copy>
>   </xsl:template>
>  
> </xsl:stylesheet>
> 
>   What I get back is 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <NewRoot xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"; 
> xmlns:XI="http://www.w3.org/2001/XMLSchema-instance"; 
> xmlns:XS="http://www.w3.org/2001/XMLSchema"; 
> xmlns:a="http://www.webserviceX.NET";>&lt;?xml version="1.0" 
> encoding="utf-16"?&gt; &lt;CurrentWeather&gt;
>   &lt;Location&gt;Montreal / Pierre Elliot Trudeau 
> International Airport, Que, Canada (CYUL) 45-28N 073-45W 
> 36M&lt;/Location&gt;
>   &lt;Time&gt;Apr 04, 2007 - 11:00 AM EDT / 2007.04.04 1500 
> UTC&lt;/Time&gt;
>   &lt;Wind&gt; from the ESE (120 degrees) at 15 MPH (13 KT) 
> gusting to 28 MPH (24 KT):0&lt;/Wind&gt;
>   &lt;Visibility&gt; 6 mile(s):0&lt;/Visibility&gt;
>   &lt;SkyConditions&gt; overcast&lt;/SkyConditions&gt;
>   &lt;Temperature&gt; 37 F (3 C)&lt;/Temperature&gt;
>   &lt;DewPoint&gt; 33 F (1 C)&lt;/DewPoint&gt;
>   &lt;RelativeHumidity&gt; 86%&lt;/RelativeHumidity&gt;
>   &lt;Pressure&gt; 29.79 in. Hg (1008 hPa)&lt;/Pressure&gt;
>   &lt;Status&gt;Success&lt;/Status&gt;
> &lt;/CurrentWeather&gt;</NewRoot>
> 
>   What I would actually like to be returned is a true XML 
> file where I could access all the nodes using Xpath, not a 
> "parsed out" version of the file. 
> 
>   For example
> 
>   <?xml version="1.0" encoding="utf-8" ?>
>   <NewRoot>
>   <CurrentWeather>
>   <Location>Montreal / Pierre Elliot Trudeau International 
> Airport, Que, Canada (CYUL) 45-28N 073-45W 36M</Location>
>   <Time>Apr 04, 2007 - 11:00 AM EDT / 2007.04.04 1500 UTC</Time>
>   <Wind>from the ESE (120 degrees) at 15 MPH (13 KT) gusting 
> to 28 MPH (24 KT):0</Wind>
>   <Visibility>6 mile(s):0</Visibility>
>   <SkyConditions>overcast</SkyConditions>
>   <Temperature>37 F (3 C)</Temperature>
>   <DewPoint>33 F (1 C)</DewPoint>
>   <RelativeHumidity>86%</RelativeHumidity>
>   <Pressure>29.79 in. Hg (1008 hPa)</Pressure>
>   <Status>Success</Status>
>   </CurrentWeather>
>   </NewRoot>
> 
>   There are a few differences that I would also like, I don't 
> need the namespace declarations. Is there anyway to do this 
> using xslt or am I dreaming?
> 
> Thanks in advance.

Current Thread