Jump to content

How to display data from XML feed in HTML?


pauljhester
 Share

Recommended Posts

I have spent quite a long time attempting to determine how to display various "elements" and "attributes" in HTML, but I have been having some issues. From what I have gathered I need to create an XSLT file that I can then reference in HTML, correct? When I try to create it using the editor below, I cannot seem to get it to work. I am trying to figure out how to display various static data from the the XML example below such as "Schedule WEBSITE" or any of the embedded data. I assume I simply have my syntax wrong, but I cannot find any XML/XSLT where that data is formatted with elements and attributes. For example, how would I go about calling some of the data that is nested multiple levels deep? If I wanted to loop through all events and display unique data, how would I do so? I should also mention that the I will be referencing an external XML feed and that the file is not stored locally. Any help would be greatly appreciated!!XSLT Tryit Editorhttp://www.w3schools.com/xml/tryxslt.asp?x...xsltfile=simpleXML EXAMPLE:<?xml version="1.0" encoding="ISO-8859-1"?><Schedule WEBSITE="Sample1" PUBLISH_DATE="06/04/2011" PUBLISH_TIME="09:55" TS="1307195737009"> <EventType CODE1="AC" CODE2="3" CODE3="Spo" CODE4="l.Spo.com" GROUP="E" ID="Spo" NAME="Sample Spo Name - Spo Lin"> <Date DTEXT="Sun, Jun 5, 11" TS="1307318400000"> <Event DenySameG="false" G_CLOCK="" G_STATUS="" ID="829403" LineOrder="D" NAME="G #3" Publish="true" STATUS="Open"> <Competitor CODE1="ABC" CODE3="ABC" CODE4="l.Spo.com-t.2" ID="45" LineOrderOverride="" NAME="ABC" NUM="1" ROT="705" SCORE=""> <LINK href="CODE3" xml:link="simple">Home Page</LINK> <Line ORDER="2" TYPE="MoLi"/> <Line ORDER="1" QUALITY="Restricted" TYPE="PoSp"> <Choice ID="7538029" NUMBER="2½" PREV="7538019" TS="1307127797249" VALUE="+2½"> <Od FRACTION="10/11" Line="-110" MULTIPLIER="1.91" RISK="110" WIN="100"/> </Choice> </Line> </Competitor> <Competitor CODE1="XYZ" CODE3="XYZ" CODE4="l.Spo.com-t.16" ID="37" LineOrderOverride="" NAME="XYZ" NUM="2" ROT="706" SCORE=""> <LINK href="CODE3" xml:link="simple">Home Page</LINK> <Line ORDER="2" TYPE="MoLi"/> <Line ORDER="1" QUALITY="Restricted" TYPE="PoSp"> <Choice ID="7538030" NUMBER="-2½" PREV="7538020" TS="1307127797249" VALUE="-2½"> <Od FRACTION="10/11" Line="-110" MULTIPLIER="1.91" RISK="110" WIN="100"/> </Choice> </Line> </Competitor> <SEGMENT CODE="SpoWG" SEQUENCE_NUMBER="1" SHORT_NAME="G"/> <NOTE>Best of ##</NOTE> <Time TS="1307318400000" TTEXT="8:00p EDT"/> <WagerStopTime TS="1307318580000" TTEXT="8:03p EDT"/> <Line ORDER="3" QUALITY="Restricted" TYPE="Total"> <Choice ID="7539300" NUMBER="189" PREV="7539292" TS="1307148604196" VALUE="189 (-105)"> <Od FRACTION="20/21" Line="-105" MULTIPLIER="1.95" RISK="105" WIN="100"/>Over</Choice> <Choice ID="7539301" NUMBER="189" PREV="7539293" TS="1307148604196" VALUE="189 (-115)"> <Od FRACTION="20/23" Line="-115" MULTIPLIER="1.87" RISK="115" WIN="100"/>Under</Choice> </Line> </Event> </Date> <Date DTEXT="Tue, Jun 7, 11" TS="1307494800000"> <Event DenySameG="false" G_CLOCK="" G_STATUS="" ID="830755" LineOrder="D" NAME="G #4" Publish="true" STATUS="Open"> <Competitor CODE1="ABC" CODE3="ABC" CODE4="l.Spo.com-t.2" ID="45" LineOrderOverride="" NAME="ABC" NUM="1" ROT="707" SCORE=""> <LINK href="CODE3" xml:link="simple">Home Page</LINK> <Line ORDER="2" TYPE="MoLi"/> <Line ORDER="1" TYPE="PoSp"/> </Competitor> <Competitor CODE1="XYZ" CODE3="XYZ" CODE4="l.Spo.com-t.16" ID="37" LineOrderOverride="" NAME="XYZ" NUM="2" ROT="708" SCORE=""> <LINK href="CODE3" xml:link="simple">Home Page</LINK> <Line ORDER="2" TYPE="MoLi"/> <Line ORDER="1" TYPE="PoSp"/> </Competitor> <SEGMENT CODE="SpoWG" SEQUENCE_NUMBER="1" SHORT_NAME="G"/> <NOTE>Best of ##</NOTE> <Time TS="1307494800000" TTEXT="9:00p EDT"/> <WagerStopTime TS="1307494980000" TTEXT="9:03p EDT"/> <Line ORDER="3" TYPE="Total"> <Choice>Over</Choice> <Choice>Under</Choice> </Line> </Event> </Date> </EventType></Schedule>

Link to comment
Share on other sites

There are lots of stand-alone XSLT processors available, like Saxon 9 (an XSLT 2.0) processor or like Saxon 6.5.5 (an XSLT 1.0 processor), both available from http://saxon.sourceforge.net/. or like AltovaXML Tools.I would consider using one of them or even consider trying out an XML ide (like Oxygen or Stylus Studio or Altova XML Spy) instead of using the web form you have linked to.As for help with your XML sample, if you show us the HTML you want to create for a short sample then we can show you how to use XSLT to create that HTML.Also tell us whether you want to use XSLT 2.0 or whether you are limited to XSLT 1.0 (which is supported by most web browsers).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...