[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Getting useful data from this XML

Subject: RE: Getting useful data from this XML
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 27 Apr 2005 11:02:11 +0100
merseyrail
They call this an XML feed?

I struggled with this at first, until I realized that they have not only
committed the crime of escaping the nested markup so that < is written as
&lt;, they have actually double-escaped it so that it is written as &amp;lt;
This must be the most perverse XML document I have seen for a long time.
Using disable-output-escaping will compensate for a single level of
unnecessary escaping in the input, but it won't compensate for two levels. 

If your project allows you to use Saxon, I would suggest

        <p>1) <xsl:value-of select="saxon:parse(concat('&lt;d&gt;',
@description, '&lt;/d&gt;'))"
                              disable-output-escaping="yes"
xmlns:saxon="http://saxon.sf.net/"/></p>

which does the trick. Horrible input sometimes demands a horrible
stylesheet.

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

> -----Original Message-----
> From: G.Wenden@xxxxxxxxxxxxxxx [mailto:G.Wenden@xxxxxxxxxxxxxxx] 
> Sent: 27 April 2005 10:15
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Getting useful data from this XML
> 
> I'm trying to write an xsl that will allow me to show whether 
> there are any problems on our local rail lines. The train 
> company provide an XML feed but I'm having trouble getting 
> any useful data out of it.
> I've tried a couple of different approaches but the data that 
> comes out has HTML tags that are displayed rather than used.
> 
> Thanks,
> 
> Greg
>  
> Here is an example XML file
>  
> <?xml version="1.0" encoding="iso-8859-1" ?> <?xml-stylesheet 
> type="text/xsl" href="new.xsl"?>
> <!--
> Number of disruption/incidents : 'num_incidents' attrbute.
> Where there are no disruptions, we recommend that you simply 
> state: 'Services running normally.'
> -->
> <!DOCTYPE merseyrail [
> <!ELEMENT merseyrail (incident?)>
> <!ATTLIST merseyrail num_incidents CDATA "0"> <!ELEMENT 
> incident (EMPTY)> <!ATTLIST incident description CDATA 
> #IMPLIED> <!ATTLIST incident details_url CDATA #IMPLIED> ]> 
> <merseyrail num_incidents='1'> <incident description="09.15 
> &amp;lt;B&amp;gt;Chester&amp;lt;/B&amp;gt; to 
> &amp;lt;B&amp;gt;Liverpool&amp;lt;/B&amp;gt; will start at 
> &amp;lt;B&amp;gt;Hooton&amp;lt;/B&amp;gt;." 
> details_url="&amp;lt;a 
> href=&amp;quot;http://www.merseyrail.org/travelling/?sSrc=&amp
> ;sGUID=59d620a61d0ba0dd29dc0c4cebefce81&amp;id=1647&amp;lt;/a&
> amp;gt;" /> </merseyrail>
> 
> And here is the xsl that I have written. 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
> <xsl:output method="html"/>
> 	<xsl:template match="/">
> 		<html>
> 			<head>
> 				<title>Merseyrail Service 
> Announcement</title>
> 			</head>
> 			<body>
>       <xsl:for-each select="merseyrail/incident">
>         <xsl:if test="position()=1">
>           <h1>Merseyrail services are NOT running normally.</h1>
>         </xsl:if>
> 
>         <p>1) <xsl:value-of select="@description" 
> disable-output-escaping="yes"/></p>
>         <p>2) <xsl:value-of select="@description" /></p>
>         <p>3) <xsl:value-of select="@details_url" 
> disable-output-escaping="yes"/></p>
>       </xsl:for-each>
>       
>       <xsl:for-each select="merseyrail[@num_incidents='0']">
>         <h1>Merseyrail services are running normally.</h1>
>       </xsl:for-each>
>       
>         <p> This information is taken from <a 
> href="http://www.merseyrail.org">www.merseyrail.org</a></p>
> 			</body>
> 		</html>
> 	</xsl:template>
> </xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.