php - Using external XML uri with variables -


i searched here , on big g, willing learn, didn't found answer yet.

i trying transform external xml data xslt read in html or php. tested few things , transformed simple xml files xsl , php. problem actual xml files need use not typical dot xml files see, more format "http://webservices.nextbus.com/service/publicxmlfeed?command=vehiclelocations&a=sf-muni&r=14&t=0". when use these addresses, seems read these files , xsl stylesheet, parse correct numbers of table cells, return them empty.

what's wrong?

also, can related xml formatting used external site? noticed xml more "xhtml styled" rather other files seen in past.

their style using 1 big tag , closed slash:

<vehicle id="5464" routetag="14" dirtag="14_ib2" lat="37.7637" lon="-122.4087" secssincereport="86" predictable="true" heading="218" speedkmhr="0"/> 

the same example, if writting using usua tree:

<vehicle> <id>5464</id> <routetag>14</routetag> <dirtag>14_ib2</dirtag> ... </vehicle> 

route14.xsl:

    <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:template match="/">   <html>   <body>   <h2>route 14</h2>   <table border="1">     <tr bgcolor="#9acd32">       <th style="text-align:left">vehicle</th>       <th style="text-align:left">direction</th>     </tr>     <xsl:for-each select="body/vehicle">     <tr>       <td><xsl:value-of select="id" /></td>       <td><xsl:value-of select="dirtag" /></td>     </tr>     </xsl:for-each>   </table>   </body>   </html> </xsl:template>  </xsl:stylesheet>    

php code:

<?php // load xml file $xml = new domdocument; $xml->load('http://webservices.nextbus.com/service/publicxmlfeed?command=vehiclelocations&a=sf-muni&r=14&t=0');  // load xsl file $xsl = new domdocument; $xsl->load('route14.xsl');  // configure transformer $proc = new xsltprocessor;  // attach xsl rules $proc->importstylesheet($xsl);  echo $proc->transformtoxml($xml); ?>  

you on right path, when accessing attribute values, have prefix them @

change these lines

<tr>   <td><xsl:value-of select="id" /></td>   <td><xsl:value-of select="dirtag" /></td> </tr> 

to

<tr>   <td><xsl:value-of select="@id" /></td>   <td><xsl:value-of select="@dirtag" /></td> </tr> 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -