Welcome to WebmasterWorld Guest from 54.198.69.193

Forum Moderators: httpwebwitch

Message Too Old, No Replies

Removing XML duplicates with XSL?

     
12:24 am on Aug 25, 2009 (gmt 0)

5+ Year Member



I have the following XML and need to remove duplicate entries via XSL and am having a hard time.

Essentially, I dont want the game Belton V. Waco to appear twice.

Any ideas on preventing this?

<game>
<sport_name>5A</sport_name>
<date>Friday</date>
<time>7:30</time>
<away_team_name/>
<away_team_school>Belton</away_team_school>
<away_team_score>0</away_team_score>
<home_team_name/>
<home_team_school>Waco</home_team_school>
<home_team_score>0</home_team_score>
</game>
<scoreboard>
<game>
<sport_name>4A</sport_name>
<date>Friday</date>
<time>7:30</time>
<away_team_name/>
<away_team_school>Belton</away_team_school>
<away_team_score>0</away_team_score>
<home_team_name/>
<home_team_school>Waco</home_team_school>
<home_team_score>0</home_team_score>
</game>
<scoreboard>

5:00 pm on Aug 25, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi ptolbert, welcome to WebmasterWorld!

I suggest that XSLT is not the right tool for this task. XSLT will do a good job of marking up XML that is already well constructed, it's really not very good at processing data.

There are many XSLT hacks that let you find groupings and rearrange pieces and sort parts and loop with conditions in interesting ways... but it's (almost) always easier to parse the XML with some kind of server-side script, clean up dupes and rearrange the data, then throw the result of that into your XSLT. What will take 1000 lines of infuriating and confusing XSLT acrobatics can be done in 20 lines of PHP or C#.

7:02 pm on Aug 25, 2009 (gmt 0)

5+ Year Member



Agreed.

Your XML is malformed and the task specifications leave for quite a bit of assumptions...

What you have here is not duplicated nodes, but rather a collection of duplicated data within multiple nodesets. Matching data against each other accross multiple nodes is gonna be pretty much impossible to implement. There is a slim chance that this can be done, but unless you provide a well-formed XML and elaborate on the specifications, it will be a wasted effort.

7:31 pm on Aug 25, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



the malformedness is just missing end tags for <scoreboard>

the important data unit here is the <game> element and its children

 

Featured Threads

Hot Threads This Week

Hot Threads This Month