Need some XML help!

Discussions about all aspects of technology, what you're doing with it and exchange of ideas and solutions to problems you might be having.

Need some XML help!

Postby Gh0st.IRE on Fri Nov 09, 2012 10:22 pm

So I've got an XML document (See spoiler), and I'm trying to apply basic styling to the document using XSLT, however, once my styling is applied, the xml document seems to continue displaying the rest of the content as a duplicate (See picture)

XML File golf.xml


Code: Select all
<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
<?xml-stylesheet href="golf_xsl.xsl" type="text/xsl" ?>
<golf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation='golf_schema.xsd'>
<page_title>The Ryder Cup 2012</page_title>
<eu_title>Team Europe</eu_title>
   <team_europe>
            <player id="1.1" captain="yes" eu="yes">Captain: José María Olazábal</player>
            <player id="1.2" eu="yes">Nicolas Colsaerts</player>
            <player id="1.3" eu="yes">Luke Donald</player>
            <player id="1.4" eu="yes">Sergio Garcia</player>
            <player id="1.5" eu="yes">Peter Hanson</player>
            <player id="1.6" eu="yes">Martin Kaymer</player>
            <player id="1.7" eu="yes">Paul Lawrie</player>
            <player id="1.8" eu="yes">Graeme McDowell</player>
            <player id="1.9" eu="yes">Rory McIlroy</player>
            <player id="1.10" eu="yes">Francesco Molinari</player>
            <player id="1.11" eu="yes">Ian Poulter</player>
            <player id="1.12" eu="yes">Justin Rose</player>
            <player id="1.13" eu="yes">Lee Westwood</player>
            <player id="1.14" vice_captain="yes" eu="yes">Vice Captain: Thomas Björn</player>
            <player id="1.15" vice_captain="yes" eu="yes">Vice Captain: Darren Clarke</player>
            <player id="1.16" vice_captain="yes" eu="yes">Vice Captain: Miguel Angel Jiménez</player>
            <player id="1.17" vice_captain="yes" eu="yes">Vice Captain: Paul McGinley</player>
   </team_europe>

<usa_title>Team USA</usa_title>
   <team_usa>
            <player id="2.1" captain="yes" usa="yes">Captain: Davis Love III</player>
            <player id="2.2" usa="yes">Keegan Bradley</player>
            <player id="2.3" usa="yes">Jason Dufner</player>
            <player id="2.4" usa="yes">Jim Furyk</player>
            <player id="2.5" usa="yes">Dustin Johnson</player>
            <player id="2.6" usa="yes">Zach Johnson</player>
            <player id="2.7" usa="yes">Matt Kuchar</player>
            <player id="2.8" usa="yes">Phil Mickelson</player>
            <player id="2.9" usa="yes">Brandt Snedeker</player>
            <player id="2.10" usa="yes">Webb Simpson</player>
            <player id="2.11" usa="yes">Steve Stricker</player>
            <player id="2.12" usa="yes">Bubba Watson</player>
            <player id="2.13" usa="yes">Tiger Woods</player>
            <player id="2.14" vice_captain="yes" usa="yes">Vice Captain: Fred Couples</player>
            <player id="2.15" vice_captain="yes" usa="yes">Vice Captain: Mike Hulbert</player>
            <player id="2.16" vice_captain="yes" usa="yes">Vice Captain: Jeff Sluman</player>
            <player id="2.17" vice_captain="yes" usa="yes">Vice Captain: Scott Verplank</player>
   </team_usa>
</golf>



and the XSL File golf_xsl.xsl


Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   
   <xsl:template match="page_title">
      <center><h1><xsl:apply-templates/></h1></center>
   </xsl:template>
   
   <xsl:template match="eu_title">
      <font color="blue"><h3><xsl:apply-templates/></h3></font>
   </xsl:template>
   
   <xsl:template match="usa_title">
      <font color="red"><h3><xsl:apply-templates/></h3></font>
   </xsl:template>

   
   <xsl:template match="team_europe">
   <xsl:for-each select="player[@eu]">
      <ul><li><xsl:value-of select="text()"/></li></ul>
   </xsl:for-each>
   <xsl:apply-templates/>
    </xsl:template>
   
    <xsl:template match="team_usa">
    <xsl:for-each select="player[@usa]">
      <ul><li><xsl:value-of select="text()"/></li></ul>
   </xsl:for-each>
   <xsl:apply-templates/>
    </xsl:template>
   
   
   <xsl:template match="/">
   <xsl:for-each select="player[@captain]">
      <font color="red"><xsl:value-of select="text()"/></font>
   </xsl:for-each>
   <xsl:apply-templates/>
   </xsl:template>
   
   
   
</xsl:transform>



Any and all help greatly appreciated!
Ex-TF2 Admin. Forum Moderator. Add me on Steam or PM me here!
Image
Heresy MMO Guild Member.
User avatar
Gh0st.IRE
Moderator
 
Player: Rear Naked Bugs
STEAM_0:0:12137987
 
Posts: 4635
Joined: Tue Dec 16, 2008 3:09 pm
Location: Dublin, Ireland



Image

Re: Need some XML help!

Postby coldandtired on Fri Nov 09, 2012 11:08 pm



<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="page_title">
<center><h1><xsl:apply-templates/></h1></center>
</xsl:template>

<xsl:template match="eu_title">
<font color="blue"><h3><xsl:apply-templates/></h3></font>
</xsl:template>

<xsl:template match="usa_title">
<font color="red"><h3><xsl:apply-templates/></h3></font>
</xsl:template>


<xsl:template match="team_europe">
<xsl:for-each select="player[@eu]">
<xsl:choose>
<xsl:when test="@captain='yes'">
<ul><li><font color="red"><xsl:value-of select="text()"/></font></li></ul>
</xsl:when>
<xsl:otherwise>
<ul><li><xsl:value-of select="text()"/></li></ul>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>

<xsl:template match="team_usa">
<xsl:for-each select="player[@usa]">
<xsl:choose>
<xsl:when test="@captain='yes'">
<ul><li><font color="red"><xsl:value-of select="text()"/></font></li></ul>
</xsl:when>
<xsl:otherwise>
<ul><li><xsl:value-of select="text()"/></li></ul>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>

</xsl:transform>


That will do it, and fix the red highlighting as well.
Image
User avatar
coldandtired
UKCS Admin
 
Player: coldandtired
STEAM_0:0:27915503
 
Posts: 3503
Joined: Sun Jan 24, 2010 12:40 pm
Location: 18th Century Europe



Image

Re: Need some XML help!

Postby Gh0st.IRE on Sat Nov 10, 2012 7:09 pm

Thanks a mill! I see where I went wrong now! :)
Last question - How would I go about displaying both teams side by side, similar to a table? And can I nest multiple choose statements? Like if I want to add Vice Captain into that <xsl:choose>?
Ex-TF2 Admin. Forum Moderator. Add me on Steam or PM me here!
Image
Heresy MMO Guild Member.
User avatar
Gh0st.IRE
Moderator
 
Player: Rear Naked Bugs
STEAM_0:0:12137987
 
Posts: 4635
Joined: Tue Dec 16, 2008 3:09 pm
Location: Dublin, Ireland



Image

Re: Need some XML help!

Postby coldandtired on Sat Nov 10, 2012 8:16 pm

Choose is like the traditional switch statement, with when acting as case.

<xsl:choose>
<xsl:when...>
...
</xsl:when>
<xsl:when>
...
</xsl:when>
... more whens...
<xsl:otherwise>
...
<xsl:otherwise>
</xsl:choose>

The table is much more difficult. Does the XML data have to look like that? It could be better formed which would make things easier.
Image
User avatar
coldandtired
UKCS Admin
 
Player: coldandtired
STEAM_0:0:27915503
 
Posts: 3503
Joined: Sun Jan 24, 2010 12:40 pm
Location: 18th Century Europe



Image

Re: Need some XML help!

Postby Gh0st.IRE on Sun Nov 11, 2012 10:07 am

No it doesn't, I just wanted to put it side by side if possible.
Ex-TF2 Admin. Forum Moderator. Add me on Steam or PM me here!
Image
Heresy MMO Guild Member.
User avatar
Gh0st.IRE
Moderator
 
Player: Rear Naked Bugs
STEAM_0:0:12137987
 
Posts: 4635
Joined: Tue Dec 16, 2008 3:09 pm
Location: Dublin, Ireland



Image

Re: Need some XML help!

Postby coldandtired on Sun Nov 11, 2012 11:03 am

I meant the raw data. Do you control it or does it come like that?
Image
User avatar
coldandtired
UKCS Admin
 
Player: coldandtired
STEAM_0:0:27915503
 
Posts: 3503
Joined: Sun Jan 24, 2010 12:40 pm
Location: 18th Century Europe



Image

Re: Need some XML help!

Postby Gh0st.IRE on Sun Nov 11, 2012 11:19 am

I control everything.
Ex-TF2 Admin. Forum Moderator. Add me on Steam or PM me here!
Image
Heresy MMO Guild Member.
User avatar
Gh0st.IRE
Moderator
 
Player: Rear Naked Bugs
STEAM_0:0:12137987
 
Posts: 4635
Joined: Tue Dec 16, 2008 3:09 pm
Location: Dublin, Ireland



Image

Re: Need some XML help!

Postby Gh0st.IRE on Mon Nov 12, 2012 1:57 pm

Also, Have you any source of good information on Schemas? I've written one for my golf.xml file but I'm not sure if I'm doing it right, or even if it has any errors. Also I don't know why, but my golf.xml will only display in Internet Explorer? If I load up in Chrome I just got a blank white screen.
Ex-TF2 Admin. Forum Moderator. Add me on Steam or PM me here!
Image
Heresy MMO Guild Member.
User avatar
Gh0st.IRE
Moderator
 
Player: Rear Naked Bugs
STEAM_0:0:12137987
 
Posts: 4635
Joined: Tue Dec 16, 2008 3:09 pm
Location: Dublin, Ireland



Image

Re: Need some XML help!

Postby coldandtired on Thu Nov 15, 2012 10:06 pm

Sorry, been crazy busy this week :(

Are you grabbing this data from another program? I ask because this seems like a huge amount of work to display a small group of names. Why not just knock up a standard HTML page?
Image
User avatar
coldandtired
UKCS Admin
 
Player: coldandtired
STEAM_0:0:27915503
 
Posts: 3503
Joined: Sun Jan 24, 2010 12:40 pm
Location: 18th Century Europe



Image

Re: Need some XML help!

Postby Gh0st.IRE on Sun Nov 18, 2012 10:35 am

It's for a lecture/module on XML. It's not about the content, it's more about using XML.

Right now, I've got that XML page and it's now styled basically using XSLT. I've then put the XML file into a TrAX Transformer which has made it into a .html (as per the modules requirements). It's a completely ridiculous assignment/task and feels like every step is reinventing the wheel.
Ex-TF2 Admin. Forum Moderator. Add me on Steam or PM me here!
Image
Heresy MMO Guild Member.
User avatar
Gh0st.IRE
Moderator
 
Player: Rear Naked Bugs
STEAM_0:0:12137987
 
Posts: 4635
Joined: Tue Dec 16, 2008 3:09 pm
Location: Dublin, Ireland



Image

Re: Need some XML help!

Postby Gh0st.IRE on Mon Nov 19, 2012 5:05 pm

Got everything sorted on the XML front, thanks guys!


Now I'm onto AJAX and what I want to do is display specific content from an xml file (in this case a small paragraph taken from scores.xml where the @<player name> matches the 'mouse-overed' name on the displayed HTML document.


E.g.
HTML Document says Stephen. When I mouse-over it, I want a pop-up showing the Stephen paragraph from the XML.

Anyone got any experience using AJAX? I'm going to give it a good shot myself during the week but would love to have someone to PM/bug if things don't go to plan...
Ex-TF2 Admin. Forum Moderator. Add me on Steam or PM me here!
Image
Heresy MMO Guild Member.
User avatar
Gh0st.IRE
Moderator
 
Player: Rear Naked Bugs
STEAM_0:0:12137987
 
Posts: 4635
Joined: Tue Dec 16, 2008 3:09 pm
Location: Dublin, Ireland



Image

Re: Need some XML help!

Postby Gh0st.IRE on Fri Nov 23, 2012 6:08 pm

My poor head :(
Ex-TF2 Admin. Forum Moderator. Add me on Steam or PM me here!
Image
Heresy MMO Guild Member.
User avatar
Gh0st.IRE
Moderator
 
Player: Rear Naked Bugs
STEAM_0:0:12137987
 
Posts: 4635
Joined: Tue Dec 16, 2008 3:09 pm
Location: Dublin, Ireland



Image

Re: Need some XML help!

Postby adz on Wed Nov 28, 2012 8:37 am

Wow you get to use XSLT/XML at Uni? We never got to do that which is a shame as I now use it quite a lot. Your browser XML problem; view source and you will see the XML source.

You basically need a method that takes input (eg the html element/value), reads the XML into a DOM and gets the element matching the input. I haven't used ajax in a while but I suspect there's something on the net.

Oh and just to point out, your XML structure made no sense. Having an element team_usa and team_europe and then having a boolean attribute is completely pointless.


adz
Home Member
 
Player: Adz
STEAM_0:1:7111525
 
Posts: 297
Joined: Wed Jun 03, 2009 10:36 pm

Re: Need some XML help!

Postby Gh0st.IRE on Wed Dec 05, 2012 3:03 pm

thanks guys. Approaching the end now. It was my first ever XML project so to speak, and my first time actually using XML. The next step is implementing a database, but doesn't that require me to re-do my entire original XML?
Ex-TF2 Admin. Forum Moderator. Add me on Steam or PM me here!
Image
Heresy MMO Guild Member.
User avatar
Gh0st.IRE
Moderator
 
Player: Rear Naked Bugs
STEAM_0:0:12137987
 
Posts: 4635
Joined: Tue Dec 16, 2008 3:09 pm
Location: Dublin, Ireland



Image

Re: Need some XML help!

Postby adz on Thu Dec 06, 2012 9:33 am

What type of database?


adz
Home Member
 
Player: Adz
STEAM_0:1:7111525
 
Posts: 297
Joined: Wed Jun 03, 2009 10:36 pm

Re: Need some XML help!

Postby Gh0st.IRE on Fri Dec 07, 2012 9:06 pm

We were going to use the eXist database but my lecturer pulled it as a requirement at the last minute. I'm officially finished now. I'll upload it here if anyone wants to see it, but I doubt that. Big thanks for all the help guys!
Ex-TF2 Admin. Forum Moderator. Add me on Steam or PM me here!
Image
Heresy MMO Guild Member.
User avatar
Gh0st.IRE
Moderator
 
Player: Rear Naked Bugs
STEAM_0:0:12137987
 
Posts: 4635
Joined: Tue Dec 16, 2008 3:09 pm
Location: Dublin, Ireland



Image


Return to PC World, Technology and Gadgets

Who is online

Users browsing this forum: CommonCrawl [Bot] and 1 guest