xsl-list
[Top] [All Lists]

Getting useful data from this XML

2005-04-27 02:15:07
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[(_at_)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>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>